Module: KnifeSous::ProcessorCommand

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(other) ⇒ Object



6
7
8
9
10
11
12
13
# File 'lib/knife_sous/processor_command.rb', line 6

def self.included(other)
  other.class_eval do
    option :node_manifest_file,
      :long        => '--node-manifest-file NODE_MANIFEST_FILE',
      :description => 'Alternate location for node manifest config file',
      :default => File.join("nodes", "nodes.rb")
  end
end

Instance Method Details

#manifest_file_pathObject



40
41
42
43
# File 'lib/knife_sous/processor_command.rb', line 40

def manifest_file_path
  config[:node_manifest_file] ||= default_config[:node_manifest_file]
  @manifest_file_path ||= File.expand_path(File.join(Dir.pwd, config[:node_manifest_file]))
end

#process_configObject



45
46
47
48
49
50
# File 'lib/knife_sous/processor_command.rb', line 45

def process_config
  validate_config!
  root_namespace = RootNamespace.new
  root_namespace.instance_eval(File.read(manifest_file_path), manifest_file_path)
  root_namespace
end

#root_namespaceObject



36
37
38
# File 'lib/knife_sous/processor_command.rb', line 36

def root_namespace
  @root_namespace ||= process_config
end

#search(target_qualifiers = []) ⇒ Object



27
28
29
30
31
32
33
34
# File 'lib/knife_sous/processor_command.rb', line 27

def search(target_qualifiers = [])
  namespace = root_namespace
  target_qualifiers.each do |target_qualifier|
    return nil if namespace.nil?
    namespace = namespace.keep_if { |item| item.name == target_qualifier }.first
  end
  namespace
end

#validate_config!Object



15
16
17
18
19
20
21
22
23
24
25
# File 'lib/knife_sous/processor_command.rb', line 15

def validate_config!
  unless File.exists?(manifest_file_path)
    ui.fatal("Couldn't find #{manifest_file_path}")
    exit 1
  end
  unless File.readable?(manifest_file_path)
    ui.fatal("Can't read #{manifest_file_path}")
    exit 1
  end
  true
end