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
-
#inspect ⇒ String
Returns the class name plus its attributes.
-
#pretty_print(pretty_printer)
Internal use only
Internal use only
This pretty prints the same information as the inspect method.
-
#inspect_dynamic_fields ⇒ String
private
Internal use only
Internal use only
Get an array of inspected dynamic fields for the document.
-
#inspect_fields ⇒ String
private
Internal use only
Internal use only
Get an array of inspected fields for the document.
Instance Method Details
#inspect ⇒ String
Returns the class name plus its attributes. If using dynamic fields will include those as well.
# 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_fields ⇒ String (private)
This method is for internal use only.
Get an array of inspected dynamic fields for the document.
# File 'lib/mongoid/inspectable.rb', line 80
def inspect_dynamic_fields [] end
#inspect_fields ⇒ String (private)
This method is for internal use only.
Get an array of inspected fields for the document.
# File 'lib/mongoid/inspectable.rb', line 63
def inspect_fields fields.map do |name, field| unless name == "_id" as = field. [:as] "#{name}#{as ? "(#{as})" : nil}: #{@attributes[name].inspect}" end end.compact end
#pretty_print(pretty_printer)
This method is for internal use only.
This pretty prints the same information as the inspect method. This is meant to be called by the standard ‘pp’ library.
# File 'lib/mongoid/inspectable.rb', line 31
def pretty_print(pretty_printer) keys = fields.keys | attributes.keys pretty_printer.group(1, "#<#{self.class.name}", '>') do sep = lambda { pretty_printer.text(',') } pretty_printer.seplist(keys, sep) do |key| pretty_printer.breakable field = fields[key] as = "(#{field. [:as]})" if field && field. [:as] pretty_printer.text("#{key}#{as}") pretty_printer.text(':') pretty_printer.group(1) do pretty_printer.breakable if key == "_id" pretty_printer.text(_id.to_s) else pretty_printer.pp(@attributes[key]) end end end end end