Module: Spice::Config

Included in:
Spice
Defined in:
lib/spice/config.rb

Constant Summary

DEFAULT_SERVER_URL =

The default Chef server URL

"http://localhost:4000"
DEFAULT_CHEF_VERSION =

The default Chef version (changing this will enable disable certain features)

"0.10.8"
DEFAULT_USER_AGENT =

The default Spice User-Agent header

"Spice #{Spice::VERSION}"
DEFAULT_CONNECTION_OPTIONS =

Default connection options

{}
VALID_OPTIONS_KEYS =

An array of valid config options

[
  :server_url,
  :client_name,
  :key_file,
  :raw_key,
  :chef_version,
  :user_agent,
  :connection_options
]

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) extended(base)

Reset all config options to default when the module is extended



33
34
35
# File 'lib/spice/config.rb', line 33

def self.extended(base)
  base.reset
end

Instance Method Details

- (Object) options

Create an options hash from valid options keys



53
54
55
56
57
# File 'lib/spice/config.rb', line 53

def options
  options = {}
  VALID_OPTIONS_KEYS.each{|k| options[k] = send(k)}
  options
end

- (Object) reset

Reset all config options to their defaults



60
61
62
63
64
65
66
67
68
# File 'lib/spice/config.rb', line 60

def reset
  self.user_agent = DEFAULT_USER_AGENT
  self.server_url = DEFAULT_SERVER_URL
  self.chef_version = DEFAULT_CHEF_VERSION
  self.client_name = nil
  self.key_file = nil
  self.raw_key = nil
  self.connection_options = DEFAULT_CONNECTION_OPTIONS
end

- (Object) setup {|Spice| ... }

Convenience method to configure Spice in a block

Examples:

Configuring spice

Spice.setup do |s|
  s.server_url  = "http://chef.example.com:4000"
  s.client_name = "admin"
  s.key_file    = "/home/admin/.chef/admin.pem"
end

Yield Parameters:

  • Spice

Yield Returns:

  • Spice



47
48
49
50
# File 'lib/spice/config.rb', line 47

def setup
  yield self
  self
end