Module: AwesomePrint::ActiveRecord

Defined in:
lib/awesome_print/ext/active_record.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



9
10
11
12
# File 'lib/awesome_print/ext/active_record.rb', line 9

def self.included(base)
  base.send :alias_method, :cast_without_active_record, :cast
  base.send :alias_method, :cast, :cast_with_active_record
end

Instance Method Details

#cast_with_active_record(object, type) ⇒ Object

Add ActiveRecord class names to the dispatcher pipeline.




16
17
18
19
20
21
22
23
24
25
26
# File 'lib/awesome_print/ext/active_record.rb', line 16

def cast_with_active_record(object, type)
  cast = cast_without_active_record(object, type)
  return cast if !defined?(::ActiveRecord)

  if object.is_a?(::ActiveRecord::Base)
    cast = :active_record_instance
  elsif object.is_a?(Class) && object.ancestors.include?(::ActiveRecord::Base)
    cast = :active_record_class
  end
  cast
end