Sha256: 22a144e22acbf2febef4ba509a2ba9a111723abf722097a27be184ef1919e409

Contents?: true

Size: 636 Bytes

Versions: 4

Compression:

Stored size: 636 Bytes

Contents

require 'facets/string/bracket'

module ActiveRecordIgnoredAttributes::Inspect

  # TODO: brackets = self.class.default_brackets_for_inspect (configurable via class_inheritable_accessor)

  def inspect_with(attr_names, brackets = ['#<', '>'])
    attr_names ||= id
    body = attr_names.map {|name|
      "#{name}: #{send(name).inspect}"
    }.join(', ')

    "#{self.class} #{body}".
      bracket(*brackets)
  end

  def attributes_for_inspect
    [:id].map(&:to_s) + 
    (attributes.keys - self.class.ignored_attributes.map(&:to_s))
  end

  def inspect_without_ignored_attributes
    inspect_with(attributes_for_inspect)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
active_record_ignored_attributes-0.0.5 lib/active_record_ignored_attributes/inspect.rb
active_record_ignored_attributes-0.0.4 lib/active_record_ignored_attributes/inspect.rb
active_record_ignored_attributes-0.0.3 lib/active_record_ignored_attributes/inspect.rb
active_record_ignored_attributes-0.0.2 lib/active_record_ignored_attributes/inspect.rb