module Disposable::Twin::Accessors

Private Instance Methods

build_collection(dfn, *args) click to toggle source
# File lib/disposable/twin.rb, line 112
def build_collection(dfn, *args)
  Collection.for_models(Twinner.new(self, dfn), *args)
end
build_for(dfn, *args) click to toggle source

Build a twin or a Twin::Collection for the value (which is a model or array of).

# File lib/disposable/twin.rb, line 104
def build_for(dfn, *args)
  dfn[:collection] ? build_collection(dfn, *args) : build_twin(dfn, *args)
end
build_twin(dfn, *args) click to toggle source
# File lib/disposable/twin.rb, line 108
def build_twin(dfn, *args)
  dfn[:nested].new(*args) # Twin.new(model, options={})
end
field_read(name) click to toggle source

Read the property’s value without using the public reader.

# File lib/disposable/twin.rb, line 99
def field_read(name)
  @fields[name.to_s]
end
field_write(name, value) click to toggle source

Write the property’s value without using the public writer.

# File lib/disposable/twin.rb, line 94
def field_write(name, value)
  @fields[name.to_s] = value
end
write_property(name, value, dfn) click to toggle source

assumption: collections are always initialized from Setup since we assume an empty [] for “nil”/uninitialized collections.

# File lib/disposable/twin.rb, line 87
def write_property(name, value, dfn)
  value = build_for(dfn, value) if dfn[:nested] and value

  field_write(name, value)
end