Method: Faceted::Model::ModelClassMethods#field

Defined in:
lib/faceted/model.rb

#field(name, args = {}) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/faceted/model.rb', line 29

def field(name, args={})
  fields << name
  define_method :"#{name}" do
    val = instance_variable_get("@#{name}")
    val.nil? ? args[:default] : val
  end
  unless args[:read_only]
    define_method :"#{name}=" do |val|
      instance_variable_set("@#{name}", val)
    end
  end
  build_association_from(name.to_s) if name.to_s.include?("id") && ! args[:skip_association]
end