Class: EY::Serverside::Deploy::Configuration
Class Method Summary
collapse
Instance Method Summary
collapse
#all_releases, legacy_path_helper
Constructor Details
Returns a new instance of Configuration.
80
81
82
83
84
85
|
# File 'lib/engineyard-serverside/configuration.rb', line 80
def initialize(options)
opts = string_keys(options)
config = MultiJson.load(opts.delete("config") || "{}")
append_config_source opts append_config_source config end
|
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &blk) ⇒ Object
Delegate to the configuration objects
144
145
146
|
# File 'lib/engineyard-serverside/configuration.rb', line 144
def method_missing(meth, *args, &blk)
configuration.key?(meth.to_s) ? configuration.fetch(meth.to_s) : super
end
|
Class Method Details
.def_boolean_option(name, default = nil, &block) ⇒ Object
Calls def_option and adds a name? predicate method
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/engineyard-serverside/configuration.rb', line 24
def self.def_boolean_option(name, default=nil, &block)
key ||= name.to_s
define_method(name) do
if block
val = fetch(key) {instance_eval(&block)}
else
val = fetch(key, default)
end
not [false,nil,'false','nil'].include?(val) end
alias_method(:"#{name}?", name)
end
|
.def_option(name, default = nil, key = nil, &block) ⇒ Object
Defines a fetch method for the specified key. If no default and no block is specified, it means the key is required and if it’s accessed without a value, it should raise.
14
15
16
17
18
19
20
21
|
# File 'lib/engineyard-serverside/configuration.rb', line 14
def self.def_option(name, default=nil, key=nil, &block)
key ||= name.to_s
if block_given?
define_method(name) { fetch(key) {instance_eval(&block)} }
else
define_method(name) { fetch(key, default) }
end
end
|
.def_required_option(name, key = nil) ⇒ Object
Required options do not have a default value. An option being required does not mean that it is always supplied, it just means that if it is accessed and it does not exist, an error will be raised instead of returning a nil default value.
42
43
44
45
46
47
|
# File 'lib/engineyard-serverside/configuration.rb', line 42
def self.def_required_option(name, key=nil)
key ||= name.to_s
define_method(name) do
fetch(key) { raise "Required configuration option not found: #{key.inspect}" }
end
end
|
Instance Method Details
131
132
133
134
135
136
137
|
# File 'lib/engineyard-serverside/configuration.rb', line 131
def [](key)
if respond_to?(key.to_sym)
send(key.to_sym)
else
configuration[key]
end
end
|
#active_revision ⇒ Object
192
193
194
|
# File 'lib/engineyard-serverside/configuration.rb', line 192
def active_revision
paths.active_revision.read.strip
end
|
#append_config_source(config_source) ⇒ Object
91
92
93
94
95
|
# File 'lib/engineyard-serverside/configuration.rb', line 91
def append_config_source(config_source)
@config_sources ||= []
@config_sources.unshift(config_source.dup)
reload_configuration!
end
|
#configuration ⇒ Object
Also known as:
c
97
98
99
|
# File 'lib/engineyard-serverside/configuration.rb', line 97
def configuration
@configuration ||= @config_sources.inject({}) {|low,high| low.merge(high)}
end
|
#current_role ⇒ Object
209
210
211
|
# File 'lib/engineyard-serverside/configuration.rb', line 209
def current_role
current_roles.first
end
|
#disable_maintenance_page? ⇒ Boolean
We disable the maintenance page if we would have enabled.
248
249
250
|
# File 'lib/engineyard-serverside/configuration.rb', line 248
def disable_maintenance_page?
enable_maintenance_page?
end
|
#enable_maintenance_page? ⇒ Boolean
Enable if stack requires it or if overridden in the ey.yml config.
243
244
245
|
# File 'lib/engineyard-serverside/configuration.rb', line 243
def enable_maintenance_page?
maintenance_on_restart? || (migrate? && maintenance_on_migrate?)
end
|
#fetch(key, *args, &block) ⇒ Object
Fetch a key from the config. You must supply either a default second argument, or a default block
127
128
129
|
# File 'lib/engineyard-serverside/configuration.rb', line 127
def fetch(key, *args, &block)
configuration.fetch(key.to_s, *args, &block)
end
|
#framework_env_names ⇒ Object
213
214
215
|
# File 'lib/engineyard-serverside/configuration.rb', line 213
def framework_env_names
%w[RAILS_ENV RACK_ENV NODE_ENV MERB_ENV]
end
|
#framework_envs ⇒ Object
217
218
219
|
# File 'lib/engineyard-serverside/configuration.rb', line 217
def framework_envs
framework_env_names.map { |e| "#{e}=#{framework_env}" }.join(' ')
end
|
#has_key?(key) ⇒ Boolean
139
140
141
|
# File 'lib/engineyard-serverside/configuration.rb', line 139
def has_key?(key)
respond_to?(key.to_sym) || configuration.has_key?(key)
end
|
#latest_revision ⇒ Object
Also known as:
revision
196
197
198
|
# File 'lib/engineyard-serverside/configuration.rb', line 196
def latest_revision
paths.latest_revision.read.strip
end
|
#load_ey_yml_data(data, shell) ⇒ Object
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
|
# File 'lib/engineyard-serverside/configuration.rb', line 108
def load_ey_yml_data(data, shell)
environments = data['environments']
if environments && environments[environment_name]
shell.substatus "ey.yml configuration loaded for environment #{environment_name.inspect}."
env_data = string_keys(environments[environment_name])
shell.debug "#{environment_name}:\n#{env_data.pretty_inspect}"
append_config_source(string_keys(env_data)) true
else
shell.info "No matching ey.yml configuration found for environment #{environment_name.inspect}."
shell.debug "ey.yml:\n#{data.pretty_inspect}"
false
end
end
|
#migrate? ⇒ Boolean
201
202
203
|
# File 'lib/engineyard-serverside/configuration.rb', line 201
def migrate?
!!migration_command
end
|
156
157
158
|
# File 'lib/engineyard-serverside/configuration.rb', line 156
def node
EY::Serverside.node
end
|
164
165
166
167
168
169
170
171
172
|
# File 'lib/engineyard-serverside/configuration.rb', line 164
def paths
@paths ||= Paths.new({
:home => configuration['home_path'],
:app_name => app_name,
:deploy_root => configuration['deploy_to'],
:active_release => configuration['release_path'],
:repository_cache => configuration['repository_cache'],
})
end
|
#precompile_assets? ⇒ Boolean
229
230
231
|
# File 'lib/engineyard-serverside/configuration.rb', line 229
def precompile_assets?
precompile_assets == true || precompile_assets == "true"
end
|
#precompile_assets_inferred? ⇒ Boolean
225
226
227
|
# File 'lib/engineyard-serverside/configuration.rb', line 225
def precompile_assets_inferred?
!precompile_assets? && !skip_precompile_assets?
end
|
#reload_configuration! ⇒ Object
reset cached configuration hash
104
105
106
|
# File 'lib/engineyard-serverside/configuration.rb', line 104
def reload_configuration!
@configuration = nil
end
|
#required_downtime_stack? ⇒ Boolean
Assume downtime required if stack is not specified (nil) just in case.
238
239
240
|
# File 'lib/engineyard-serverside/configuration.rb', line 238
def required_downtime_stack?
[nil, 'nginx_mongrel', 'glassfish'].include? stack
end
|
#respond_to?(meth, include_private = false) ⇒ Boolean
148
149
150
|
# File 'lib/engineyard-serverside/configuration.rb', line 148
def respond_to?(meth, include_private=false)
configuration.key?(meth.to_s) || super
end
|
205
206
207
|
# File 'lib/engineyard-serverside/configuration.rb', line 205
def role
node['instance_role']
end
|
#rollback_paths! ⇒ Object
174
175
176
177
178
179
180
181
182
|
# File 'lib/engineyard-serverside/configuration.rb', line 174
def rollback_paths!
rollback_paths = paths.rollback
if rollback_paths
@paths = rollback_paths
true
else
false
end
end
|
#ruby_version_command ⇒ Object
184
185
186
|
# File 'lib/engineyard-serverside/configuration.rb', line 184
def ruby_version_command
"ruby -v"
end
|
#set_framework_envs ⇒ Object
221
222
223
|
# File 'lib/engineyard-serverside/configuration.rb', line 221
def set_framework_envs
framework_env_names.each { |e| ENV[e] = environment }
end
|
#skip_precompile_assets? ⇒ Boolean
233
234
235
|
# File 'lib/engineyard-serverside/configuration.rb', line 233
def skip_precompile_assets?
precompile_assets == false || precompile_assets == "false"
end
|
#strategy_class ⇒ Object
160
161
162
|
# File 'lib/engineyard-serverside/configuration.rb', line 160
def strategy_class
EY::Serverside::Strategies.const_get(strategy)
end
|
#string_keys(hsh) ⇒ Object
87
88
89
|
# File 'lib/engineyard-serverside/configuration.rb', line 87
def string_keys(hsh)
hsh.inject({}) { |h,(k,v)| h[k.to_s] = v; h }
end
|
#system_version_command ⇒ Object
188
189
190
|
# File 'lib/engineyard-serverside/configuration.rb', line 188
def system_version_command
"uname -m"
end
|
152
153
154
|
# File 'lib/engineyard-serverside/configuration.rb', line 152
def to_json
MultiJson.dump(configuration)
end
|