class UserChoices::YamlConfigFileSource

Use an YAML file as a source of choices. Note: because the YAML parser can produce something out of many typo-filled YAML files, it’s a good idea to check that your file looks like you’d expect before trusting in it. Do that with:

irb> require 'yaml'
irb> YAML.load_file('config.yaml')

Public Instance Methods

ensure_array_values_are_strings(a) click to toggle source
# File lib/user-choices/sources.rb, line 259
def ensure_array_values_are_strings(a)
  a.each_with_index { |elt, index| ensure_element_is_string(a, index) }
end
ensure_element_is_string(collection, key) click to toggle source
# File lib/user-choices/sources.rb, line 263
def ensure_element_is_string(collection, key)
  case collection[key]
    when Hash then ensure_hash_values_are_strings(collection[key])
    when Array then ensure_array_values_are_strings(collection[key])
    else collection[key] = collection[key].to_s
  end
end
ensure_hash_values_are_strings(h) click to toggle source
# File lib/user-choices/sources.rb, line 255
def ensure_hash_values_are_strings(h)
  h.each { |k, v| ensure_element_is_string(h, k) }
end
format_specific_exception?(ex) click to toggle source
# File lib/user-choices/sources.rb, line 249
def format_specific_exception?(ex)
  ex.is_a?(ArgumentError)
end
format_specific_reading() click to toggle source

Treat filename as the configuration file. filename is expected to be in the home directory. The home directory is found in the same way Rubygems finds it.

# File lib/user-choices/sources.rb, line 243
def format_specific_reading
  result = YAML.load_file(@path)
  ensure_hash_values_are_strings(result)
  result
end