class Msewage::Importer::Config
Constants
- API_ENDPOINT
Attributes
config[R]
Public Class Methods
new(options)
click to toggle source
# File lib/msewage-importer/config.rb, line 6 def initialize(options) setup_config(options) validate_config end
Public Instance Methods
api_endpoint()
click to toggle source
# File lib/msewage-importer/config.rb, line 11 def api_endpoint API_ENDPOINT end
Private Instance Methods
config_file(config_file_path)
click to toggle source
# File lib/msewage-importer/config.rb, line 49 def config_file(config_file_path) YAML.load_file(config_file_path) rescue Errno::ENOENT end
config_file_example()
click to toggle source
# File lib/msewage-importer/config.rb, line 54 def config_file_example File.read(config_file_example_path) end
config_file_example_path()
click to toggle source
# File lib/msewage-importer/config.rb, line 58 def config_file_example_path File.expand_path('../../../config/config-example.yml', __FILE__) end
config_file_path(options)
click to toggle source
# File lib/msewage-importer/config.rb, line 28 def config_file_path(options) options.delete(:config_file_path) || default_config_file_path end
default_config_file_path()
click to toggle source
# File lib/msewage-importer/config.rb, line 45 def default_config_file_path "#{ENV['HOME']}/.config/msewage-importer/config.yml" end
method_missing(meth, *args, &block)
click to toggle source
Calls superclass method
# File lib/msewage-importer/config.rb, line 62 def method_missing(meth, *args, &block) return config[meth.to_s] if config.has_key?(meth.to_s) super end
respond_to?(meth)
click to toggle source
Calls superclass method
# File lib/msewage-importer/config.rb, line 67 def respond_to?(meth) config.has_key?(meth.to_s) || super end
setup_config(options)
click to toggle source
# File lib/msewage-importer/config.rb, line 21 def setup_config(options) options_from_config = config_file(config_file_path(options)) @config = Hashie::Mash.new config.merge!(options_from_config) unless options_from_config.nil? config.merge!(options) end
valid_keys?()
click to toggle source
# File lib/msewage-importer/config.rb, line 41 def valid_keys? config[:msewage] && config.msewage[:username] && config.msewage[:password] end
validate_config()
click to toggle source
# File lib/msewage-importer/config.rb, line 32 def validate_config unless valid_keys? STDERR.puts "Please create a config file in #{default_config_file_path}" STDERR.puts "\nIt should look like:\n\n#{config_file_example}" exit 1 end end