lib/cliutils/prefs.rb in cliutils-1.0.3 vs lib/cliutils/prefs.rb in cliutils-1.0.4

- old
+ new

@@ -1,14 +1,16 @@ +require 'cliutils/pretty-io' + module CLIUtils # Engine to derive preferences from a YAML file, deliver # those to a user via a prompt, and collect the results. class Prefs include PrettyIO attr_reader :answers, :config_path, :prompts # Reads prompt data from and stores it. - # @param [<String, Array>] data Either a filepath or an array + # @param [<String, Hash, Array>] data Filepath to YAML, Hash, or Array # @return [void] def initialize(data) @answers = [] @prompts = {} @@ -20,9 +22,14 @@ prompts = YAML::load_file(data) @prompts.deep_merge!(prompts).deep_symbolize_keys! else fail "Invalid configuration file: #{ yaml_path }" end + when Hash + @config_path = nil + + data = {:prompts => data} unless data.keys[0] == :prompts + @prompts.deep_merge!(data).deep_symbolize_keys! when Array @config_path = nil prompts = {:prompts => data} @prompts.deep_merge!(prompts).deep_symbolize_keys!