Class: YTools::Path::Executor

Inherits:
Object
  • Object
show all
Defined in:
lib/ytools/path/executor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path = nil, yaml_object = nil) ⇒ Executor

Returns a new instance of Executor.



8
9
10
11
# File 'lib/ytools/path/executor.rb', line 8

def initialize(path=nil, yaml_object=nil)
  @selector = Parser.new(path).parse! if path
  @yaml_object = yaml_object
end

Instance Attribute Details

#selectorObject (readonly)

Returns the value of attribute selector.



6
7
8
# File 'lib/ytools/path/executor.rb', line 6

def selector
  @selector
end

#yaml_objectObject (readonly)

Returns the value of attribute yaml_object.



6
7
8
# File 'lib/ytools/path/executor.rb', line 6

def yaml_object
  @yaml_object
end

Instance Method Details

#execute!(yaml_files, options) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
# File 'lib/ytools/path/executor.rb', line 13

def execute!(yaml_files, options)
  @yaml_object = options[:yaml_object]

  if options[:debug]
    STDERR.puts @yaml_object.to_s
  end

  @selector = options[:selector]
  output = process!
  puts output if !output.empty?
end

#process!Object



25
26
27
28
29
30
31
32
33
34
# File 'lib/ytools/path/executor.rb', line 25

def process!
  found = @selector.select(yaml_object)
  if found.is_a?(YTools::YamlObject)
    show_yaml_object(found)
  elsif found.is_a?(Array)
    show_array(found)
  else
    found.to_s
  end
end