Sha256: 7117e382162dab66034e355dd73a800ceb9703fa6c646fc3f50894e4a075668c

Contents?: true

Size: 656 Bytes

Versions: 36

Compression:

Stored size: 656 Bytes

Contents

require 'active_support/core_ext/module/delegation'

module MongoModel
  module Attributes
    class Store < ActiveSupport::OrderedHash
      include Typecasting
      include Mongo
      
      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

36 entries across 36 versions & 1 rubygems

Version Path
mongomodel-0.5.5 lib/mongomodel/attributes/store.rb
mongomodel-0.5.4 lib/mongomodel/attributes/store.rb
mongomodel-0.5.3 lib/mongomodel/attributes/store.rb
mongomodel-0.5.2 lib/mongomodel/attributes/store.rb
mongomodel-0.5.1 lib/mongomodel/attributes/store.rb
mongomodel-0.5.0 lib/mongomodel/attributes/store.rb
mongomodel-0.4.9 lib/mongomodel/attributes/store.rb
mongomodel-0.4.8 lib/mongomodel/attributes/store.rb
mongomodel-0.4.7 lib/mongomodel/attributes/store.rb
mongomodel-0.4.6 lib/mongomodel/attributes/store.rb
mongomodel-0.4.5 lib/mongomodel/attributes/store.rb
mongomodel-0.4.4 lib/mongomodel/attributes/store.rb
mongomodel-0.4.3 lib/mongomodel/attributes/store.rb
mongomodel-0.4.2 lib/mongomodel/attributes/store.rb
mongomodel-0.4.1 lib/mongomodel/attributes/store.rb
mongomodel-0.4.0 lib/mongomodel/attributes/store.rb
mongomodel-0.3.6 lib/mongomodel/attributes/store.rb
mongomodel-0.3.5 lib/mongomodel/attributes/store.rb
mongomodel-0.3.4 lib/mongomodel/attributes/store.rb
mongomodel-0.3.3 lib/mongomodel/attributes/store.rb