Class: Glabssms::Configuration
- Inherits:
-
Object
- Object
- Glabssms::Configuration
- Defined in:
- lib/glabssms/configuration.rb
Constant Summary collapse
- READABLE_ATTRIBUTES =
%i[app_id app_secret cross_telco_short_code short_code]
- WRITABLE_ATTRIBUTES =
%i[app_id app_secret cross_telco_short_code short_code logger]
Class Method Summary collapse
- ._default_logger ⇒ Object
- .client ⇒ Object
- .expectant_reader(*attributes) ⇒ Object
- .instantiate ⇒ Object
- .logger ⇒ Object
Instance Method Summary collapse
- #assert_has_keys ⇒ Object
-
#initialize(options = {}) ⇒ Configuration
constructor
A new instance of Configuration.
- #inspect ⇒ Object
- #logger ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ Configuration
Returns a new instance of Configuration.
45 46 47 48 49 50 |
# File 'lib/glabssms/configuration.rb', line 45 def initialize( = {}) WRITABLE_ATTRIBUTES.each do |attr| instance_variable_set "@#{attr}", [attr] || Glabssms.configuration.send(attr) end end |
Class Method Details
._default_logger ⇒ Object
56 57 58 59 60 |
# File 'lib/glabssms/configuration.rb', line 56 def self._default_logger logger = Logger.new(STDOUT) logger.level = Logger::INFO logger end |
.client ⇒ Object
33 34 35 |
# File 'lib/glabssms/configuration.rb', line 33 def self.client Glabssms::Client.new(instantiate) end |
.expectant_reader(*attributes) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/glabssms/configuration.rb', line 13 def self.expectant_reader(*attributes) attributes.each do |attribute| ( class << self self end ) .send(:define_method, attribute) do attribute_value = instance_variable_get("@#{attribute}") if attribute_value.nil? || attribute_value.to_s.empty? raise ConfigurationError.new( "Glabssms::Configuration.#{attribute} needs to be set" ) end attribute_value end end end |
.instantiate ⇒ Object
37 38 39 |
# File 'lib/glabssms/configuration.rb', line 37 def self.instantiate config = new end |
.logger ⇒ Object
41 42 43 |
# File 'lib/glabssms/configuration.rb', line 41 def self.logger @logger ||= _default_logger end |
Instance Method Details
#assert_has_keys ⇒ Object
66 67 68 69 70 71 72 |
# File 'lib/glabssms/configuration.rb', line 66 def assert_has_keys if app_id.nil? || app_secret.nil? || cross_telco_short_code.nil? || short_code.nil? raise ConfigurationError.new( 'Glabssms::Configuration app_id, app_secret, cross_telco_short_code, short_code and are required.' ) end end |
#inspect ⇒ Object
62 63 64 |
# File 'lib/glabssms/configuration.rb', line 62 def inspect super.gsub(/@app_secret=\".*\"/, '@app_secret="[FILTERED]"') end |
#logger ⇒ Object
52 53 54 |
# File 'lib/glabssms/configuration.rb', line 52 def logger @logger ||= self.class._default_logger end |