module Forward::Config
Constants
- DEFAULTS
Attributes
accounts[RW]
auto_copy[RW]
auto_open[RW]
default_account[RW]
Public Instance Methods
add_account(subdomain, api_token)
click to toggle source
# File lib/forward/config.rb, line 34 def add_account(subdomain, api_token) accounts[subdomain.to_sym] = api_token self.default_account = subdomain write end
api_key()
click to toggle source
# File lib/forward/config.rb, line 52 def api_key accounts[default_account.to_sym] end
auto_copy?()
click to toggle source
# File lib/forward/config.rb, line 60 def auto_copy? auto_copy == true end
auto_open?()
click to toggle source
# File lib/forward/config.rb, line 56 def auto_open? auto_open == true end
config_path()
click to toggle source
Returns the location of the forward config file based on the host os.
Returns the String path.
# File lib/forward/config.rb, line 102 def config_path File.join(ENV['HOME'], '.forwardrc') end
create_or_load()
click to toggle source
Create a config file if it doesn't exist, load one if it does.
Returns the resulting Config
object.
# File lib/forward/config.rb, line 116 def create_or_load if present? load else set_defaults! write end end
load()
click to toggle source
It initializes a new Config
instance, updates it with the config values from the config file, and raises an error if there's not a config or if the config options aren't valid.
Returns the Config
object.
# File lib/forward/config.rb, line 130 def load Forward.logger.debug('[config] loading') raise ConfigError, "Unable to find a forward config file at `#{config_path}'" unless present? update(YAML.load_file(config_path).symbolize_keys) end
present?()
click to toggle source
Checks to see if a .forward config file exists.
Returns true or false based on the existence of the config file.
# File lib/forward/config.rb, line 109 def present? File.exist? config_path end
remove_account(subdomain)
click to toggle source
# File lib/forward/config.rb, line 41 def remove_account(subdomain) accounts.delete(subdomain.to_sym) self.default_account = accounts.empty? ? nil : accounts.keys.first write end
set_default!(setting)
click to toggle source
# File lib/forward/config.rb, line 20 def set_default!(setting) value = DEFAULTS[setting.to_sym] value = value.dup if value.is_a?(Hash) || value.is_a?(Array) self.send("#{setting}=", value) value end
set_default_account(subdomain)
click to toggle source
# File lib/forward/config.rb, line 28 def set_default_account(subdomain) self.default_account = subdomain write end
set_defaults!()
click to toggle source
# File lib/forward/config.rb, line 16 def set_defaults! DEFAULTS.keys.each { |setting| set_default!(setting) } end
to_hash()
click to toggle source
update(attributes)
click to toggle source
write()
click to toggle source
Write the current config data to `config_path', and the current private_key to `key_path'.
Returns the Config
object.
# File lib/forward/config.rb, line 87 def write Forward.logger.debug('[config] writing') File.open(config_path, 'w') { |f| f.write(YAML.dump(to_hash)) } self rescue Exception => e Forward.logger.fatal "#{e.message}" raise ConfigError, 'Unable to write config file' end