Module: AmazingPrint::ActiveSupport

Included in:
Formatter
Defined in:
lib/amazing_print/ext/active_support.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



10
11
12
13
# File 'lib/amazing_print/ext/active_support.rb', line 10

def self.included(base)
  base.send :alias_method, :cast_without_active_support, :cast
  base.send :alias_method, :cast, :cast_with_active_support
end

Instance Method Details

#awesome_active_support_time(object) ⇒ Object

Format ActiveSupport::TimeWithZone as standard Time.




29
30
31
# File 'lib/amazing_print/ext/active_support.rb', line 29

def awesome_active_support_time(object)
  colorize(object.inspect, :time)
end

#awesome_hash_with_indifferent_access(object) ⇒ Object

Format HashWithIndifferentAccess as standard Hash.




35
36
37
# File 'lib/amazing_print/ext/active_support.rb', line 35

def awesome_hash_with_indifferent_access(object)
  awesome_hash(object)
end

#cast_with_active_support(object, type) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/amazing_print/ext/active_support.rb', line 15

def cast_with_active_support(object, type)
  cast = cast_without_active_support(object, type)
  if defined?(::ActiveSupport) && defined?(::HashWithIndifferentAccess)
    if (defined?(::ActiveSupport::TimeWithZone) && object.is_a?(::ActiveSupport::TimeWithZone)) || object.is_a?(::Date)
      cast = :active_support_time
    elsif object.is_a?(::HashWithIndifferentAccess)
      cast = :hash_with_indifferent_access
    end
  end
  cast
end