stack_master 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5a3ed3d56cf859f61ca5a72f89d42cfefea0cd0d
4
- data.tar.gz: af141896b5817e2ff3a30b3811c3b3fedb1cade9
3
+ metadata.gz: 47ceb9c3a194f4352336f7994f8c4034c8d0ff6e
4
+ data.tar.gz: a990f7e54348aee9b55378ea9518c1518ae4d4eb
5
5
  SHA512:
6
- metadata.gz: 13e318d63d1a51aa9c379a571694cf43bc640aabc9e55d4cc0fb6570d0e44031609cd463fb655805620c39e60877d816d79a4ad6f1fbb909df652bdb27a3ebb1
7
- data.tar.gz: 5fa3fad8464793c9d2d91738095e3e22e09d4029fcff28888f46f9fa30b92ff576761ad0db3df7ce74bc86d2c6237f9ff6813a2b9d81874008bc8659e99d691a
6
+ metadata.gz: 8dafc6386c511101ab2da220d0c632b823fc2add8f6d88430d0cf11f6c94c8256c7b99bc1661f5db3e62051e0383952b3f769baa31dfcae8919305db4390a27e
7
+ data.tar.gz: fa452352356d15ba2fc08ab728e6709a72f793250bd325fa990cc8cb9ccfa15a7ec1b75ea5c5af65deedf3b0dd7f952691f0b5797f1d10c042faa83b48121304
@@ -0,0 +1,6 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.2
4
+ sudo: false
5
+ script:
6
+ - bundle exec rake spec features
data/README.md CHANGED
@@ -169,6 +169,41 @@ web_ami:
169
169
  latest_ami_by_tags: role=web,application=myapp
170
170
  ```
171
171
 
172
+ ### Custom parameter resolvers
173
+
174
+ New parameter resolvers can be created in a separate gem.
175
+
176
+ To create a resolver named my_resolver:
177
+ * Create a new gem using your favorite tool
178
+ * The gem structure must contain the following path:
179
+ ```
180
+ lib/stack_master/parameter_resolvers/my_resolver.rb
181
+ ```
182
+ * That file need to contain a class named `StackMaster::ParameterResolvers::MyResolver`
183
+ that implements a `resolve` method and an initializer taking 2 parameters :
184
+ ```ruby
185
+ module StackMaster
186
+ module ParameterResolvers
187
+ class MyResolver
188
+ def initialize(config, stack_definition)
189
+ @config = config
190
+ @stack_definition = stack_definition
191
+ end
192
+
193
+ def resolve(value)
194
+ value
195
+ end
196
+ end
197
+ end
198
+ end
199
+ ```
200
+ * Note that the filename and classname are both derived from the resolver name
201
+ passed in the parameter file. In our case, the parameters YAML would look like:
202
+ ```yaml
203
+ vpc_id:
204
+ my_resolver: dummy_value
205
+ ```
206
+
172
207
  ## Commands
173
208
 
174
209
  ```bash
data/Rakefile CHANGED
@@ -9,3 +9,17 @@ task :console => :environment do
9
9
  require 'pry'
10
10
  binding.pry
11
11
  end
12
+
13
+ # Add specs and features tests
14
+ begin
15
+ require 'cucumber/rake/task'
16
+ Cucumber::Rake::Task.new(:features) do |t|
17
+ t.cucumber_opts = "features --format pretty"
18
+ end
19
+
20
+ require 'rspec/core/rake_task'
21
+ RSpec::Core::RakeTask.new(:spec) do |t|
22
+ t.rspec_opts = "--format doc"
23
+ end
24
+ rescue LoadError
25
+ end
@@ -27,19 +27,49 @@ module StackMaster
27
27
 
28
28
  private
29
29
 
30
+ def require_parameter_resolver(file_name)
31
+ require "stack_master/parameter_resolvers/#{file_name}"
32
+ rescue LoadError
33
+ raise ResolverNotFound.new(file_name)
34
+ end
35
+
36
+ def load_parameter_resolver(class_name)
37
+ # Check if the class name already exists
38
+ resolver_class_const(class_name)
39
+ rescue NameError
40
+ # If it doesn't, try to load it
41
+ require_parameter_resolver(class_name.underscore)
42
+ end
43
+
30
44
  def resolve_parameter_value(parameter_value)
31
45
  return parameter_value if String === parameter_value || parameter_value.nil?
32
46
  raise InvalidParameter, parameter_value unless Hash === parameter_value
33
47
  raise InvalidParameter, parameter_value unless parameter_value.keys.size == 1
34
- resolver_class_name = parameter_value.keys.first.to_s.camelize
48
+
49
+ resolver_name = parameter_value.keys.first.to_s
50
+ load_parameter_resolver(resolver_name)
51
+
35
52
  value = parameter_value.values.first
36
- resolver_class(resolver_class_name).resolve(value)
53
+ resolver_class_name = resolver_name.camelize
54
+ call_resolver(resolver_class_name, value)
55
+ end
56
+
57
+ def call_resolver(class_name, value)
58
+ resolver_class(class_name).resolve(value)
59
+ end
60
+
61
+ def resolver_class_name(class_name)
62
+ "StackMaster::ParameterResolvers::#{class_name.camelize}"
63
+ end
64
+
65
+ def resolver_class_const(class_name)
66
+ Kernel.const_get(resolver_class_name(class_name))
37
67
  end
38
68
 
39
69
  def resolver_class(class_name)
40
70
  @resolvers.fetch(class_name) do
41
71
  begin
42
- @resolvers[class_name] = Kernel.const_get("StackMaster::ParameterResolvers::#{class_name}").new(@config, @stack_definition)
72
+ @resolvers[class_name] = resolver_class_const(class_name).new(@config, @stack_definition)
43
73
  rescue NameError
44
74
  raise ResolverNotFound, "Could not find parameter resolver called #{class_name}, please double check your configuration"
45
75
  end
@@ -1,3 +1,3 @@
1
1
  module StackMaster
2
- VERSION = "0.0.3"
2
+ VERSION = "0.0.4"
3
3
  end
@@ -1,5 +1,12 @@
1
1
  RSpec.describe StackMaster::ParameterResolver do
2
+ subject(:parameter_resolver) { StackMaster::ParameterResolver.new(config, region, params) }
3
+ let(:params) do
4
+ {
5
+ param: { my_resolver: 2 }
6
+ }
7
+ end
2
8
  let(:config) { double }
9
+ let(:region) { 'us-east-1' }
3
10
  let(:my_resolver) {
4
11
  Class.new do
5
12
  def initialize(config, region)
@@ -10,11 +17,11 @@ RSpec.describe StackMaster::ParameterResolver do
10
17
  end
11
18
  end
12
19
  }
20
+
13
21
  before do
14
22
  stub_const('StackMaster::ParameterResolvers::MyResolver', my_resolver)
15
23
  end
16
24
 
17
-
18
25
  def resolve(params)
19
26
  StackMaster::ParameterResolver.resolve(config, 'us-east-1', params)
20
27
  end
@@ -55,4 +62,29 @@ RSpec.describe StackMaster::ParameterResolver do
55
62
  expect(resolve(param: { my_resolver: 2 }, param2: { my_resolver: 2 })).to eq(param: 10, param2: 10)
56
63
  end
57
64
  end
65
+
66
+ context 'when the resolver class already exist' do
67
+ it 'does not try to load it' do
68
+ expect(parameter_resolver).to receive(:load_parameter_resolver).once.and_call_original
69
+ expect(parameter_resolver).not_to receive(:require_parameter_resolver)
70
+
71
+ parameter_resolver.resolve
72
+ end
73
+ end
74
+
75
+ context 'when the resolver class does not exist' do
76
+ let(:params) do
77
+ {
78
+ param: { dummy_resolver: 2 }
79
+ }
80
+ end
81
+
82
+ it 'tries to load it' do
83
+ expect(parameter_resolver).to receive(:load_parameter_resolver).once.and_call_original
84
+ expect(parameter_resolver).to receive(:require_parameter_resolver).and_return nil
85
+ expect(parameter_resolver).to receive(:call_resolver).and_return nil
86
+
87
+ parameter_resolver.resolve
88
+ end
89
+ end
58
90
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: stack_master
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Steve Hodgkiss
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2015-12-09 00:00:00.000000000 Z
12
+ date: 2015-12-15 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -274,6 +274,7 @@ extra_rdoc_files: []
274
274
  files:
275
275
  - ".gitignore"
276
276
  - ".rspec"
277
+ - ".travis.yml"
277
278
  - Gemfile
278
279
  - LICENSE.txt
279
280
  - README.md
@@ -395,7 +396,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
395
396
  version: '0'
396
397
  requirements: []
397
398
  rubyforge_project:
398
- rubygems_version: 2.4.5.1
399
+ rubygems_version: 2.2.3
399
400
  signing_key:
400
401
  specification_version: 4
401
402
  summary: StackMaster is a sure-footed way of creating, updating and keeping track