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
- EY_YML_HINTS =
"# ey.yml supports many deploy configuration options when committed in an\n# application's repository.\n#\n# Valid locations: REPO_ROOT/ey.yml or REPO_ROOT/config/ey.yml.\n#\n# Examples options (defaults apply to all environments for this application):\n#\n# defaults:\n# migrate: true # Default --migrate choice for ey deploy\n# migration_command: 'rake migrate' # Default migrate command to run when migrations are enabled\n# branch: default_deploy_branch # Branch/ref to be deployed by default during ey deploy\n# bundle_without: development test # The string to pass to bundle install --without ''\n# maintenance_on_migrate: true # Enable maintenance page during migrate action (use with caution) (default: true)\n# maintenance_on_restart: false # Enable maintanence page during every deploy (default: false for unicorn & passenger)\n# ignore_database_adapter_warning: false # Hide the warning shown when the Gemfile does not contain a recognized database adapter (mongodb for example)\n# your_own_custom_key: 'any attribute you put in ey.yml is available in deploy hooks'\n# environments:\n# YOUR_ENVIRONMENT_NAME: # All options pertain only to the named environment\n# any_option: 'override any of the options above with specific options for certain environments'\n# migrate: false\n#\n# Further information available here:\n# https://support.cloud.engineyard.com/entries/20996661-customize-your-deployment-on-engine-yard-cloud\n#\n# NOTE: Please commit this file into your git repository.\n#\n"
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(file = nil) ⇒ Config
Returns a new instance of Config.
12
13
14
15
16
17
18
19
20
21
22
|
# File 'lib/engineyard/config.rb', line 12
def initialize(file = nil)
@path = file ? Pathname.new(file) : CONFIG_FILES.find{|pathname| pathname.exist? }
@config = @path ? YAML.load_file(@path.to_s) : {}
@config ||= {}
unless Hash === @config
raise "ey.yml load error: Expected a Hash but a #{@config.class.name} was returned."
end
@config["environments"] ||= {}
end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
24
25
26
27
28
29
30
31
|
# File 'lib/engineyard/config.rb', line 24
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.
10
11
12
|
# File 'lib/engineyard/config.rb', line 10
def path
@path
end
|
Instance Method Details
#[](key) ⇒ Object
46
47
48
|
# File 'lib/engineyard/config.rb', line 46
def [](key)
@config[key.to_s.downcase]
end
|
#default_endpoint ⇒ Object
58
59
60
|
# File 'lib/engineyard/config.rb', line 58
def default_endpoint
"https://cloud.engineyard.com/"
end
|
#default_endpoint? ⇒ Boolean
62
63
64
|
# File 'lib/engineyard/config.rb', line 62
def default_endpoint?
default_endpoint == endpoint
end
|
#default_environment ⇒ Object
66
67
68
69
70
71
|
# File 'lib/engineyard/config.rb', line 66
def default_environment
d = environments.find do |name, env|
env["default"]
end
d && d.first
end
|
#defaults ⇒ Object
73
74
75
|
# File 'lib/engineyard/config.rb', line 73
def defaults
@config['defaults'] ||= {}
end
|
#endpoint ⇒ Object
50
51
52
|
# File 'lib/engineyard/config.rb', line 50
def endpoint
env_var_endpoint || default_endpoint
end
|
#ensure_path ⇒ Object
139
140
141
142
143
144
145
146
147
148
149
150
|
# File 'lib/engineyard/config.rb', line 139
def ensure_path
return if @path && @path.exist?
unless EY::Repo.exist?
raise "Not in application directory. Unable to save configuration."
end
if Pathname.new('config').exist?
@path = Pathname.new('config/ey.yml')
else
@path = Pathname.new('ey.yml')
end
@path
end
|
#env_var_endpoint ⇒ Object
54
55
56
|
# File 'lib/engineyard/config.rb', line 54
def env_var_endpoint
ENV["CLOUD_URL"]
end
|
#environment_config(environment_name) ⇒ Object
77
78
79
80
|
# File 'lib/engineyard/config.rb', line 77
def environment_config(environment_name)
environments[environment_name] ||= {}
EnvironmentConfig.new(environments[environment_name], environment_name, self)
end
|
131
132
133
134
135
136
137
|
# File 'lib/engineyard/config.rb', line 131
def
if @path.exist?
existing = @path.readlines.grep(/^#/).map {|line| line.strip }.join("\n")
else
EY_YML_HINTS
end
end
|
#fetch(key, default = nil, &block) ⇒ Object
38
39
40
|
# File 'lib/engineyard/config.rb', line 38
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
42
43
44
|
# File 'lib/engineyard/config.rb', line 42
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
33
34
35
36
|
# File 'lib/engineyard/config.rb', line 33
def respond_to?(meth)
key = meth.to_s.downcase
@config.key?(key) || super
end
|
#set_default_option(key, value) ⇒ Object
97
98
99
100
|
# File 'lib/engineyard/config.rb', line 97
def set_default_option(key, value)
defaults[key] = value
write_ey_yaml
end
|
#set_environment_option(environment_name, key, value) ⇒ Object
82
83
84
85
86
|
# File 'lib/engineyard/config.rb', line 82
def set_environment_option(environment_name, key, value)
environments[environment_name] ||= {}
environments[environment_name][key] = value
write_ey_yaml
end
|
#write_ey_yaml ⇒ Object
88
89
90
91
92
93
94
95
|
# File 'lib/engineyard/config.rb', line 88
def write_ey_yaml
ensure_path
=
@path.open('w') do |f|
f.puts
f.puts YAML.dump(@config)
end
end
|