Class: Searcher::Model

Inherits:
Object
  • Object
show all
Defined in:
app/models/searcher/model.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#methodsObject

Returns the value of attribute methods.



2
3
4
# File 'app/models/searcher/model.rb', line 2

def methods
  @methods
end

#searcherObject

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, options)
  methods.class_eval do
    define_method name do
      instance_variable_get("@#{name}") ||
        (options[:default].call if options[:default] && options[:default].respond_to?(:call))
    end
    define_method "#{name}=" do |value|
      instance_variable_set("@#{name}", value)
    end
  end
end