Class: Groupdate::Series

Inherits:
Object
  • Object
show all
Defined in:
lib/groupdate/series.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(magic, relation) ⇒ Series

Returns a new instance of Series.



5
6
7
8
# File 'lib/groupdate/series.rb', line 5

def initialize(magic, relation)
  @magic = magic
  @relation = relation
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object

clone to prevent modifying original variables



11
12
13
14
15
16
17
18
19
20
# File 'lib/groupdate/series.rb', line 11

def method_missing(method, *args, &block)
  # https://github.com/rails/rails/blob/master/activerecord/lib/active_record/relation/calculations.rb
  if ActiveRecord::Calculations.method_defined?(method)
    magic.perform(relation, method, *args, &block)
  elsif @relation.respond_to?(method, true)
    Groupdate::Series.new(magic, relation.send(method, *args, &block))
  else
    super
  end
end

Instance Attribute Details

#magicObject

Returns the value of attribute magic.



3
4
5
# File 'lib/groupdate/series.rb', line 3

def magic
  @magic
end

#relationObject

Returns the value of attribute relation.



3
4
5
# File 'lib/groupdate/series.rb', line 3

def relation
  @relation
end

Instance Method Details

#respond_to?(method, include_all = false) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/groupdate/series.rb', line 22

def respond_to?(method, include_all = false)
  ActiveRecord::Calculations.method_defined?(method) || relation.respond_to?(method) || super
end

#reverse_order_valueObject



26
27
28
# File 'lib/groupdate/series.rb', line 26

def reverse_order_value
  nil
end