Sha256: a0b9174b723e5a0e87668a6d54b429cba26615e9d45d006f2466c048e4d09dea

Contents?: true

Size: 540 Bytes

Versions: 3

Compression:

Stored size: 540 Bytes

Contents

module Id
  module Model
    class CompoundField < Association

      def initialize(model, name, fields, options)
        @fields = fields
        super(model, name, options)
      end

      def define_getter
        field = self
        model.send :define_method, name do
          memoize field.name do
            compound = Hash[field.fields.map { |k,v| [k.to_s, send(v) { raise MissingAttributeError, k.to_s }]}]
            field.type.new(compound)
          end
        end
      end

      attr_accessor :fields
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
id-0.0.9 lib/id/model/compound_field.rb
id-0.0.8 lib/id/model/compound_field.rb
id-0.0.7 lib/id/model/compound_field.rb