module MongoidOccurrenceViews::Event::HasViewsOnOccurrences::ClassMethods

Public Instance Methods

event_class_names() click to toggle source
# File lib/mongoid_occurrence_views/event/has_views_on_occurrences.rb, line 76
def event_class_names
  ObjectSpace.each_object(Class).select do |cls|
    cls.included_modules.include?(MongoidOccurrenceViews::Event)
  end.map(&:to_s)
end
event_relations() click to toggle source
# File lib/mongoid_occurrence_views/event/has_views_on_occurrences.rb, line 62
def event_relations
  return unless self.relations.present?
  self.relations.values.select { |rel| is_event_relation?(rel) }
end
expanded_occurrences_view_name() click to toggle source
# File lib/mongoid_occurrence_views/event/has_views_on_occurrences.rb, line 33
def expanded_occurrences_view_name
  [collection.name, EXPANDED_VIEW_NAME_SUFFIX].join('__').freeze
end
is_event_relation?(rel) click to toggle source
# File lib/mongoid_occurrence_views/event/has_views_on_occurrences.rb, line 67
def is_event_relation?(rel)
  relation_class_name = rel.options[:class_name]
  return false unless relation_class_name.present?
  return true if event_class_names.include?(relation_class_name)
  return unless relation_class = relation_class_name.safe_constantize
  event_superclasses = event_class_names.map { |cn| cn.safe_constantize.ancestors }.flatten
  event_superclasses.include? relation_class
end
occurrence_relation_chain() click to toggle source
# File lib/mongoid_occurrence_views/event/has_views_on_occurrences.rb, line 57
def occurrence_relation_chain
  return occurrence_relation_names unless event_relations.present?
  [event_relations.first.store_as, occurrence_relation_names].flatten
end
occurrence_relation_names() click to toggle source
# File lib/mongoid_occurrence_views/event/has_views_on_occurrences.rb, line 82
def occurrence_relation_names
  %w[occurrences daily_occurrences]
end
occurrence_relations_chained() click to toggle source
# File lib/mongoid_occurrence_views/event/has_views_on_occurrences.rb, line 51
def occurrence_relations_chained
  occurrence_relation_chain.each_with_index.map do |_, i|
    occurrence_relation_chain[0..i].join('.')
  end
end
occurrences_ordering_view_name() click to toggle source
# File lib/mongoid_occurrence_views/event/has_views_on_occurrences.rb, line 29
def occurrences_ordering_view_name
  [collection.name, ORDERING_VIEW_NAME_SUFFIX].join('__').freeze
end
with_expanded_occurrences_view(&block) click to toggle source
# File lib/mongoid_occurrence_views/event/has_views_on_occurrences.rb, line 37
def with_expanded_occurrences_view(&block)
  with_occurrences_view(expanded: true, &block)
end
with_occurrences_ordering_view(&block) click to toggle source
# File lib/mongoid_occurrence_views/event/has_views_on_occurrences.rb, line 41
def with_occurrences_ordering_view(&block)
  with_occurrences_view(expanded: false, &block)
end
with_occurrences_view(options = {}, &block) click to toggle source
# File lib/mongoid_occurrence_views/event/has_views_on_occurrences.rb, line 45
def with_occurrences_view(options = {}, &block)
  expanded = options.delete(:expanded) { |_| true }
  options[:collection] ||= expanded ? expanded_occurrences_view_name : occurrences_ordering_view_name
  criteria.with(options, &block)
end