module Opto
An option parser/validator/resolver
Constants
- VERSION
Public Class Methods
new(opts)
click to toggle source
Initialize a new Opto::Option
(when input is hash) or an Opto::Group
(when input is an array of hashes)
# File lib/opto.rb, line 17 def self.new(opts) case opts when Hash if opts.has_key?('name') || opts.has_key?(:name) Option.new(opts) else Group.new(opts) end when ::Array if opts.all? {|o| o.kind_of?(Hash) } Group.new(opts) else raise TypeError, "Invalid input, an option hash or an array of option hashes required" end else raise TypeError, "Invalid input, an option hash or an array of option hashes required" end end
read(yaml_path, key=nil)
click to toggle source
Read an option (or option group) from a YAML file @param [String] path_to_file @param [String,Symbol] a key in the hash representation of the file, such as :variables to read the options from (instead of using the root) @example
Opto.read('/tmp/foo.yml', :options)
# File lib/opto.rb, line 41 def self.read(yaml_path, key=nil) opts = YAML.load(File.read(yaml_path)) new(key.nil? ? opts : opts[key]) end