Class: SgtnCldr::Config
- Inherits:
-
Object
- Object
- SgtnCldr::Config
- Defined in:
- lib/sgtn-cldr/core/config.rb
Constant Summary collapse
- @@config_cache =
{}
Instance Attribute Summary collapse
-
#app_id ⇒ Object
Returns the value of attribute app_id.
-
#bundle_mode ⇒ Object
Returns the value of attribute bundle_mode.
-
#cache_expiry_period ⇒ Object
Returns the value of attribute cache_expiry_period.
-
#cert_path ⇒ Object
Returns the value of attribute cert_path.
-
#client_id ⇒ Object
Returns the value of attribute client_id.
-
#client_secret ⇒ Object
Returns the value of attribute client_secret.
-
#device_ipaddress ⇒ Object
Returns the value of attribute device_ipaddress.
-
#disable_cache ⇒ Object
Returns the value of attribute disable_cache.
-
#endpoint ⇒ Object
Returns the value of attribute endpoint.
-
#http_proxy ⇒ Object
Returns the value of attribute http_proxy.
-
#http_timeout ⇒ Object
Returns the value of attribute http_timeout.
-
#ipn_endpoint ⇒ Object
Returns the value of attribute ipn_endpoint.
-
#merchant_endpoint ⇒ Object
Returns the value of attribute merchant_endpoint.
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#openid_client_id ⇒ Object
Returns the value of attribute openid_client_id.
-
#openid_client_secret ⇒ Object
Returns the value of attribute openid_client_secret.
-
#openid_endpoint ⇒ Object
Returns the value of attribute openid_endpoint.
-
#openid_redirect_uri ⇒ Object
Returns the value of attribute openid_redirect_uri.
-
#password ⇒ Object
Returns the value of attribute password.
-
#platform_endpoint ⇒ Object
Returns the value of attribute platform_endpoint.
-
#product_name ⇒ Object
Returns the value of attribute product_name.
-
#rest_endpoint ⇒ Object
Returns the value of attribute rest_endpoint.
-
#rest_token_endpoint ⇒ Object
Returns the value of attribute rest_token_endpoint.
-
#sandbox_email_address ⇒ Object
Returns the value of attribute sandbox_email_address.
-
#signature ⇒ Object
Returns the value of attribute signature.
-
#source_bundle ⇒ Object
Returns the value of attribute source_bundle.
-
#subject ⇒ Object
Returns the value of attribute subject.
-
#token ⇒ Object
Returns the value of attribute token.
-
#token_secret ⇒ Object
Returns the value of attribute token_secret.
-
#translation_bundle ⇒ Object
Returns the value of attribute translation_bundle.
-
#username ⇒ Object
Returns the value of attribute username.
-
#verbose_logging ⇒ Object
Returns the value of attribute verbose_logging.
-
#version ⇒ Object
Returns the value of attribute version.
-
#vip_server ⇒ Object
Returns the value of attribute vip_server.
Class Method Summary collapse
-
.config(env = default_environment, override_configuration = {}) ⇒ Object
Create or Load Config object based on given environment and configurations.
-
.configurations ⇒ Object
Get raw configurations in Hash format.
-
.configurations=(configs) ⇒ Object
Set configuration.
- .configure(options = {}, &block) ⇒ Object (also: set_config)
- .default_config(env = nil) ⇒ Object
-
.default_environment ⇒ Object
Get default environment name.
-
.default_environment=(env) ⇒ Object
Set default environment.
-
.load(file_name, default_env = default_environment) ⇒ Object
Load configurations from file === Arguments *
file_name
– Configuration file path *default_environment
(Optional) – default environment configuration to load === Example Config.load(‘config/paypal.yml’, ‘development’). -
.logger ⇒ Object
Get logger.
-
.logger=(logger) ⇒ Object
Set logger.
Instance Method Summary collapse
-
#initialize(options) ⇒ Config
constructor
Create Config object === Options(Hash) *
username
– Username *password
– Password *signature
(Optional if certificate present) – Signature *app_id
– Application ID *cert_path
(Optional if signature present) – Certificate file path. -
#merge!(options) ⇒ Object
Override configurations.
Constructor Details
#initialize(options) ⇒ Config
Create Config object
Options(Hash)
-
username
– Username -
password
– Password -
signature
(Optional if certificate present) – Signature -
app_id
– Application ID -
cert_path
(Optional if signature present) – Certificate file path
53 54 55 |
# File 'lib/sgtn-cldr/core/config.rb', line 53 def initialize() merge!() end |
Instance Attribute Details
#app_id ⇒ Object
Returns the value of attribute app_id.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def app_id @app_id end |
#bundle_mode ⇒ Object
Returns the value of attribute bundle_mode.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def bundle_mode @bundle_mode end |
#cache_expiry_period ⇒ Object
Returns the value of attribute cache_expiry_period.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def cache_expiry_period @cache_expiry_period end |
#cert_path ⇒ Object
Returns the value of attribute cert_path.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def cert_path @cert_path end |
#client_id ⇒ Object
Returns the value of attribute client_id.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def client_secret @client_secret end |
#device_ipaddress ⇒ Object
Returns the value of attribute device_ipaddress.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def device_ipaddress @device_ipaddress end |
#disable_cache ⇒ Object
Returns the value of attribute disable_cache.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def disable_cache @disable_cache end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def endpoint @endpoint end |
#http_proxy ⇒ Object
Returns the value of attribute http_proxy.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def http_proxy @http_proxy end |
#http_timeout ⇒ Object
Returns the value of attribute http_timeout.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def http_timeout @http_timeout end |
#ipn_endpoint ⇒ Object
Returns the value of attribute ipn_endpoint.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def ipn_endpoint @ipn_endpoint end |
#merchant_endpoint ⇒ Object
Returns the value of attribute merchant_endpoint.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def merchant_endpoint @merchant_endpoint end |
#mode ⇒ Object
Returns the value of attribute mode.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def mode @mode end |
#openid_client_id ⇒ Object
Returns the value of attribute openid_client_id.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def openid_client_id @openid_client_id end |
#openid_client_secret ⇒ Object
Returns the value of attribute openid_client_secret.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def openid_client_secret @openid_client_secret end |
#openid_endpoint ⇒ Object
Returns the value of attribute openid_endpoint.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def openid_endpoint @openid_endpoint end |
#openid_redirect_uri ⇒ Object
Returns the value of attribute openid_redirect_uri.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def openid_redirect_uri @openid_redirect_uri end |
#password ⇒ Object
Returns the value of attribute password.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def password @password end |
#platform_endpoint ⇒ Object
Returns the value of attribute platform_endpoint.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def platform_endpoint @platform_endpoint end |
#product_name ⇒ Object
Returns the value of attribute product_name.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def product_name @product_name end |
#rest_endpoint ⇒ Object
Returns the value of attribute rest_endpoint.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def rest_endpoint @rest_endpoint end |
#rest_token_endpoint ⇒ Object
Returns the value of attribute rest_token_endpoint.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def rest_token_endpoint @rest_token_endpoint end |
#sandbox_email_address ⇒ Object
Returns the value of attribute sandbox_email_address.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def sandbox_email_address @sandbox_email_address end |
#signature ⇒ Object
Returns the value of attribute signature.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def signature @signature end |
#source_bundle ⇒ Object
Returns the value of attribute source_bundle.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def source_bundle @source_bundle end |
#subject ⇒ Object
Returns the value of attribute subject.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def subject @subject end |
#token ⇒ Object
Returns the value of attribute token.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def token @token end |
#token_secret ⇒ Object
Returns the value of attribute token_secret.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def token_secret @token_secret end |
#translation_bundle ⇒ Object
Returns the value of attribute translation_bundle.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def translation_bundle @translation_bundle end |
#username ⇒ Object
Returns the value of attribute username.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def username @username end |
#verbose_logging ⇒ Object
Returns the value of attribute verbose_logging.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def verbose_logging @verbose_logging end |
#version ⇒ Object
Returns the value of attribute version.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def version @version end |
#vip_server ⇒ Object
Returns the value of attribute vip_server.
35 36 37 |
# File 'lib/sgtn-cldr/core/config.rb', line 35 def vip_server @vip_server end |
Class Method Details
.config(env = default_environment, override_configuration = {}) ⇒ Object
113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/sgtn-cldr/core/config.rb', line 113 def config(env = default_environment, override_configuration = {}) if env.is_a? Hash override_configuration = env env = default_environment end if override_configuration.nil? or override_configuration.empty? default_config(env) else default_config(env).dup.merge!(override_configuration) end end |
.configurations ⇒ Object
Get raw configurations in Hash format.
135 136 137 |
# File 'lib/sgtn-cldr/core/config.rb', line 135 def configurations @@configurations ||= read_configurations end |
.configurations=(configs) ⇒ Object
Set configuration
140 141 142 143 |
# File 'lib/sgtn-cldr/core/config.rb', line 140 def configurations=(configs) @@config_cache = {} @@configurations = configs && Hash[configs.map{|k,v| [k.to_s, v] }] end |
.configure(options = {}, &block) ⇒ Object Also known as: set_config
94 95 96 97 98 99 100 101 102 |
# File 'lib/sgtn-cldr/core/config.rb', line 94 def configure( = {}, &block) begin self.config.merge!() rescue Errno::ENOENT self.configurations = { default_environment => } end block.call(self.config) if block self.config end |
.default_config(env = nil) ⇒ Object
125 126 127 128 129 130 131 132 |
# File 'lib/sgtn-cldr/core/config.rb', line 125 def default_config(env = nil) env = (env || default_environment).to_s if configurations[env] @@config_cache[env] ||= new(configurations[env]) else raise SgtnClient::Exceptions::MissingConfig.new("Configuration[#{env}] NotFound") end end |
.default_environment ⇒ Object
Get default environment name
84 85 86 |
# File 'lib/sgtn-cldr/core/config.rb', line 84 def default_environment @@default_environment ||= ENV['SGTN_ENV'] || ENV['RACK_ENV'] || ENV['RAILS_ENV'] || "development" end |
.default_environment=(env) ⇒ Object
Set default environment
90 91 92 |
# File 'lib/sgtn-cldr/core/config.rb', line 90 def default_environment=(env) @@default_environment = env.to_s end |
.load(file_name, default_env = default_environment) ⇒ Object
Load configurations from file
Arguments
-
file_name
– Configuration file path -
default_environment
(Optional) – default environment configuration to load
Example
Config.load('config/paypal.yml', 'development')
75 76 77 78 79 80 |
# File 'lib/sgtn-cldr/core/config.rb', line 75 def load(file_name, default_env = default_environment) @@config_cache = {} @@configurations = read_configurations(file_name) @@default_environment = default_env config end |
.logger ⇒ Object
Get logger
151 152 153 154 155 156 157 |
# File 'lib/sgtn-cldr/core/config.rb', line 151 def logger if @@configurations[:mode] == 'live' and Logging.logger.level == Logger::DEBUG Logging.logger.warn "DEBUG log level not allowed in live mode for security of confidential information. Changing log level to INFO..." Logging.logger.level = Logger::INFO end Logging.logger end |
Instance Method Details
#merge!(options) ⇒ Object
Override configurations
58 59 60 61 62 63 |
# File 'lib/sgtn-cldr/core/config.rb', line 58 def merge!() .each do |key, value| send("#{key}=", value) end self end |