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
# File 'lib/disposable/twin/property/struct.rb', line 7

def read_value_for(dfn, options)
  name = dfn[:name]
  @model[name.to_s] || @model[name.to_sym] # TODO: test sym vs. str.
end

#save!Object

So far, hashes can’t be persisted separately.



28
29
# File 'lib/disposable/twin/property/struct.rb', line 28

def save!
end

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



22
23
24
# File 'lib/disposable/twin/property/struct.rb', line 22

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

#sync_hash_representerObject

TODO: make this without representable, please.



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

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