Sha256: 8bbc189ce23fe4a0d60076f76c83c18fec8d6310f94711c391d89b09aaa3450e

Contents?: true

Size: 1.41 KB

Versions: 4

Compression:

Stored size: 1.41 KB

Contents

module Disposable
  class Twin
    # Read all properties at twin initialization time from model.
    # Simply pass through all properties from the model to the respective twin writer method.
    # This will result in all twin properties/collection items being twinned, and collections
    # being Collection to expose the desired public API.
    module Setup
      # test is in incoming hash? is nil on incoming model?

      def initialize(model, options={})
        @fields = {}
        @model  = model
        @mapper = mapper_for(model) # mapper for model.

        setup_properties!(model, options)
      end

    private
      def mapper_for(model)
        model
      end

      def setup_properties!(model, options)
        schema.each do |dfn|
          next if dfn[:readable] == false

          name  = dfn.name
          value = options[name.to_sym] || mapper.send(name) # model.title.

          setup_write!(dfn, value)
        end

        @fields.merge!(options) # FIXME: hash/string. # FIXME: call writer!!!!!!!!!!
        # from_hash(options) # assigns known properties from options.
      end

      def setup_write!(dfn, value)
        send(dfn.setter, value)
      end


      # Including this will _not_ use the property's setter in Setup and allow you to override it.
      module SkipSetter
        def setup_write!(dfn, value)
          write_property(dfn.name, value, dfn)
        end
      end
    end # Setup
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
disposable-0.1.4 lib/disposable/twin/setup.rb
disposable-0.1.3 lib/disposable/twin/setup.rb
disposable-0.1.2 lib/disposable/twin/setup.rb
disposable-0.1.1 lib/disposable/twin/setup.rb