Module: Hopsoft::ActsAsLookup::UsesLookups::StaticMethods

Defined in:
lib/hopsoft/acts_as_lookup.rb

Overview

Add class methods here

Instance Attribute Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(name, *args) ⇒ Object



106
107
108
109
110
111
112
113
114
115
116
117
118
119
# File 'lib/hopsoft/acts_as_lookup.rb', line 106

def method_missing(name, *args)
  if name =~ /^find_by_/i && args && args.length == 1
    @lookup_models.each do |model|
      attribute_name = model.table_name.singularize

      if name =~ /#{attribute_name}$/i
        # if we get here, assume a lookup is being performed
        return lookup_parent(model, args[0])
      end
    end
  end

  super
end

Instance Attribute Details

#lookup_modelsObject (readonly)

Returns the value of attribute lookup_models.



104
105
106
# File 'lib/hopsoft/acts_as_lookup.rb', line 104

def lookup_models
  @lookup_models
end