class MessageBird::Config
Attributes
Public Class Methods
Returns the current configuration or sets it up
# File lib/messagebird/config.rb, line 22 def configuration @config ||= setup end
Set configuration parameters from a code block, where each method evaluates to a config parameter.
Parameters¶ ↑
- &block
-
Configuration parameter block.
Examples¶ ↑
# Set environment and log level. MessageBird::Config.configure do environment "development" log_level "debug" end
Returns¶ ↑
nil
:api: public
# File lib/messagebird/config.rb, line 158 def configure(&block) ConfigBlock.new(self, &block) if block_given? nil end
# File lib/messagebird/config.rb, line 9 def defaults @defaults ||= { :module => :http, :api_url => "https://api.messagebird.com/api/sms", :username => 'replace_me', :password => 'replace_me', :sender_name => 'replace_me', :test_mode => true, :enabled => false } end
Retrieve the value of a config entry, returning the provided default if the key is not present
Parameters¶ ↑
- key<Object>
-
The key to retrieve the parameter for.
- default<Object>
-
The default value to return if the parameter is not set.
Returns¶ ↑
- Object
-
The value of the configuration parameter or the default.
:api: public
# File lib/messagebird/config.rb, line 113 def fetch(key, default = nil) configuration.fetch(key, default) end
Allows retrieval of single key config values via MessageBird::Config
.<key> Allows single key assignment via Merb.config.<key> = …
Parameters¶ ↑
- method<~to_s>
-
Method name as hash key value.
- *args
-
Value to set the configuration parameter to.
Returns¶ ↑
The value of the entry fetched or assigned to.
:api: public
# File lib/messagebird/config.rb, line 174 def method_missing(method, *args) if method.to_s[-1,1] == '=' self[method.to_s.tr('=','').to_sym] = args.first else self[method] end end
Resets the configuration to its default state
# File lib/messagebird/config.rb, line 98 def reset setup end
Sets up the configuration by storing the given settings.
Parameters¶ ↑
- settings<Hash>
-
Configuration settings to use. These are merged with the defaults.
Returns¶ ↑
The configuration as a hash.
:api: private
# File lib/messagebird/config.rb, line 137 def setup(settings = {}) @config = defaults.merge(settings) end
Yields the configuration.
Block parameters¶ ↑
- c<Hash>
-
The configuration parameters.
Examples¶ ↑
MessageBird::Config.use do |config| config[:exception_details] = false config[:log_stream] = STDOUT end
Returns¶ ↑
nil
:api: public
# File lib/messagebird/config.rb, line 41 def use yield configuration nil end