Class: LimitedRed::Config
- Inherits:
-
Object
- Object
- LimitedRed::Config
- Defined in:
- lib/limited_red/config.rb
Class Method Summary collapse
Instance Method Summary collapse
- #config ⇒ Object
-
#initialize(out_stream = STDOUT, in_stream = STDIN, env_config = ENV) ⇒ Config
constructor
A new instance of Config.
- #load_and_validate_config(type) ⇒ Object
Constructor Details
#initialize(out_stream = STDOUT, in_stream = STDIN, env_config = ENV) ⇒ Config
Returns a new instance of Config.
3 4 5 6 7 |
# File 'lib/limited_red/config.rb', line 3 def initialize(out_stream = STDOUT, in_stream = STDIN, env_config = ENV) @in = in_stream @out = out_stream @env_config = env_config end |
Class Method Details
.load_and_validate_config(type) ⇒ Object
9 10 11 |
# File 'lib/limited_red/config.rb', line 9 def self.load_and_validate_config(type) new.load_and_validate_config(type) end |
Instance Method Details
#config ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/limited_red/config.rb', line 26 def config @config ||= begin limited_red_project_config = load_yaml(limited_red_project_config_file) limited_red_shared_config = load_yaml(limited_red_shared_config_file) limited_red_shared_config = limited_red_shared_config.merge(limited_red_project_config) if @env_config.has_key?('LIMITED_RED_USERNAME') limited_red_shared_config = limited_red_shared_config.merge({'username' => @env_config['LIMITED_RED_USERNAME']}) end if @env_config.has_key?('LIMITED_RED_API_KEY') limited_red_shared_config = limited_red_shared_config.merge({'api key' => @env_config['LIMITED_RED_API_KEY']}) end limited_red_shared_config end end |
#load_and_validate_config(type) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/limited_red/config.rb', line 13 def load_and_validate_config(type) ensure_config_exists if valid_config? config.merge({'type' => type}) else errors = "Make sure you have the following set in your .limited_red:\n" errors += " * project name\n" unless config['project name'] errors += " * username\n" unless config['username'] errors += " * api key\n" unless config['api key'] @out.print errors end end |