Module: Gems::Configuration
- Included in:
- Gems
- Defined in:
- lib/gems/configuration.rb
Constant Summary collapse
- VALID_OPTIONS_KEYS =
An array of valid keys in the options hash when configuring a Gems::Client
[ :format, :key, :password, :user_agent, :username, ]
- DEFAULT_FORMAT =
Note:
JSON is preferred over XML because it is more concise and faster to parse.
The response format appended to the path if none is set
:json
- DEFAULT_KEY =
Attempt to automatically load credentials
begin YAML.load(File.read(File.("~/.gem/credentials")))[:rubygems_api_key] rescue Errno::ENOENT nil end
- DEFAULT_USER_AGENT =
The value sent in the 'User-Agent' header if none is set
"Gems #{Gems::VERSION}".freeze
Class Method Summary collapse
-
.extended(base) ⇒ Object
When this module is extended, set all configuration options to their default values.
Instance Method Summary collapse
-
#configure {|_self| ... } ⇒ Object
Convenience method to allow configuration options to be set in a block.
-
#options ⇒ Object
Create a hash of options and their values.
-
#reset ⇒ Object
Reset all configuration options to defaults.
Class Method Details
.extended(base) ⇒ Object
When this module is extended, set all configuration options to their default values
33 34 35 |
# File 'lib/gems/configuration.rb', line 33 def self.extended(base) base.reset end |
Instance Method Details
#configure {|_self| ... } ⇒ Object
Convenience method to allow configuration options to be set in a block
38 39 40 |
# File 'lib/gems/configuration.rb', line 38 def configure yield self end |
#options ⇒ Object
Create a hash of options and their values
43 44 45 46 47 |
# File 'lib/gems/configuration.rb', line 43 def = {} VALID_OPTIONS_KEYS.each{|k| [k] = send(k)} end |
#reset ⇒ Object
Reset all configuration options to defaults
50 51 52 53 54 55 56 57 |
# File 'lib/gems/configuration.rb', line 50 def reset self.format = DEFAULT_FORMAT self.key = DEFAULT_KEY self.password = nil self.user_agent = DEFAULT_USER_AGENT self.username = nil self end |