Sha256: bb510c48ac0426114eca2633553b4a531816ff07197f21b0ebc497b87d9e629e

Contents?: true

Size: 676 Bytes

Versions: 14

Compression:

Stored size: 676 Bytes

Contents

require 'active_support/core_ext/module/delegation'

module MongoModel
  module Attributes
    class Store < ActiveSupport::OrderedHash
      include Typecasting
      include Mongo
      include Dirty
      
      attr_reader :instance
      delegate :properties, :to => :instance
      
      def initialize(instance)
        super()
        @instance = instance
        set_defaults!
      end
      
      def inspect
        "{#{map { |k, v| "#{k.inspect}=>#{v.inspect}"}.join(', ')}}"
      end
    
    private
      def set_defaults!
        properties.each do |name, property|
          self[name] = property.default(instance)
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
mongomodel-0.2.17 lib/mongomodel/attributes/store.rb
mongomodel-0.2.16 lib/mongomodel/attributes/store.rb
mongomodel-0.2.15 lib/mongomodel/attributes/store.rb
mongomodel-0.2.14 lib/mongomodel/attributes/store.rb
mongomodel-0.2.13 lib/mongomodel/attributes/store.rb
mongomodel-0.2.12 lib/mongomodel/attributes/store.rb
mongomodel-0.2.11 lib/mongomodel/attributes/store.rb
mongomodel-0.2.10 lib/mongomodel/attributes/store.rb
mongomodel-0.2.9 lib/mongomodel/attributes/store.rb
mongomodel-0.2.8 lib/mongomodel/attributes/store.rb
mongomodel-0.2.7 lib/mongomodel/attributes/store.rb
mongomodel-0.2.6 lib/mongomodel/attributes/store.rb
mongomodel-0.2.5 lib/mongomodel/attributes/store.rb
mongomodel-0.2.4 lib/mongomodel/attributes/store.rb