Module: Locomotive::Concerns::Shared::JsonAttribute::ClassMethods

Defined in:
app/models/locomotive/concerns/shared/json_attribute.rb

Instance Method Summary collapse

Instance Method Details

#json_attribute(name) ⇒ Object


10
11
12
13
14
15
16
17
# File 'app/models/locomotive/concerns/shared/json_attribute.rb', line 10

def json_attribute(name)
  validate { |record| record.send(:json_attribute_must_be_valid, name) }
  before_validation { |record| record.send(:add_json_parsing_error, name) }

  define_method(:"#{name}=") do |json|
    super(decode_json(name, json))
  end
end