Class: MyAsk::ConfigHelper

Inherits:
Object
  • Object
show all
Defined in:
lib/myask/config_helper.rb

Instance Method Summary collapse

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(global_options, options, args)
  @global_options = global_options
  @options = options
  @args = args
  @rc_file_path = File.expand_path("~/.myask.rc")
  @config_data = YAML.load_file(@rc_file_path)
end

Instance Method Details

#get_configObject



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_configObject



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