class CLIUtils::Prefs

PrefManager Class

Engine to derive preferences from a YAML file, deliver those to a user via a prompt, and collect the results.

Attributes

answers[R]

Attributes

config_path[R]

Attributes

prompts[R]

Attributes

Public Class Methods

new(data) click to toggle source

Methods


initialize method

Reads prompt data from YAML file. @return Void


# File lib/cliutils/prefs.rb, line 24
def initialize(data)
  @answers = []
  @prompts = {}

  case data
  when String
    if File.exists?(data)
      @config_path = data

      prompts = YAML::load_file(data)
      @prompts.deep_merge!(prompts).deep_symbolize_keys!
    else
      fail "Invalid configuration file: #{ yaml_path }"
    end
  when Array
    @config_path = nil

    prompts = {:prompts => data}
    @prompts.deep_merge!(prompts).deep_symbolize_keys!
  else
    fail 'Invalid configuration data'
  end
end

Public Instance Methods

ask() click to toggle source

ask method

Runs through all of the prompt questions and collects answers from the user. Note that all questions w/o requirements are examined first; once those are complete, questions w/ requirements are examined. @return Void


# File lib/cliutils/prefs.rb, line 57
def ask
  @prompts[:prompts].reject { |p| p[:requirements] }.each do |p|
    _deliver_prompt(p)
  end

  @prompts[:prompts].find_all { |p| p[:requirements] }.each do |p|
    _deliver_prompt(p) if _requirements_fulfilled?(p)
  end
end