Module: Leafy::Mixin::ActiveRecord::Fields::InstanceMethods

Defined in:
lib/leafy/mixin/active_record/fields.rb

Instance Method Summary collapse

Instance Method Details

#leafy_field_valuesObject



30
31
32
33
34
# File 'lib/leafy/mixin/active_record/fields.rb', line 30

def leafy_field_values
  field_value_collection = ::Leafy::FieldValueCollection.new(leafy_fields, ar_json: activerecord_json_column?)
  field_value_collection.load(leafy_data || '{}')
  field_value_collection
end

#leafy_fieldsObject

Raises:

  • (RuntimeError)


15
16
17
# File 'lib/leafy/mixin/active_record/fields.rb', line 15

def leafy_fields
  raise(RuntimeError, "Leafy: leafy_fields method is not defined")
end

#leafy_valuesObject



19
20
21
# File 'lib/leafy/mixin/active_record/fields.rb', line 19

def leafy_values
  leafy_field_values.values
end

#leafy_values=(attributes = {}) ⇒ Object



23
24
25
26
27
28
# File 'lib/leafy/mixin/active_record/fields.rb', line 23

def leafy_values=(attributes = {})
  field_value_list = leafy_field_values
  field_value_list.values = attributes

  self.leafy_data = field_value_list.dump
end