Sha256: 2bdd16b8af75388b65b15dc0942836c00ebeb2aed8fff23cb00709555c30287a

Contents?: true

Size: 886 Bytes

Versions: 2

Compression:

Stored size: 886 Bytes

Contents

module Id
  module Model
    attr_reader :data

    def initialize(data)
      @data = Hash[data.map { |k, v| [k.to_s, v] }]
    end

    private

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

    def memoize(f, &b)
      instance_variable_get("@#{f}") || instance_variable_set("@#{f}", b.call)
    end

    module Descriptor
      def field(f, options={})
        Field.new(self, f, options).define
        builder_class.field f
      end

      def has_one(f, options={})
        HasOne.new(self, f, options).define
        builder_class.field f
      end

      def has_many(f, options={})
        HasMany.new(self, f, options).define
        builder_class.field f
      end

      def builder
        builder_class.new(self)
      end

      private

      def builder_class
        @builder_class ||= Class.new { include Builder }
      end
    end

  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
id-0.0.3 lib/id/model.rb
id-0.0.2 lib/id/model.rb