Module: Disposable::Twin::Property::Struct

Defined in:
lib/disposable/twin/property/struct.rb

Overview

Twin that uses a hash to populate.

Twin.new(id: 1)

Instance Method Summary collapse

Instance Method Details

#read_value_for(dfn, options) ⇒ Object



7
8
9
10
11
12
# File 'lib/disposable/twin/property/struct.rb', line 7

def read_value_for(dfn, options)
  name = dfn[:name]
  # TODO: test sym vs. str.
  return unless key_value = model.to_h.find { |k, _| k.to_sym == name.to_sym }
  key_value.last
end

#save!Object

So far, hashes can’t be persisted separately.



30
31
# File 'lib/disposable/twin/property/struct.rb', line 30

def save!
end

#sync(options = {}) ⇒ Object Also known as: sync!



24
25
26
# File 'lib/disposable/twin/property/struct.rb', line 24

def sync(options={})
  sync_hash_representer.new(self).to_hash
end

#sync_hash_representerObject

TODO: make this without representable, please.



14
15
16
17
18
19
20
21
22
# File 'lib/disposable/twin/property/struct.rb', line 14

def sync_hash_representer # TODO: make this without representable, please.
  Sync.hash_representer(self.class) do |dfn|
    dfn.merge!(
      prepare:       lambda { |options| options[:input] },
      serialize: lambda { |options| options[:input].sync! },
      representable: true
    ) if dfn[:nested]
  end
end