module Disposable::Twin::Sync::ToNestedHash::ClassMethods

Public Instance Methods

build_nested_hash_representer() click to toggle source
# File lib/disposable/twin/sync.rb, line 90
def build_nested_hash_representer
  Sync.hash_representer(self) do |dfn|
    dfn.merge!(
      readable:   true, # the nested hash contains all fields.
      as:         dfn[:private_name], # nested hash keys by model property names.
      render_nil: dfn[:collection] ? nil : true,
    )

    dfn.merge!(
      prepare:   lambda { |options| options[:input] }, # TODO: why do we need that here?
      serialize: lambda { |options| options[:input].to_nested_hash },
    ) if dfn[:nested]
  end
end
nested_hash_representer() click to toggle source

Create a hash representer on-the-fly to serialize the form to a hash.

# File lib/disposable/twin/sync.rb, line 86
def nested_hash_representer
  @nested_hash_representer ||= build_nested_hash_representer
end