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.
79
80
81
82
83
84
|
# File 'lib/engineyard-serverside/configuration.rb', line 79
def initialize(options)
opts = string_keys(options)
config = JSON.parse(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
143
144
145
|
# File 'lib/engineyard-serverside/configuration.rb', line 143
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
130
131
132
133
134
135
136
|
# File 'lib/engineyard-serverside/configuration.rb', line 130
def [](key)
if respond_to?(key.to_sym)
send(key.to_sym)
else
configuration[key]
end
end
|
#active_revision ⇒ Object
191
192
193
|
# File 'lib/engineyard-serverside/configuration.rb', line 191
def active_revision
paths.active_revision.read.strip
end
|
#append_config_source(config_source) ⇒ Object
90
91
92
93
94
|
# File 'lib/engineyard-serverside/configuration.rb', line 90
def append_config_source(config_source)
@config_sources ||= []
@config_sources.unshift(config_source.dup)
reload_configuration!
end
|
#configuration ⇒ Object
Also known as:
c
96
97
98
|
# File 'lib/engineyard-serverside/configuration.rb', line 96
def configuration
@configuration ||= @config_sources.inject({}) {|low,high| low.merge(high)}
end
|
#current_role ⇒ Object
208
209
210
|
# File 'lib/engineyard-serverside/configuration.rb', line 208
def current_role
current_roles.first
end
|
#disable_maintenance_page? ⇒ Boolean
We disable the maintenance page if we would have enabled.
247
248
249
|
# File 'lib/engineyard-serverside/configuration.rb', line 247
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.
242
243
244
|
# File 'lib/engineyard-serverside/configuration.rb', line 242
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
126
127
128
|
# File 'lib/engineyard-serverside/configuration.rb', line 126
def fetch(key, *args, &block)
configuration.fetch(key.to_s, *args, &block)
end
|
#framework_env_names ⇒ Object
212
213
214
|
# File 'lib/engineyard-serverside/configuration.rb', line 212
def framework_env_names
%w[RAILS_ENV RACK_ENV NODE_ENV MERB_ENV]
end
|
#framework_envs ⇒ Object
216
217
218
|
# File 'lib/engineyard-serverside/configuration.rb', line 216
def framework_envs
framework_env_names.map { |e| "#{e}=#{framework_env}" }.join(' ')
end
|
#has_key?(key) ⇒ Boolean
138
139
140
|
# File 'lib/engineyard-serverside/configuration.rb', line 138
def has_key?(key)
respond_to?(key.to_sym) || configuration.has_key?(key)
end
|
#latest_revision ⇒ Object
Also known as:
revision
195
196
197
|
# File 'lib/engineyard-serverside/configuration.rb', line 195
def latest_revision
paths.latest_revision.read.strip
end
|
#load_ey_yml_data(data, shell) ⇒ Object
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
|
# File 'lib/engineyard-serverside/configuration.rb', line 107
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
200
201
202
|
# File 'lib/engineyard-serverside/configuration.rb', line 200
def migrate?
!!migration_command
end
|
155
156
157
|
# File 'lib/engineyard-serverside/configuration.rb', line 155
def node
EY::Serverside.node
end
|
163
164
165
166
167
168
169
170
171
|
# File 'lib/engineyard-serverside/configuration.rb', line 163
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
228
229
230
|
# File 'lib/engineyard-serverside/configuration.rb', line 228
def precompile_assets?
precompile_assets == true
end
|
#precompile_assets_inferred? ⇒ Boolean
224
225
226
|
# File 'lib/engineyard-serverside/configuration.rb', line 224
def precompile_assets_inferred?
!precompile_assets? && !skip_precompile_assets?
end
|
#reload_configuration! ⇒ Object
reset cached configuration hash
103
104
105
|
# File 'lib/engineyard-serverside/configuration.rb', line 103
def reload_configuration!
@configuration = nil
end
|
#required_downtime_stack? ⇒ Boolean
Assume downtime required if stack is not specified (nil) just in case.
237
238
239
|
# File 'lib/engineyard-serverside/configuration.rb', line 237
def required_downtime_stack?
[nil, 'nginx_mongrel', 'glassfish'].include? stack
end
|
#respond_to?(meth, include_private = false) ⇒ Boolean
147
148
149
|
# File 'lib/engineyard-serverside/configuration.rb', line 147
def respond_to?(meth, include_private=false)
configuration.key?(meth.to_s) || super
end
|
204
205
206
|
# File 'lib/engineyard-serverside/configuration.rb', line 204
def role
node['instance_role']
end
|
#rollback_paths! ⇒ Object
173
174
175
176
177
178
179
180
181
|
# File 'lib/engineyard-serverside/configuration.rb', line 173
def rollback_paths!
rollback_paths = paths.rollback
if rollback_paths
@paths = rollback_paths
true
else
false
end
end
|
#ruby_version_command ⇒ Object
183
184
185
|
# File 'lib/engineyard-serverside/configuration.rb', line 183
def ruby_version_command
"ruby -v"
end
|
#set_framework_envs ⇒ Object
220
221
222
|
# File 'lib/engineyard-serverside/configuration.rb', line 220
def set_framework_envs
framework_env_names.each { |e| ENV[e] = environment }
end
|
#skip_precompile_assets? ⇒ Boolean
232
233
234
|
# File 'lib/engineyard-serverside/configuration.rb', line 232
def skip_precompile_assets?
precompile_assets == false
end
|
#strategy_class ⇒ Object
159
160
161
|
# File 'lib/engineyard-serverside/configuration.rb', line 159
def strategy_class
EY::Serverside::Strategies.const_get(strategy)
end
|
#string_keys(hsh) ⇒ Object
86
87
88
|
# File 'lib/engineyard-serverside/configuration.rb', line 86
def string_keys(hsh)
hsh.inject({}) { |h,(k,v)| h[k.to_s] = v; h }
end
|
#system_version_command ⇒ Object
187
188
189
|
# File 'lib/engineyard-serverside/configuration.rb', line 187
def system_version_command
"uname -m"
end
|
151
152
153
|
# File 'lib/engineyard-serverside/configuration.rb', line 151
def to_json
configuration.to_json
end
|