Class: Okapi::Settings
- Inherits:
-
Object
- Object
- Okapi::Settings
- Defined in:
- lib/okapi/settings.rb
Instance Method Summary collapse
- #get_var!(symbol, error_msg) ⇒ Object
-
#initialize(url, tenant, token) ⇒ Settings
constructor
A new instance of Settings.
- #tenant ⇒ Object
- #token ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(url, tenant, token) ⇒ Settings
Returns a new instance of Settings.
3 4 5 6 7 |
# File 'lib/okapi/settings.rb', line 3 def initialize(url, tenant, token) @url = url @tenant = tenant @token = token end |
Instance Method Details
#get_var!(symbol, error_msg) ⇒ Object
45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/okapi/settings.rb', line 45 def get_var!(symbol, error_msg) env_var_name = "OKAPI_#{symbol.to_s.upcase}" env_value = ENV[env_var_name] instance_value = instance_variable_get("@#{symbol}") if instance_value && !instance_value.strip.empty? block_given? ? yield(instance_value) : instance_value elsif !env_value.nil? && !env_value.strip.empty? block_given? ? yield(env_value) : env_value else raise ConfigurationError, error_msg end end |
#tenant ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/okapi/settings.rb', line 21 def tenant get_var!(:tenant, "This operation requires a tenant id, but it couldn't be found.\n\nYou can fix this by setting either the `OKAPI_TENANT` environment variable, or\nusing the `--tenant` option if you're using the command line.\n\nTo store a default tenant, run `okapi config:set OKAPI_TENANT=<TENANT>`\n") end |
#token ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/okapi/settings.rb', line 32 def token get_var!(:token, "This operation requires you to be logged in, and already authenticated with\nyour Okapi cluster.\n\nYou can fix this by obtaining an authenication token, and then using it by\neither setting the `OKAPI_TOKEN` environment variable or using the\n`--token` option from the command line.\n\nTo log in with a username and password, run the command `okapi login`.\n") end |
#url ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 |
# File 'lib/okapi/settings.rb', line 8 def url get_var!(:url, "This operation requires the url of your Okapi gateway, but it couldn't be found.\n\nYou can fix this by setting either the `OKAPI_URL` environment variable, or\nusing the `--url` option if you're using the command line.\n\nTo store a default url, run `okapi config:set OKAPI_URL=<URL>`\n") do |url| URI(url) end end |