Module: AwesomePrintActiveSupport

Defined in:
lib/ap/mixin/active_support.rb

Overview

Copyright © 2010-2011 Michael Dvorkin

Awesome Print is freely distributable under the terms of MIT license. See LICENSE file or www.opensource.org/licenses/mit-license.php


Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



8
9
10
11
# File 'lib/ap/mixin/active_support.rb', line 8

def self.included(base)
  base.send :alias_method, :printable_without_active_support, :printable
  base.send :alias_method, :printable, :printable_with_active_support
end

Instance Method Details

#awesome_active_support_time(object) ⇒ Object

Format ActiveSupport::TimeWithZone as standard Time.




31
32
33
# File 'lib/ap/mixin/active_support.rb', line 31

def awesome_active_support_time(object)
  awesome_self(object, :as => :time)
end

#awesome_hash_with_indifferent_access(object) ⇒ Object

Format HashWithIndifferentAccess as standard Hash.

NOTE: can’t use awesome_self(object, :as => :hash) since awesome_self uses object.inspect internally, i.e. it would convert hash to string.




40
41
42
# File 'lib/ap/mixin/active_support.rb', line 40

def awesome_hash_with_indifferent_access(object)
  awesome_hash(object)
end

#printable_with_active_support(object) ⇒ Object

Add ActiveSupport class names to the dispatcher pipeline.




15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/ap/mixin/active_support.rb', line 15

def printable_with_active_support(object)
  printable = printable_without_active_support(object)
  return printable if !defined?(ActiveSupport::TimeWithZone) || !defined?(HashWithIndifferentAccess)

  if printable == :self
    if object.is_a?(ActiveSupport::TimeWithZone)
      printable = :active_support_time
    elsif object.is_a?(HashWithIndifferentAccess)
      printable = :hash_with_indifferent_access
    end
  end
  printable
end