Class: Disposable::Twin::Finders::FinderBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/disposable/twin/finders.rb

Instance Method Summary collapse

Constructor Details

#initialize(*args) ⇒ FinderBuilder

Returns a new instance of FinderBuilder.



13
14
15
# File 'lib/disposable/twin/finders.rb', line 13

def initialize(*args)
  @twin_class, @model_class = *args
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

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



18
19
20
21
22
23
# File 'lib/disposable/twin/finders.rb', line 18

def method_missing(*args, &block)
  models = execute(*args, &block)

  return @twin_class.new(models) unless models.respond_to?(:each) # sorry for all the magic, but that's how ActiveRecord works.
  models.collect { |mdl| @twin_class.new(mdl) }
end