Module: UltraCommandLine::Utils::YamlFactory

Included in:
Commands::Factory, Manager::Factory
Defined in:
lib/ultra_command_line/utils/yaml_factory.rb

Instance Method Summary collapse

Instance Method Details

#from_yaml(yaml, factory_options = {}, &block) ⇒ Object



14
15
16
17
18
19
# File 'lib/ultra_command_line/utils/yaml_factory.rb', line 14

def from_yaml(yaml, factory_options = {}, &block)
  from_hash YAML.load(yaml), factory_options, &block
rescue => e
  UltraCommandLine.logger.error "#{e.message}\nBacktrace:\n#{e.backtrace.join("\n\t")}"
  raise UltraCommandLine::Error, 'Invalid Yaml content. Parser error !'
end

#from_yaml_file(yaml_file, factory_options = {}, &block) ⇒ Object



6
7
8
9
10
11
12
# File 'lib/ultra_command_line/utils/yaml_factory.rb', line 6

def from_yaml_file(yaml_file, factory_options = {}, &block)
  yaml_file = File.expand_path yaml_file
  UltraCommandLine.logger.debug "Loading commands definitions from '#{yaml_file}'."
  raise UltraCommandLine::Error, 'Invalid Yaml command file specified !' unless File.exists? yaml_file
  raise UltraCommandLine::Error, 'Cannot read Yaml command file !' unless File.readable? yaml_file
  from_yaml File.read(yaml_file), factory_options, &block
end