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



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

def to_h
  hash = {}

  hash.merge! unused_attributes if self.class.with_unused_attributes?
  self.class.attribute_names_for_inlining.each do |name|
    hash[name] = send(name)
  end
  self.class.attribute_names_for_nesting.each do |name|
    hash[name] = send(name).to_h
  end

  hash
end