Module: Specifind::ClassMethods

Defined in:
lib/specifind.rb

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *arguments, &block) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/specifind.rb', line 20

def method_missing(name, *arguments, &block)
  unless Specifind.comparator
    active_record_adapter = ActiveRecord::Base.connection.class.name.split(':').last.gsub /Adapter/, ''
    comparator = "Specifind::Comparators::#{active_record_adapter}".constantize
    Specifind.comparator = "Specifind::Comparators::#{active_record_adapter}".constantize
  end
  
  match = MethodBuilder.match(self, name)
  if match && match.valid?
    types = self.columns.map{|c| {:name => c.name, :type => c.type}}
    match.merge_attribute_types types
    match.define
    send(name, *arguments, &block)
  else
    super
  end
end