Class: EY::Config
- Inherits:
-
Object
show all
- Defined in:
- lib/engineyard/config.rb
Defined Under Namespace
Classes: ConfigurationError, EnvironmentConfig
Constant Summary
collapse
- CONFIG_FILES =
["config/ey.yml", "ey.yml"].map {|path| Pathname.new(path)}.freeze
- TEMPLATE_PATHNAME =
Pathname.new(__FILE__).dirname.join('templates','ey.yml').freeze
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(file = nil) ⇒ Config
Returns a new instance of Config.
36
37
38
39
40
|
# File 'lib/engineyard/config.rb', line 36
def initialize(file = nil)
@path = file ? Pathname.new(file) : self.class.pathname
@config = self.class.load_config(@path)
@config["environments"] ||= {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
42
43
44
45
46
47
48
49
|
# File 'lib/engineyard/config.rb', line 42
def method_missing(meth, *args, &blk)
key = meth.to_s.downcase
if @config.key?(key)
@config[key]
else
super
end
end
|
Instance Attribute Details
#path ⇒ Object
Returns the value of attribute path.
34
35
36
|
# File 'lib/engineyard/config.rb', line 34
def path
@path
end
|
Class Method Details
.load_config(path = pathname) ⇒ Object
24
25
26
27
28
29
30
31
32
|
# File 'lib/engineyard/config.rb', line 24
def self.load_config(path = pathname)
config = YAML.load_file(path.to_s) if path && path.exist?
config ||= {}
unless Hash === config
raise "ey.yml load error: Expected a Hash but a #{config.class.name} was returned."
end
config
end
|
.pathname ⇒ Object
16
17
18
|
# File 'lib/engineyard/config.rb', line 16
def self.pathname
CONFIG_FILES.find{|pathname| pathname.exist? }
end
|
.pathname_for_write ⇒ Object
12
13
14
|
# File 'lib/engineyard/config.rb', line 12
def self.pathname_for_write
pathname || CONFIG_FILES.find{|pathname| pathname.dirname.exist? }
end
|
.template_pathname ⇒ Object
20
21
22
|
# File 'lib/engineyard/config.rb', line 20
def self.template_pathname
TEMPLATE_PATHNAME
end
|
Instance Method Details
#[](key) ⇒ Object
64
65
66
|
# File 'lib/engineyard/config.rb', line 64
def [](key)
@config[key.to_s.downcase]
end
|
#default_endpoint ⇒ Object
76
77
78
|
# File 'lib/engineyard/config.rb', line 76
def default_endpoint
"https://cloud.engineyard.com/"
end
|
#default_endpoint? ⇒ Boolean
80
81
82
|
# File 'lib/engineyard/config.rb', line 80
def default_endpoint?
default_endpoint == endpoint
end
|
#default_environment ⇒ Object
84
85
86
87
88
89
|
# File 'lib/engineyard/config.rb', line 84
def default_environment
d = environments.find do |name, env|
env["default"]
end
d && d.first
end
|
#defaults ⇒ Object
91
92
93
|
# File 'lib/engineyard/config.rb', line 91
def defaults
@config['defaults'] ||= {}
end
|
#endpoint ⇒ Object
68
69
70
|
# File 'lib/engineyard/config.rb', line 68
def endpoint
env_var_endpoint || default_endpoint
end
|
#env_var_endpoint ⇒ Object
72
73
74
|
# File 'lib/engineyard/config.rb', line 72
def env_var_endpoint
ENV["CLOUD_URL"]
end
|
#environment_config(environment_name) ⇒ Object
95
96
97
98
|
# File 'lib/engineyard/config.rb', line 95
def environment_config(environment_name)
environments[environment_name] ||= {}
EnvironmentConfig.new(environments[environment_name], environment_name, self)
end
|
#fetch(key, default = nil, &block) ⇒ Object
56
57
58
|
# File 'lib/engineyard/config.rb', line 56
def fetch(key, default = nil, &block)
block ? @config.fetch(key.to_s, &block) : @config.fetch(key.to_s, default)
end
|
#fetch_from_defaults(key, default = nil, &block) ⇒ Object
60
61
62
|
# File 'lib/engineyard/config.rb', line 60
def fetch_from_defaults(key, default=nil, &block)
block ? defaults.fetch(key.to_s, &block) : defaults.fetch(key.to_s, default)
end
|
#respond_to?(meth) ⇒ Boolean
51
52
53
54
|
# File 'lib/engineyard/config.rb', line 51
def respond_to?(meth)
key = meth.to_s.downcase
@config.key?(key) || super
end
|