Module: Elastic::Beanstalk::Config
- Extended by:
- Config
- Included in:
- Config
- Defined in:
- lib/elastic/beanstalk/config.rb
Overview
If this behavior of merging arrays or the defaults are somehow un-sensible, file an issue and we’ll revisit it.
Instance Attribute Summary collapse
Instance Method Summary
collapse
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
102
103
104
105
106
|
# File 'lib/elastic/beanstalk/config.rb', line 102
def method_missing(name, *args, &block)
@configuration[name.to_sym] ||
nil
end
|
Instance Attribute Details
#configuration ⇒ Object
Returns the value of attribute configuration.
39
40
41
|
# File 'lib/elastic/beanstalk/config.rb', line 39
def configuration
@configuration
end
|
Instance Method Details
#clear ⇒ Object
108
109
110
|
# File 'lib/elastic/beanstalk/config.rb', line 108
def clear
init
end
|
#deep_merge!(target, data) ⇒ Object
79
80
81
82
83
84
85
86
87
88
89
90
|
# File 'lib/elastic/beanstalk/config.rb', line 79
def deep_merge!(target, data)
merger = proc { |key, v1, v2|
if (Hash === v1 && Hash === v2)
v1.merge(v2, &merger)
elsif (Array === v1 && Array === v2)
v1.concat(v2)
else
v2
end
}
target.merge! data, &merger
end
|
#find_option_setting(name) ⇒ Object
142
143
144
145
146
147
148
149
150
151
152
|
# File 'lib/elastic/beanstalk/config.rb', line 142
def find_option_setting(name)
name = name.to_sym
options.each_key do |namespace|
options[namespace].each do |option_name, value|
if option_name.eql? name
return to_option_setting(namespace, option_name, value)
end
end
end
return nil
end
|
#find_option_setting_value(name) ⇒ Object
154
155
156
157
|
# File 'lib/elastic/beanstalk/config.rb', line 154
def find_option_setting_value(name)
o = find_option_setting(name)
o[:value] unless o.nil?
end
|
#init ⇒ Object
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
|
# File 'lib/elastic/beanstalk/config.rb', line 19
def init
@configuration = {
environment: nil,
secrets_dir: '~/.aws',
disallow_environments: %w(cucumber test),
strategy: :blue_green,
package: {
dir: 'pkg',
verbose: false,
includes: %w(**/* .ebextensions/**/*),
exclude_files: [],
exclude_dirs: %w(pkg tmp log test-reports)
},
options: {}
}
end
|
#load!(environment = nil, filename = resolve_path('config/eb.yml')) ⇒ Object
This is the main point of entry - we call Settings.load! and provide a name of the file to read as it’s argument. We can also pass in some options, but at the moment it’s being used to allow per-environment overrides in Rails
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
|
# File 'lib/elastic/beanstalk/config.rb', line 45
def load!(environment = nil, filename = resolve_path('config/eb.yml'))
deep_merge!(@configuration, YAML::load_file(filename).deep_symbolize)
@configuration[:environment] = (environment.nil? ? nil : environment.to_s)
if environment && @configuration[environment.to_sym]
[:development, :test, :staging, :production].each do |env|
@configuration.delete(env)
end
environment_settings = YAML::load_file(filename).deep_symbolize
environment_settings = environment_settings[environment.to_sym]
deep_merge!(@configuration, environment_settings)
end
end
|
#option_settings ⇒ Object
custom methods for the specifics of eb.yml settings
118
119
120
121
122
123
124
125
126
127
128
|
# File 'lib/elastic/beanstalk/config.rb', line 118
def option_settings
result = []
options.each_key do |namespace|
options[namespace].each do |option_name, value|
result << to_option_setting(namespace, option_name, value)
end
end
result
end
|
#options ⇒ Object
112
113
114
115
|
# File 'lib/elastic/beanstalk/config.rb', line 112
def options
@configuration[:options] = {} if @configuration[:options].nil?
@configuration[:options]
end
|
#reload!(options = {}, filename) ⇒ Object
92
93
94
95
96
|
# File 'lib/elastic/beanstalk/config.rb', line 92
def reload!(options = {}, filename)
clear
load!(options)
end
|
#resolve_path(relative_path) ⇒ Object
167
168
169
170
171
172
173
174
175
176
|
# File 'lib/elastic/beanstalk/config.rb', line 167
def resolve_path(relative_path)
if defined?(Rails)
Rails.root.join(relative_path)
elsif defined?(Rake.original_dir)
File.expand_path(relative_path, Rake.original_dir)
else
File.expand_path(relative_path, Dir.pwd)
end
end
|
#set_option(namespace, option_name, value) ⇒ Object
130
131
132
133
134
135
136
137
138
139
140
|
# File 'lib/elastic/beanstalk/config.rb', line 130
def set_option(namespace, option_name, value)
namespace = namespace.to_sym
if options[namespace].nil?
options[namespace] = {option_name.to_sym => value}
else
options[namespace][option_name.to_sym] = value
end
end
|
#to_option_setting(namespace, option_name, value) ⇒ Object
159
160
161
162
163
164
165
|
# File 'lib/elastic/beanstalk/config.rb', line 159
def to_option_setting(namespace, option_name, value)
{
:"namespace" => "#{namespace}",
:"option_name" => "#{option_name}",
:"value" => "#{value}"
}
end
|
#to_yaml ⇒ Object
98
99
100
|
# File 'lib/elastic/beanstalk/config.rb', line 98
def to_yaml
end
|