class Temjin::Config
Attributes
file_path[R]
key[RW]
token[RW]
username[RW]
Public Class Methods
new(options = {})
click to toggle source
# File lib/temjin/config.rb, line 7 def initialize(options = {}) options = {:path => File.join(ENV['HOME'], '.config', 'temjin.yml'), :create => false}.merge(options.select { |k, _| %i[path create].include?(k) }) @file_path = options[:path] create_or_verify_file(options[:create]) config = YAML.load_file(@file_path) || {} @username = config.dig('username') @key = config.dig('key') @token = config.dig('token') verify_format unless options[:create] end
Public Instance Methods
create_or_verify_file(create_bool = false)
click to toggle source
# File lib/temjin/config.rb, line 23 def create_or_verify_file(create_bool = false) if create_bool FileUtils.touch(file_path) else fail Temjin::ConfigurationNotFoundError unless File.exist?(file_path) end end
save!()
click to toggle source
# File lib/temjin/config.rb, line 36 def save! File.open(file_path, 'w') do |f| f.write({'username' => username, 'key' => key, 'token' => token}.to_yaml) end end
verify_format()
click to toggle source
# File lib/temjin/config.rb, line 31 def verify_format malformed = username.nil? || key.nil? || token.nil? fail Temjin::ConfigurationNotFoundError if malformed end