Module: EndecaOnDemand::PP

Instance Method Summary collapse

Instance Method Details

#inspectObject

:nodoc:


4
5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/endeca_on_demand/pp.rb', line 4

def inspect # :nodoc:
  return super if not respond_to?(:inspect_attributes) or inspect_attributes.blank?
  attributes = inspect_attributes.reject { |x|
    begin
      attribute = send x
      attribute.blank?
    rescue NoMethodError
      true
    end
  }.map { |attribute|
    "#{attribute.to_s.sub(/_\w+/, 's')}=#{send(attribute).inspect}"
  }.join ' '
  "#<#{self.class.name}:#{sprintf("0x%x", object_id)} #{attributes}>"
end

#pretty_print(pp) ⇒ Object

:nodoc:


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/endeca_on_demand/pp.rb', line 19

def pretty_print pp # :nodoc:
  return super if not respond_to?(:inspect_attributes) or inspect_attributes.blank?
  nice_name = self.class.name
  pp.group(2, "#(#{nice_name}:#{sprintf("0x%x", object_id)} {", '})') do

    pp.breakable
    attrs = inspect_attributes.map { |t|
      [t, send(t)] if respond_to?(t)
    }.compact.find_all { |x|
      x.last.present?
    }

    pp.seplist(attrs) do |v|
      if v.last.class == EndecaOnDemand::Collection
        pp.group(2, "#{v.first} = [", "]") do
          pp.breakable
          pp.seplist(v.last) do |item|
            pp.pp item
          end
        end
      else
        pp.text "#{v.first} = "
        pp.pp v.last
      end
    end
    pp.breakable

  end
end