1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
|
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
# License:: GNU General Public License version 2 or later
#
# This program and entire repository is free software; you can
# redistribute it and/or modify it under the terms of the GNU
# General Public License as published by the Free Software
# Foundation; either version 2 of the License, or any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
#
require File.join(File.dirname(__FILE__), "mixin", "check_helper")
require File.join(File.dirname(__FILE__), "mixin", "from_file")
# Chef::Config[:variable]
# @config = Chef::Config.new()
#
# Chef::ConfigFast << Chef::Config
#
# Chef::Config.from_file(foo)
# Chef::Resource.from_file (NoMethodError)
# Chef::Config[:cookbook_path]
# Chef::Config.cookbook_path
# Chef::Config.cookbook_path "one", "two"
class Chef
class Config
include Chef::Mixin::CheckHelper
@configuration = {
:cookbook_path => [ "/etc/chef/site-cookbook", "/etc/chef/cookbook" ],
:node_path => "/etc/chef/node",
:file_store_path => "/var/chef/store",
:search_index_path => "/var/chef/search_index",
:log_level => :info,
:log_location => STDOUT,
:openid_providers => nil,
:ssl_verify_mode => :verify_none,
:rest_timeout => 60,
:couchdb_url => "http://localhost:5984",
:registration_url => "http://localhost:4000",
:openid_url => "http://localhost:4001",
}
class << self
include Chef::Mixin::FromFile
def configure(&block)
yield @configuration
end
def [](config_option)
if @configuration.has_key?(config_option.to_sym)
@configuration[config_option.to_sym]
else
raise ArgumentError, "Cannot find configuration option #{config_option.to_s}"
end
end
def []=(config_option, value)
@configuration[config_option.to_sym] = value
end
def has_key?(key)
@configuration.has_key?(key.to_sym)
end
def method_missing(method_symbol, *args)
if @configuration.has_key?(method_symbol)
if args.length == 1
@configuration[method_symbol] = args[0]
elsif args.length > 1
@configuration[method_symbol] = args
end
return @configuration[method_symbol]
else
raise ArgumentError, "Cannot find configuration option #{method_symbol.to_s}"
end
end
end # class << self
end
end
|