Class: SgtnClient::Config
- Inherits:
-
Object
- Object
- SgtnClient::Config
- Extended by:
- Observable
- Defined in:
- lib/sgtn-client/core/config.rb
Constant Summary collapse
- @@config_cache =
{}
Instance Attribute Summary collapse
-
#app_id ⇒ Object
Returns the value of attribute app_id.
-
#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.
-
#default_language ⇒ Object
Returns the value of attribute default_language.
-
#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
- .available_bundles ⇒ Object
- .available_locales ⇒ Object
-
.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
- .loader ⇒ Object
-
.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
63 64 65 |
# File 'lib/sgtn-client/core/config.rb', line 63 def initialize() merge!() end |
Instance Attribute Details
#app_id ⇒ Object
Returns the value of attribute app_id.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def app_id @app_id end |
#cache_expiry_period ⇒ Object
Returns the value of attribute cache_expiry_period.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def cache_expiry_period @cache_expiry_period end |
#cert_path ⇒ Object
Returns the value of attribute cert_path.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def cert_path @cert_path end |
#client_id ⇒ Object
Returns the value of attribute client_id.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def client_id @client_id end |
#client_secret ⇒ Object
Returns the value of attribute client_secret.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def client_secret @client_secret end |
#default_language ⇒ Object
Returns the value of attribute default_language.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def default_language @default_language end |
#device_ipaddress ⇒ Object
Returns the value of attribute device_ipaddress.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def device_ipaddress @device_ipaddress end |
#disable_cache ⇒ Object
Returns the value of attribute disable_cache.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def disable_cache @disable_cache end |
#endpoint ⇒ Object
Returns the value of attribute endpoint.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def endpoint @endpoint end |
#http_proxy ⇒ Object
Returns the value of attribute http_proxy.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def http_proxy @http_proxy end |
#http_timeout ⇒ Object
Returns the value of attribute http_timeout.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def http_timeout @http_timeout end |
#ipn_endpoint ⇒ Object
Returns the value of attribute ipn_endpoint.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def ipn_endpoint @ipn_endpoint end |
#merchant_endpoint ⇒ Object
Returns the value of attribute merchant_endpoint.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def merchant_endpoint @merchant_endpoint end |
#mode ⇒ Object
Returns the value of attribute mode.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def mode @mode end |
#openid_client_id ⇒ Object
Returns the value of attribute openid_client_id.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def openid_client_id @openid_client_id end |
#openid_client_secret ⇒ Object
Returns the value of attribute openid_client_secret.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def openid_client_secret @openid_client_secret end |
#openid_endpoint ⇒ Object
Returns the value of attribute openid_endpoint.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def openid_endpoint @openid_endpoint end |
#openid_redirect_uri ⇒ Object
Returns the value of attribute openid_redirect_uri.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def openid_redirect_uri @openid_redirect_uri end |
#password ⇒ Object
Returns the value of attribute password.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def password @password end |
#platform_endpoint ⇒ Object
Returns the value of attribute platform_endpoint.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def platform_endpoint @platform_endpoint end |
#product_name ⇒ Object
Returns the value of attribute product_name.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def product_name @product_name end |
#rest_endpoint ⇒ Object
Returns the value of attribute rest_endpoint.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def rest_endpoint @rest_endpoint end |
#rest_token_endpoint ⇒ Object
Returns the value of attribute rest_token_endpoint.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def rest_token_endpoint @rest_token_endpoint end |
#sandbox_email_address ⇒ Object
Returns the value of attribute sandbox_email_address.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def sandbox_email_address @sandbox_email_address end |
#signature ⇒ Object
Returns the value of attribute signature.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def signature @signature end |
#source_bundle ⇒ Object
Returns the value of attribute source_bundle.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def source_bundle @source_bundle end |
#subject ⇒ Object
Returns the value of attribute subject.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def subject @subject end |
#token ⇒ Object
Returns the value of attribute token.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def token @token end |
#token_secret ⇒ Object
Returns the value of attribute token_secret.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def token_secret @token_secret end |
#translation_bundle ⇒ Object
Returns the value of attribute translation_bundle.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def translation_bundle @translation_bundle end |
#username ⇒ Object
Returns the value of attribute username.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def username @username end |
#verbose_logging ⇒ Object
Returns the value of attribute verbose_logging.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def verbose_logging @verbose_logging end |
#version ⇒ Object
Returns the value of attribute version.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def version @version end |
#vip_server ⇒ Object
Returns the value of attribute vip_server.
45 46 47 |
# File 'lib/sgtn-client/core/config.rb', line 45 def vip_server @vip_server end |
Class Method Details
.available_bundles ⇒ Object
170 171 172 173 174 175 176 |
# File 'lib/sgtn-client/core/config.rb', line 170 def available_bundles loader.available_bundles rescue StandardError => e SgtnClient.logger.error 'failed to get available bundles' SgtnClient.logger.error e Set.new end |
.available_locales ⇒ Object
178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/sgtn-client/core/config.rb', line 178 def available_locales bundles = available_bundles return Set.new if bundles.nil? || bundles.empty? unless bundles.respond_to?(:locales) def bundles.locales @locales ||= reduce(Set.new) { |locales, id| locales << id.locale } end changed notify_observers(:available_locales) end bundles.locales end |
.config(env = default_environment, override_configuration = {}) ⇒ Object
116 117 118 119 120 121 122 123 124 125 126 |
# File 'lib/sgtn-client/core/config.rb', line 116 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.
138 139 140 |
# File 'lib/sgtn-client/core/config.rb', line 138 def configurations @@configurations ||= read_configurations end |
.configurations=(configs) ⇒ Object
Set configuration
143 144 145 146 |
# File 'lib/sgtn-client/core/config.rb', line 143 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
97 98 99 100 101 102 103 104 105 |
# File 'lib/sgtn-client/core/config.rb', line 97 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
128 129 130 131 132 133 134 135 |
# File 'lib/sgtn-client/core/config.rb', line 128 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
87 88 89 |
# File 'lib/sgtn-client/core/config.rb', line 87 def default_environment @@default_environment ||= ENV['SGTN_ENV'] || ENV['RACK_ENV'] || ENV['RAILS_ENV'] || "development" end |
.default_environment=(env) ⇒ Object
Set default environment
93 94 95 |
# File 'lib/sgtn-client/core/config.rb', line 93 def default_environment=(env) @@default_environment = env.to_s end |
.load(file_name, default_env = default_environment) ⇒ Object
78 79 80 81 82 83 |
# File 'lib/sgtn-client/core/config.rb', line 78 def load(file_name, default_env = default_environment) @@config_cache = {} @@configurations = read_configurations(file_name) @@default_environment = default_env config end |
.loader ⇒ Object
163 164 165 166 167 168 |
# File 'lib/sgtn-client/core/config.rb', line 163 def loader @loader ||= begin config = SgtnClient::Config.configurations[SgtnClient::Config.default_environment] SgtnClient::TranslationLoader::LoaderFactory.create(config) end end |
.logger ⇒ Object
Get logger
154 155 156 157 158 159 160 |
# File 'lib/sgtn-client/core/config.rb', line 154 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
68 69 70 71 72 73 |
# File 'lib/sgtn-client/core/config.rb', line 68 def merge!() .each do |key, value| send("#{key}=", value) end self end |