123456789_123456789_123456789_123456789_123456789_

Module: Mongoid::Inspectable

Relationships & Source Files
Extension / Inclusion / Inheritance Descendants
Included In:
Defined in: lib/mongoid/inspectable.rb

Overview

Contains the behavior around inspecting documents via inspect.

Instance Method Summary

Instance Method Details

#inspectString

Returns the class name plus its attributes. If using dynamic fields will include those as well.

Examples:

Inspect the document.

person.inspect

Returns:

  • (String)

    A nice pretty string to look at.

[ GitHub ]

  
# File 'lib/mongoid/inspectable.rb', line 16

def inspect
  inspection = []
  inspection.concat(inspect_fields).concat(inspect_dynamic_fields)
  "#<#{self.class.name} _id: #{_id}, #{inspection * ', '}>"
end

#inspect_dynamic_fieldsString (private)

This method is for internal use only.

Get an array of inspected dynamic fields for the document.

Examples:

Inspect the dynamic fields.

document.inspect_dynamic_fields

Returns:

  • (String)

    An array of pretty printed dynamic field values.

[ GitHub ]

  
# File 'lib/mongoid/inspectable.rb', line 49

def inspect_dynamic_fields
  []
end

#inspect_fieldsString (private)

This method is for internal use only.

Get an array of inspected fields for the document.

Examples:

Inspect the defined fields.

document.inspect_fields

Returns:

  • (String)

    An array of pretty printed field values.

[ GitHub ]

  
# File 'lib/mongoid/inspectable.rb', line 32

def inspect_fields
  fields.map do |name, field|
    unless name == "_id"
      as = field.options[:as]
      "#{name}#{as ? "(#{as})" : nil}: #{@attributes[name].inspect}"
    end
  end.compact
end