Sha256: f416f077fc4f0c618524f93a4c023e49b36703078f7f90877baf742a12707748

Contents?: true

Size: 661 Bytes

Versions: 4

Compression:

Stored size: 661 Bytes

Contents

module MiniMongo
  module AttributeAssignment
    def assign_attributes(attributes)
      @attributes["id"] = attributes.delete("_id").to_s || attributes.delete(:_id).to_s
      attributes.each do |key, value|
        @attributes[key] = value
        define_accessors(key) unless self.respond_to? :key
      end
    end

    alias_method :attributes=, :assign_attributes

    def id
      @attributes["id"]
    end

    private
      def define_accessors(key)
        define_singleton_method(key) do
          @attributes[key]
        end

        define_singleton_method("#{key}=") do |value|
          @attributes[key] = value
        end
      end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
mini_mongo-0.1.0 lib/mini_mongo/attribute_assignment.rb
mini_mongo-0.0.4 lib/mini_mongo/attribute_assignment.rb
mini_mongo-0.0.3 lib/mini_mongo/attribute_assignment.rb
mini_mongo-0.0.2 lib/mini_mongo/attribute_assignment.rb