Class: Searcher::Model
- Inherits:
-
Object
- Object
- Searcher::Model
- Defined in:
- app/models/searcher/model.rb
Instance Attribute Summary collapse
-
#methods ⇒ Object
Returns the value of attribute methods.
-
#searcher ⇒ Object
Returns the value of attribute searcher.
Instance Method Summary collapse
- #attributes=(params = nil) ⇒ Object
- #create_field(name, options) ⇒ Object
-
#initialize(searcher) ⇒ Model
constructor
A new instance of Model.
Constructor Details
#initialize(searcher) ⇒ Model
Returns a new instance of Model.
4 5 6 7 8 |
# File 'app/models/searcher/model.rb', line 4 def initialize(searcher) self.searcher = searcher self.methods = Module.new self.extend self.methods end |
Instance Attribute Details
#methods ⇒ Object
Returns the value of attribute methods.
2 3 4 |
# File 'app/models/searcher/model.rb', line 2 def methods @methods end |
#searcher ⇒ Object
Returns the value of attribute searcher.
2 3 4 |
# File 'app/models/searcher/model.rb', line 2 def searcher @searcher end |
Instance Method Details
#attributes=(params = nil) ⇒ Object
10 11 12 13 14 15 |
# File 'app/models/searcher/model.rb', line 10 def attributes=(params=nil) params ||= {} params.each do |field, value| self.send "#{field}=", value if respond_to? "#{field}=" end end |
#create_field(name, options) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/models/searcher/model.rb', line 17 def create_field(name, ) methods.class_eval do define_method name do instance_variable_get("@#{name}") || ([:default].call if [:default] && [:default].respond_to?(:call)) end define_method "#{name}=" do |value| instance_variable_set("@#{name}", value) end end end |