Sha256: 72904473cbe1774435f7b263a49ab62b32def0efa7ed4046915ff92e762a901e

Contents?: true

Size: 1010 Bytes

Versions: 4

Compression:

Stored size: 1010 Bytes

Contents

module MiniMongo
  module Core

    attr_reader :attributes

    alias_method :to_hash, :attributes

    def initialize(attributes = {})
      @attributes = {}
      assign_attributes(attributes.dup)
    end

    # Return an array with this +Document+ only in it.
    #
    # @example Return the document in an array.
    #   document.to_a
    #
    def to_a
      attributes.to_a
    end


    def inspect
      inspection = if attributes
                     attributes.collect { |key, value|
                       "#{key}: #{value_for_inspect(value)}"
                     }.compact.join(", ")
                   else
                     "not initialized"
                   end
      "#<#{self.class} #{inspection}>"
    end

    private

    def value_for_inspect(value)
      if value.is_a?(String) && value.length > 50
        "#{value[0..50]}...".inspect
      elsif value.is_a?(Date) || value.is_a?(Time)
        %("#{value.to_s(:db)}")
      else
        value.inspect
      end
    end

  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

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