Sha256: 82d9e6be2698aaa11205fee6e5986629983d392221cde51caeff65e8d62e6b73

Contents?: true

Size: 1.36 KB

Versions: 8

Compression:

Stored size: 1.36 KB

Contents

require "disposable/expose"
require "disposable/composition"

module Disposable
  class Twin
    module Expose
      module ClassMethods
        def expose_class
          @expose_class ||= Class.new(Disposable::Expose).from(definitions.values)
        end
      end # ClassMethods.

      def self.included(base)
        base.extend(ClassMethods)
      end

      module Initialize
        def mapper_for(*args)
          self.class.expose_class.new(*args)
        end
      end
      include Initialize
    end


    module Composition
      module ClassMethods
        def expose_class
          @expose_class ||= Class.new(Disposable::Composition).from(definitions.values)
        end
      end

      def self.included(base)
        base.send(:include, Expose::Initialize)
        base.extend(ClassMethods)
      end

      def to_nested_hash(*)
        hash = {}

        @model.each do |name, model| # TODO: provide list of composee attributes in Composition.
          part_properties = schema.find_all { |dfn| dfn[:on] == name }.collect{ |dfn| dfn[:name].to_sym }
          hash[name] = self.class.nested_hash_representer.new(self).to_hash(include: part_properties)
        end

        hash
      end

    private
      def save_model
        res = true
        mapper.each { |twin| res &= twin.save } # goes through all models in Composition.
        res
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
disposable-0.2.5 lib/disposable/twin/composition.rb
disposable-0.2.4 lib/disposable/twin/composition.rb
disposable-0.2.3 lib/disposable/twin/composition.rb
disposable-0.2.2 lib/disposable/twin/composition.rb
disposable-0.2.1 lib/disposable/twin/composition.rb
disposable-0.2.0 lib/disposable/twin/composition.rb
disposable-0.2.0.rc2 lib/disposable/twin/composition.rb
disposable-0.2.0.rc1 lib/disposable/twin/composition.rb