Class: Webmaster::Configuration
- Includes:
- Singleton
- Defined in:
- lib/webmaster/configuration.rb
Constant Summary collapse
- VALID_OPTIONS_KEYS =
[ :adapter, :app_id, :app_password, :oauth_token, :endpoint, :site, :ssl, :user_agent, :connection_options ].freeze
- DEFAULT_ADAPTER =
Other adapters are :typhoeus, :patron, :em_synchrony, :excon, :test
:net_http
- DEFAULT_APP_ID =
By default, don’t set an application id
nil
- DEFAULT_APP_PASSWORD =
By default, don’t set an application password
nil
- DEFAULT_OAUTH_TOKEN =
By default, don’t set a user oauth access token
nil
- DEFAULT_LOGIN =
By default, don’t set a user login name
nil
- DEFAULT_PASSWORD =
By default, don’t set a user password
nil
- DEFAULT_BASIC_AUTH =
By default, don’t set a user basic authentication
nil
- DEFAULT_ENDPOINT =
The api endpoint used to connect to Yandex.Webmaster if none is set
'https://webmaster.yandex.ru/api/v2/'.freeze
- DEFAULT_SITE =
The web endpoint used to connect to Yandex.Webmaster if none is set
'https://oauth.yandex.ru/'.freeze
- DEFAULT_SSL =
The default SSL configuration
{}
- DEFAULT_USER_AGENT =
The value sent in the http header for ‘User-Agent’ if none is set
"Webmaster Ruby Gem #{Webmaster::Version::STRING}".freeze
- DEFAULT_CONNECTION_OPTIONS =
By default uses the Faraday connection options if none is set
{}
Instance Method Summary collapse
-
#configure {|_self| ... } ⇒ Object
Convenience method to allow for global setting of configuration options.
- #current ⇒ Object
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
- #keys ⇒ Object
-
#method_missing(method, *args, &block) ⇒ Object
Responds to attribute query or attribute clear.
-
#reset! ⇒ Object
Reset configuration options to their defaults.
- #setup(options = {}) ⇒ Object
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
59 60 61 62 |
# File 'lib/webmaster/configuration.rb', line 59 def initialize super self.reset! end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method, *args, &block) ⇒ Object
Responds to attribute query or attribute clear
100 101 102 103 104 105 106 107 108 109 |
# File 'lib/webmaster/configuration.rb', line 100 def method_missing(method, *args, &block) # :nodoc: case method.to_s when /^(.*)\?$/ return !!self.send($1.to_s) when /^clear_(.*)$/ self.send("#{$1.to_s}=", nil) else super end end |
Instance Method Details
#configure {|_self| ... } ⇒ Object
Convenience method to allow for global setting of configuration options
95 96 97 |
# File 'lib/webmaster/configuration.rb', line 95 def configure yield self end |
#current ⇒ Object
68 69 70 |
# File 'lib/webmaster/configuration.rb', line 68 def current VALID_OPTIONS_KEYS.inject({}) { |h, k| h[k] = send(k); h } end |
#keys ⇒ Object
64 65 66 |
# File 'lib/webmaster/configuration.rb', line 64 def keys VALID_OPTIONS_KEYS end |
#reset! ⇒ Object
Reset configuration options to their defaults
81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/webmaster/configuration.rb', line 81 def reset! self.adapter = DEFAULT_ADAPTER self.app_id = DEFAULT_APP_ID self.app_password = DEFAULT_APP_PASSWORD self.oauth_token = DEFAULT_OAUTH_TOKEN self.endpoint = DEFAULT_ENDPOINT self.site = DEFAULT_SITE self.ssl = DEFAULT_SSL self.user_agent = DEFAULT_USER_AGENT self. = DEFAULT_CONNECTION_OPTIONS self end |
#setup(options = {}) ⇒ Object
72 73 74 75 76 77 |
# File 'lib/webmaster/configuration.rb', line 72 def setup( = {}) raise ArgumentError if (.symbolize_keys!.keys - VALID_OPTIONS_KEYS).any? .each { |k,v| send("#{k}=", v) } self end |