Sha256: 4f22495e782cd6e86876bc916d182559cfdac92f5c6f476595c6ad31bd0d9419

Contents?: true

Size: 543 Bytes

Versions: 6

Compression:

Stored size: 543 Bytes

Contents

module Id
  module Model
    class Field

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

      def define
        field = self
        model.send :define_method, name do
          data.fetch(field.key) { field.default or raise MissingAttributeError }
        end
      end

      def key
        options.fetch(:key, name).to_s
      end

      def default
        options.fetch(:default, nil)
      end

      attr_reader :model, :name, :options
    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
id-0.0.6 lib/id/model/field.rb
id-0.0.5 lib/id/model/field.rb
id-0.0.4 lib/id/model/field.rb
id-0.0.3 lib/id/model/field.rb
id-0.0.2 lib/id/model/field.rb
id-0.0.1 lib/id/model/field.rb