class Figobox::ConfigParser
Attributes
yaml[R]
Public Class Methods
new()
click to toggle source
# File lib/figobox/config_parser.rb, line 5 def initialize verify_config_exists @yaml = YAML.load(File.read(File.expand_path("config/application.yml"))) end
Public Instance Methods
get_keys_for_environment(environment)
click to toggle source
# File lib/figobox/config_parser.rb, line 10 def get_keys_for_environment(environment) verify_environment_exists(environment) global_values = get_global_key_value_sets env_values = get_environment_key_value_sets(environment) global_values.merge(env_values) end
Private Instance Methods
get_environment_key_value_sets(environment)
click to toggle source
# File lib/figobox/config_parser.rb, line 37 def get_environment_key_value_sets(environment) found = yaml.find { |key, _| key.casecmp(environment).zero? } return found[1] if found {} end
get_global_key_value_sets()
click to toggle source
# File lib/figobox/config_parser.rb, line 33 def get_global_key_value_sets yaml.reject { |_, value| value.is_a?(Hash) } end
verify_config_exists()
click to toggle source
# File lib/figobox/config_parser.rb, line 23 def verify_config_exists return if File.exists?("config/application.yml") abort "No config file could be found at config/application.yml. Please see https://github.com/laserlemon/figaro for more details." end
verify_environment_exists(environment)
click to toggle source
# File lib/figobox/config_parser.rb, line 28 def verify_environment_exists(environment) return unless get_environment_key_value_sets(environment) == {} abort "'#{environment}' environment doesn't exist in the configuration file." end