Class: NSConnector::Config
- Inherits:
-
Object
- Object
- NSConnector::Config
- Defined in:
- lib/ns_connector/config.rb
Overview
A ‘global’ config.
Being global, we are restricted to connecting to one NetSuite upstream URL per ruby process.
Constant Summary collapse
- ArgumentError =
Class.new(Exception)
- DEFAULT =
{ :use_threads => true, :no_threads => 4 }
- @@options =
{}
Class Method Summary collapse
-
.[](key) ⇒ Object
Read a key stored in @@options: Config.
-
.[]=(key, value) ⇒ Object
Write a key stored in @@options: Config = 1.
-
.check_valid! ⇒ Object
Check if the current config is valid.
-
.set_config!(options) ⇒ Object
Overwrite the current ‘global’ config with
options
.
Class Method Details
.[](key) ⇒ Object
Read a key stored in @@options: Config
15 16 17 18 19 20 |
# File 'lib/ns_connector/config.rb', line 15 def [](key) key = key.to_sym val = @@options[key] val.nil? ? DEFAULT[key] : val end |
.[]=(key, value) ⇒ Object
Write a key stored in @@options: Config = 1
23 24 25 |
# File 'lib/ns_connector/config.rb', line 23 def []=(key, value) @@options[key.to_sym] = value end |
.check_valid! ⇒ Object
Check if the current config is valid. Returns:
- true
-
if all required keys are supplied
Raises:
- ArgumentError
-
if any keys are missing
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
# File 'lib/ns_connector/config.rb', line 40 def check_valid! unless @@options then raise NSConnector::Config::ArgumentError, 'Need a configuration set. '\ 'See: NSConnector::Config.set_config!' end required = [ :account_id, :email, :password, :role, :restlet_url ] missing_keys = (required - @@options.keys) unless missing_keys.empty? raise NSConnector::Config::ArgumentError, 'Missing configuration key(s): '\ "#{missing_keys.join(', ')}" end # All good return true end |
.set_config!(options) ⇒ Object
Overwrite the current ‘global’ config with options
28 29 30 31 32 33 |
# File 'lib/ns_connector/config.rb', line 28 def set_config! @@options = {} .each do |k,v| @@options[k.to_sym] = v end end |