Module: CustomFields::Types::Json::Target::ClassMethods
- Defined in:
- lib/custom_fields/types/json.rb
Instance Method Summary collapse
-
#apply_json_custom_field(klass, rule) ⇒ Object
Adds a json field.
-
#json_attribute_get(instance, name) ⇒ Hash
Build a hash storing the formatted value for a JSON custom field of an instance.
-
#json_attribute_set(instance, name, attributes) ⇒ Object
Set the value for the instance and the date field specified by the 2 params.
Instance Method Details
#apply_json_custom_field(klass, rule) ⇒ Object
Adds a json field
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/custom_fields/types/json.rb', line 18 def apply_json_custom_field(klass, rule) name = rule['name'] klass.field name, type: Hash, localize: rule['localized'] || false klass.validates_presence_of name if rule['required'] klass.before_validation { |record| record.send(:add_json_parsing_error, name) } klass.send(:define_method, :"#{name}=") do |json| super(decode_json(name, json)) end end |
#json_attribute_get(instance, name) ⇒ Hash
Build a hash storing the formatted value for a JSON custom field of an instance.
39 40 41 |
# File 'lib/custom_fields/types/json.rb', line 39 def json_attribute_get(instance, name) default_attribute_get(instance, name) end |
#json_attribute_set(instance, name, attributes) ⇒ Object
Set the value for the instance and the date field specified by the 2 params.
50 51 52 |
# File 'lib/custom_fields/types/json.rb', line 50 def json_attribute_set(instance, name, attributes) default_attribute_set(instance, name, attributes) end |