itamae 1.2.4 → 1.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +12 -0
- data/lib/itamae.rb +7 -0
- data/lib/itamae/definition.rb +14 -49
- data/lib/itamae/recipe.rb +30 -15
- data/lib/itamae/resource.rb +17 -11
- data/lib/itamae/version.txt +1 -1
- data/spec/integration/default_spec.rb +5 -0
- data/spec/integration/recipes/default.rb +1 -3
- data/spec/integration/recipes/define/default.rb +6 -0
- data/spec/integration/recipes/define/files/remote_file_in_definition +1 -0
- data/spec/unit/lib/itamae/resource_spec.rb +0 -8
- metadata +6 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 167d45d181120c9a6aa4b7323c20681d925680b7
|
4
|
+
data.tar.gz: e8e0218836135ffdb4d9684ed07a5ee3027fca0f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f0e733d5d7adce8fdbab8a02a3c147b3e2ca6c000a05926d3144a2b8f0ba4f9d744bb59ce41d6586853d12fddca50ce7657e97856ac5dd5cf205307f86ce5859
|
7
|
+
data.tar.gz: 1ca5a89dc112249321a75a831482eb679252ec5a3854dd8f9ea9d20009b60ebffe65eb577977442fab2588f1e3c9447b44e3db82be4a1a77d17d53fd24fffb0e
|
data/CHANGELOG.md
CHANGED
data/lib/itamae.rb
CHANGED
data/lib/itamae/definition.rb
CHANGED
@@ -3,9 +3,13 @@ require 'itamae'
|
|
3
3
|
module Itamae
|
4
4
|
class Definition < Resource::Base
|
5
5
|
class << self
|
6
|
-
|
6
|
+
attr_accessor :definition_block
|
7
|
+
attr_accessor :defined_in_recipe
|
8
|
+
|
9
|
+
def create_class(name, params, defined_in_recipe, &block)
|
7
10
|
Class.new(self).tap do |klass|
|
8
11
|
klass.definition_block = block
|
12
|
+
klass.defined_in_recipe = defined_in_recipe
|
9
13
|
|
10
14
|
klass.define_attribute :action, default: :run
|
11
15
|
params.each_pair do |key, value|
|
@@ -13,62 +17,23 @@ module Itamae
|
|
13
17
|
end
|
14
18
|
end
|
15
19
|
end
|
16
|
-
|
17
|
-
def definition_block=(block)
|
18
|
-
@definition_block = block
|
19
|
-
end
|
20
|
-
|
21
|
-
def definition_block
|
22
|
-
@definition_block
|
23
|
-
end
|
24
20
|
end
|
25
21
|
|
26
22
|
def initialize(*args)
|
27
23
|
super
|
28
24
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
25
|
+
r = Recipe::RecipeFromDefinition.new(
|
26
|
+
runner,
|
27
|
+
self.class.defined_in_recipe.path,
|
28
|
+
)
|
29
|
+
recipe.children << r
|
37
30
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
context = Context.new(self, @attributes.merge(name: resource_name))
|
42
|
-
context.instance_exec(&block)
|
43
|
-
@children = context.children
|
31
|
+
r.definition = self
|
32
|
+
r.load(params: @attributes.merge(name: resource_name))
|
44
33
|
end
|
45
34
|
|
46
|
-
|
47
|
-
|
48
|
-
attr_reader :children
|
49
|
-
|
50
|
-
def initialize(definition, params, &block)
|
51
|
-
@definition = definition
|
52
|
-
@params = params
|
53
|
-
@children = RecipeChildren.new
|
54
|
-
end
|
55
|
-
|
56
|
-
def respond_to_missing?(method, include_private = false)
|
57
|
-
Resource.get_resource_class(method)
|
58
|
-
true
|
59
|
-
rescue NameError
|
60
|
-
false
|
61
|
-
end
|
62
|
-
|
63
|
-
def method_missing(method, name, &block)
|
64
|
-
klass = Resource.get_resource_class(method)
|
65
|
-
resource = klass.new(@definition.recipe, name, &block)
|
66
|
-
@children << resource
|
67
|
-
end
|
68
|
-
|
69
|
-
def node
|
70
|
-
@definition.recipe.runner.node
|
71
|
-
end
|
35
|
+
def run(*args)
|
36
|
+
# nothing
|
72
37
|
end
|
73
38
|
end
|
74
39
|
end
|
data/lib/itamae/recipe.rb
CHANGED
@@ -36,12 +36,13 @@ module Itamae
|
|
36
36
|
::File.dirname(@path)
|
37
37
|
end
|
38
38
|
|
39
|
-
def load
|
40
|
-
EvalContext.new(self)
|
39
|
+
def load(variables = {})
|
40
|
+
context = EvalContext.new(self, variables)
|
41
|
+
context.instance_eval(File.read(path), path, 1)
|
41
42
|
end
|
42
43
|
|
43
44
|
def run(options = {})
|
44
|
-
|
45
|
+
show_banner
|
45
46
|
|
46
47
|
Logger.formatter.with_indent do
|
47
48
|
@children.run(options)
|
@@ -54,11 +55,19 @@ module Itamae
|
|
54
55
|
end
|
55
56
|
end
|
56
57
|
|
58
|
+
private
|
59
|
+
|
60
|
+
def show_banner
|
61
|
+
Logger.info "Recipe: #{@path}"
|
62
|
+
end
|
63
|
+
|
57
64
|
class EvalContext
|
58
|
-
def initialize(recipe)
|
65
|
+
def initialize(recipe, variables)
|
59
66
|
@recipe = recipe
|
60
67
|
|
61
|
-
|
68
|
+
variables.each do |k, v|
|
69
|
+
define_singleton_method(k) { v }
|
70
|
+
end
|
62
71
|
end
|
63
72
|
|
64
73
|
def respond_to_missing?(method, include_private = false)
|
@@ -83,16 +92,7 @@ module Itamae
|
|
83
92
|
end
|
84
93
|
|
85
94
|
def define(name, params = {}, &block)
|
86
|
-
|
87
|
-
if Resource.const_defined?(class_name)
|
88
|
-
Logger.warn "Redefine class. (#{class_name})"
|
89
|
-
return
|
90
|
-
end
|
91
|
-
|
92
|
-
Resource.const_set(
|
93
|
-
Resource.get_resource_class_name(name),
|
94
|
-
Definition.create_class(name, params, &block)
|
95
|
-
)
|
95
|
+
Resource.define_resource(name, Definition.create_class(name, params, @recipe, &block))
|
96
96
|
end
|
97
97
|
|
98
98
|
def include_recipe(target)
|
@@ -124,5 +124,20 @@ module Itamae
|
|
124
124
|
@recipe.runner
|
125
125
|
end
|
126
126
|
end
|
127
|
+
|
128
|
+
class RecipeFromDefinition < Recipe
|
129
|
+
attr_accessor :definition
|
130
|
+
|
131
|
+
def load(variables = {})
|
132
|
+
context = EvalContext.new(self, variables)
|
133
|
+
context.instance_eval(&@definition.class.definition_block)
|
134
|
+
end
|
135
|
+
|
136
|
+
private
|
137
|
+
|
138
|
+
def show_banner
|
139
|
+
Logger.debug "#{@definition.resource_type}[#{@definition.resource_name}]"
|
140
|
+
end
|
141
|
+
end
|
127
142
|
end
|
128
143
|
end
|
data/lib/itamae/resource.rb
CHANGED
@@ -23,26 +23,32 @@ module Itamae
|
|
23
23
|
ParseError = Class.new(StandardError)
|
24
24
|
|
25
25
|
class << self
|
26
|
-
def get_resource_class_name(method)
|
27
|
-
to_camel_case(method.to_s)
|
28
|
-
end
|
29
|
-
|
30
|
-
def get_resource_plugin_class_name(method)
|
31
|
-
'::Itamae::Plugin::Resource::' + to_camel_case(method.to_s)
|
32
|
-
end
|
33
|
-
|
34
26
|
def to_camel_case(str)
|
35
27
|
str.split('_').map {|part| part.capitalize}.join
|
36
28
|
end
|
37
29
|
|
38
30
|
def get_resource_class(method)
|
39
31
|
begin
|
40
|
-
const_get(
|
41
|
-
rescue NameError
|
42
|
-
|
32
|
+
self.const_get(to_camel_case(method.to_s))
|
33
|
+
rescue NameError
|
34
|
+
begin
|
35
|
+
::Itamae::Plugin::Resource.const_get(to_camel_case(method.to_s))
|
36
|
+
rescue NameError
|
37
|
+
raise Error, "#{method} resource is missing."
|
38
|
+
end
|
43
39
|
end
|
44
40
|
end
|
45
41
|
|
42
|
+
def define_resource(name, klass)
|
43
|
+
class_name = to_camel_case(name.to_s)
|
44
|
+
if Resource.const_defined?(class_name)
|
45
|
+
Logger.warn "Redefine class. (#{class_name})"
|
46
|
+
return
|
47
|
+
end
|
48
|
+
|
49
|
+
Resource.const_set(class_name, klass)
|
50
|
+
end
|
51
|
+
|
46
52
|
def parse_description(desc)
|
47
53
|
if /\A([^\[]+)\[([^\]]+)\]\z/ =~ desc
|
48
54
|
[$1, $2]
|
data/lib/itamae/version.txt
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.2.
|
1
|
+
1.2.5
|
@@ -130,3 +130,8 @@ describe file('/tmp/created_by_definition') do
|
|
130
130
|
it { should be_file }
|
131
131
|
its(:content) { should eq("name:name,key:value,message:Hello, Itamae\n") }
|
132
132
|
end
|
133
|
+
|
134
|
+
describe file('/tmp/remote_file_in_definition') do
|
135
|
+
it { should be_file }
|
136
|
+
its(:content) { should eq("definition_example\n") }
|
137
|
+
end
|
@@ -207,9 +207,7 @@ end
|
|
207
207
|
|
208
208
|
#####
|
209
209
|
|
210
|
-
define
|
211
|
-
execute "echo 'name:#{params[:name]},key:#{params[:key]},message:#{node[:message]}' > /tmp/created_by_definition"
|
212
|
-
end
|
210
|
+
include_recipe "define/default.rb"
|
213
211
|
|
214
212
|
definition_example "name" do
|
215
213
|
key 'value'
|
@@ -0,0 +1 @@
|
|
1
|
+
definition_example
|
@@ -2,14 +2,6 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
module Itamae
|
4
4
|
describe Resource do
|
5
|
-
describe ".get_resource_class_name" do
|
6
|
-
let(:method) { :foo_bar_baz }
|
7
|
-
it "returns camel-cased string" do
|
8
|
-
expect(described_class.get_resource_class_name(method)).
|
9
|
-
to eq("FooBarBaz")
|
10
|
-
end
|
11
|
-
end
|
12
|
-
|
13
5
|
describe ".parse_description" do
|
14
6
|
context "with valid description" do
|
15
7
|
it "returns type and name" do
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: itamae
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.2.
|
4
|
+
version: 1.2.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryota Arai
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-03-
|
11
|
+
date: 2015-03-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: thor
|
@@ -223,6 +223,8 @@ files:
|
|
223
223
|
- spec/integration/default_spec.rb
|
224
224
|
- spec/integration/recipes/default.rb
|
225
225
|
- spec/integration/recipes/default2.rb
|
226
|
+
- spec/integration/recipes/define/default.rb
|
227
|
+
- spec/integration/recipes/define/files/remote_file_in_definition
|
226
228
|
- spec/integration/recipes/files/remote_file_auto
|
227
229
|
- spec/integration/recipes/hello.erb
|
228
230
|
- spec/integration/recipes/hello.txt
|
@@ -269,6 +271,8 @@ test_files:
|
|
269
271
|
- spec/integration/default_spec.rb
|
270
272
|
- spec/integration/recipes/default.rb
|
271
273
|
- spec/integration/recipes/default2.rb
|
274
|
+
- spec/integration/recipes/define/default.rb
|
275
|
+
- spec/integration/recipes/define/files/remote_file_in_definition
|
272
276
|
- spec/integration/recipes/files/remote_file_auto
|
273
277
|
- spec/integration/recipes/hello.erb
|
274
278
|
- spec/integration/recipes/hello.txt
|