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
39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/okapi/settings.rb', line 39 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
19 20 21 22 23 24 25 26 |
# File 'lib/okapi/settings.rb', line 19 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") end |
#token ⇒ Object
28 29 30 31 32 33 34 35 36 37 |
# File 'lib/okapi/settings.rb', line 28 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") end |
#url ⇒ Object
8 9 10 11 12 13 14 15 16 17 |
# 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") do |url| URI(url) end end |