Class: MyAsk::ConfigHelper
- Inherits:
-
Object
- Object
- MyAsk::ConfigHelper
- Defined in:
- lib/myask/config_helper.rb
Instance Method Summary collapse
- #get_config ⇒ Object
-
#initialize(global_options, options, args) ⇒ ConfigHelper
constructor
A new instance of ConfigHelper.
- #save_config ⇒ Object
Constructor Details
#initialize(global_options, options, args) ⇒ ConfigHelper
Returns a new instance of ConfigHelper.
4 5 6 7 8 9 10 |
# File 'lib/myask/config_helper.rb', line 4 def initialize(, , args) @global_options = @options = @args = args @rc_file_path = File.("~/.myask.rc") @config_data = YAML.load_file(@rc_file_path) end |
Instance Method Details
#get_config ⇒ Object
12 13 14 |
# File 'lib/myask/config_helper.rb', line 12 def get_config @config_data.reject { |key, _| ["commands", "version", "s", "help"].include?(key.to_s) }.to_json end |
#save_config ⇒ Object
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/myask/config_helper.rb', line 16 def save_config @config_data[:api_key] = @options[:api_key] if @options[:api_key] @config_data[:api_host] = @options[:api_host] if @options[:api_host] @config_data[:project] = @options[:project] if @options[:project] File.open(@rc_file_path, "w") do |file| file.write(@config_data.to_yaml) end @config_data.reject { |key, _| ["commands", "version", "s", "help"].include?(key.to_s) }.to_json end |