Class: FilterTable::Trace

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/utils/filter.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeTrace

Returns a new instance of Trace.



50
51
52
# File 'lib/inspec/utils/filter.rb', line 50

def initialize
  @chain = []
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*args) ⇒ Object



62
63
64
65
66
# File 'lib/inspec/utils/filter.rb', line 62

def method_missing(*args)
  res = Trace.new
  @chain.push([args, res])
  res
end

Class Method Details

.to_ruby(trace) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/inspec/utils/filter.rb', line 68

def self.to_ruby(trace)
  chain = trace.instance_variable_get(:@chain)
  return "" if chain.empty?

  " " + chain.map do |el|
    m = el[0][0]
    args = el[0].drop(1)
    nxt = to_ruby(el[1])
    next m.to_s + nxt if args.empty?
    next m.to_s + " " + args[0].inspect + nxt if args.length == 1

    m.to_s + "(" + args.map(&:inspect).join(", ") + ")" + nxt
  end.join(" ")
end