Class: Ttoken::Config
- Inherits:
-
Object
- Object
- Ttoken::Config
- Defined in:
- lib/ttoken/config.rb
Instance Attribute Summary collapse
-
#config_file ⇒ Object
Returns the value of attribute config_file.
-
#issuer ⇒ Object
Returns the value of attribute issuer.
-
#pinplustoken ⇒ Object
Returns the value of attribute pinplustoken.
-
#token ⇒ Object
Returns the value of attribute token.
Instance Method Summary collapse
- #config_file_path ⇒ Object
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #load_config ⇒ Object
- #source_path ⇒ Object
Constructor Details
#initialize ⇒ Config
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_file ⇒ Object
Returns the value of attribute config_file.
4 5 6 |
# File 'lib/ttoken/config.rb', line 4 def config_file @config_file end |
#issuer ⇒ Object
Returns the value of attribute issuer.
4 5 6 |
# File 'lib/ttoken/config.rb', line 4 def issuer @issuer end |
#pinplustoken ⇒ Object
Returns the value of attribute pinplustoken.
4 5 6 |
# File 'lib/ttoken/config.rb', line 4 def pinplustoken @pinplustoken end |
#token ⇒ Object
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_path ⇒ Object
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_config ⇒ Object
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.}" end |
#source_path ⇒ Object
29 30 31 |
# File 'lib/ttoken/config.rb', line 29 def source_path File.('../../..', __FILE__) end |