Module: OptionsModel::Concerns::Serialization

Extended by:
ActiveSupport::Concern
Included in:
Base
Defined in:
lib/options_model/concerns/serialization.rb

Defined Under Namespace

Modules: ClassMethods

Instance Method Summary collapse

Instance Method Details

#to_hObject



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/options_model/concerns/serialization.rb', line 5

def to_h
  hash = {}

  self.class.attribute_names.each do |attribute_name|
    attribute = public_send(attribute_name)
    if attribute.is_a?(OptionsModel::Base)
      hash[attribute_name] = attribute.to_h
    else
      hash[attribute_name] = attribute
    end
  end

  hash
end

#to_h_with_unusedObject



20
21
22
# File 'lib/options_model/concerns/serialization.rb', line 20

def to_h_with_unused
  to_h.merge unused_attributes
end