Class: Recognizer::Config
- Inherits:
-
Object
- Object
- Recognizer::Config
- Defined in:
- lib/recognizer/config.rb
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Config
constructor
A new instance of Config.
- #read ⇒ Object
- #validate ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Config
Returns a new instance of Config.
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
# File 'lib/recognizer/config.rb', line 5 def initialize(={}) unless [:config_file] raise "Missing config file path" end if File.readable?([:config_file]) config_file_contents = File.open([:config_file], "r").read begin @config = JSON.parse(config_file_contents, :symbolize_names => true) rescue JSON::ParserError => error raise "Config file must be valid JSON: #{error}" end else raise "Config file does not exist or is not readable: #{[:config_file]}" end validate end |
Instance Method Details
#read ⇒ Object
28 29 30 |
# File 'lib/recognizer/config.rb', line 28 def read @config end |
#validate ⇒ Object
22 23 24 25 26 |
# File 'lib/recognizer/config.rb', line 22 def validate unless @config[:librato][:email] && @config[:librato][:api_key] raise "You must provide a Librato Metrics account email and API key" end end |