Module: ASIR::Description

Extended by:
Description
Included in:
Description
Defined in:
lib/asir/description.rb

Instance Method Summary collapse

Instance Method Details

#describe(obj, indent = "", more = nil) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/asir/description.rb', line 3

def describe obj, indent = "", more = nil
  case obj
  when nil, ASIR::Coder::Identity
    s = ""; more = nil
  when ASIR::Transport
    s = "#{describe(obj.encoder, indent, "->\n")}#{indent}#{obj.class.name}"
    opts = [ :file, :uri ].
      select { | x | obj.respond_to?(x) && obj.send(x) != nil }.
      map { | x | "#{x}: #{obj.send(x).inspect}" } * ","
    s << "(" << opts << ")" unless opts.empty?
    case
    when obj.respond_to?(:transports)
      s << "->[\n"
      s << obj.transports.map { | x | describe(x, indent + "  ") } * ",\n"
      s << "]"
    when obj.respond_to?(:transport)
      s << "->\n" << describe(obj.transport, indent + "  ")
    end
  when ASIR::Coder::Chain
    s = "#{indent}Chain(\n"
    s << obj.encoders.map { | x | describe(x, indent + "  ") } * "->\n"
    s << ")"
  else
    s = "#{indent}#{obj.class.name}"
  end
  s << more if more
  s
end