Class: Ttoken::Config

Inherits:
Object
  • Object
show all
Defined in:
lib/ttoken/config.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



6
7
8
9
10
11
12
# File 'lib/ttoken/config.rb', line 6

def initialize
  @config_file = config_file_path
  @options = load_config
  @token = @options.fetch(:token, nil)
  @issuer = @options.fetch(:issuer, nil)
  @pinplustoken = @options.fetch(:pinplustoken, false)
end

Instance Attribute Details

#config_fileObject

Returns the value of attribute config_file.



4
5
6
# File 'lib/ttoken/config.rb', line 4

def config_file
  @config_file
end

#issuerObject

Returns the value of attribute issuer.



4
5
6
# File 'lib/ttoken/config.rb', line 4

def issuer
  @issuer
end

#pinplustokenObject

Returns the value of attribute pinplustoken.



4
5
6
# File 'lib/ttoken/config.rb', line 4

def pinplustoken
  @pinplustoken
end

#tokenObject

Returns the value of attribute token.



4
5
6
# File 'lib/ttoken/config.rb', line 4

def token
  @token
end

Instance Method Details

#config_file_pathObject



14
15
16
# File 'lib/ttoken/config.rb', line 14

def config_file_path
  File.exist?(CONFIG_FILE) ? CONFIG_FILE : File.join(source_path, 'config/ttoken.yml')
end

#load_configObject



18
19
20
21
22
23
24
25
26
27
# File 'lib/ttoken/config.rb', line 18

def load_config
  if File.exist?(config_file)
    YAML.load(File.open(config_file)) || {}
  else
    puts "Config file #{config_file} not found, using default configuration"
    {}
  end
rescue StandardError => e
  raise "Couldn't load configuration file. Error: #{e.message}"
end

#source_pathObject



29
30
31
# File 'lib/ttoken/config.rb', line 29

def source_path
  File.expand_path('../../..', __FILE__)
end