Sha256: a9adfe977c2ac296d378c441e5aa00a773d32dd4f4eb72ec0dd60e3578d3c550

Contents?: true

Size: 799 Bytes

Versions: 5

Compression:

Stored size: 799 Bytes

Contents

require 'ripple'

module Ripple
  # Makes IRB and other inspect output a bit friendlier
  module Inspection

    # A human-readable version of the {Ripple::Document} or {Ripple::EmbeddedDocument}
    # plus attributes
    def inspect
      attribute_list = attributes_for_persistence.except("_type").map {|k,v| "#{k}=#{v.inspect}" }.join(' ')
      inspection_string(attribute_list)
    end

    # A string representation of the {Ripple::Document} or {Ripple::EmbeddedDocument}
    def to_s
      inspection_string
    end

    private

    def inspection_string(extra = nil)
      body = self.class.name + persistance_identifier
      body += " #{extra}" if extra
      "<#{body}>"
    end

    def persistance_identifier
      self.class.embeddable? ? "" : ":#{key || '[new]'}"
    end

  end
end

Version data entries

5 entries across 5 versions & 4 rubygems

Version Path
wyngle-ripple-0.1.0 lib/ripple/inspection.rb
better-ripple-1.0.0 lib/ripple/inspection.rb
ripple-1.0.0.beta2 lib/ripple/inspection.rb
seomoz-ripple-1.0.0.pre lib/ripple/inspection.rb
ripple-1.0.0.beta lib/ripple/inspection.rb