Module: JsonFields::Configurable

Defined in:
lib/json_fields/configurable.rb

Constant Summary collapse

@@fields =
{}

Instance Method Summary collapse

Instance Method Details

#json_field(attribute, json_structure, options = {}) ⇒ Object



5
6
7
8
9
10
11
12
# File 'lib/json_fields/configurable.rb', line 5

def json_field(attribute, json_structure, options = {})
  options[:allow_blank] ||= false
  @@fields[attribute] = JsonFields::ConfigurationParser.parse!(json_structure, options)
  define_method("#{attribute}=") do |values|
    value = self.class.json_fields[attribute].assemble(values)
    self.write_attribute(attribute, value)
  end
end

#json_fieldsObject



14
15
16
# File 'lib/json_fields/configurable.rb', line 14

def json_fields
  @@fields
end