summaryrefslogtreecommitdiff
path: root/chef/lib/chef/config.rb
blob: 573cf9dfb74bdf1e09dfcee0a542ab4eba7d18ac (plain)
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
93
94
95
96
97
98
#
# Author:: Adam Jacob (<adam@hjksolutions.com>)
# Copyright:: Copyright (c) 2008 HJK Solutions, LLC
# License:: Apache License, Version 2.0
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
# 
#     http://www.apache.org/licenses/LICENSE-2.0
# 
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

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,
      :merb_log_path => "/var/log/chef/merb.log",
      :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",
      :template_url => "http://localhost:4000",
      :remotefile_url => "http://localhost:4000",
      :search_url => "http://localhost:4000",
      :couchdb_database => "chef",
      :openid_store_path => "/var/chef/openid/db",
      :openid_cstore_path => "/var/chef/openid/cstore",
      :file_cache_path => "/var/chef/cache",
      :executable_path => ENV['PATH'] ? ENV['PATH'].split(File::PATH_SEPARATOR) : []
    }
    
    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