itamae 1.0.0.beta10 → 1.0.0.beta11

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: 81a5923793f82c902667a2d8324149ec2ef160ac
4
- data.tar.gz: dbaf21780d608bfa50de7141b6666fbe8e592656
3
+ metadata.gz: 1e79cccb302b213dead194d1fb5a47ee4421325d
4
+ data.tar.gz: 7ed4180528acd9fb5e0ae50834f85e44aeb91a7e
5
5
  SHA512:
6
- metadata.gz: 92f837c2a09449dca10841e0de3e17f620f18bbbd82391f4b654c6e42737bc127878caec62df874aa7a0c9be94133b92919ec8108480adfd3baeb2485fe652b2
7
- data.tar.gz: 23fdf6eeffcd642c16c2d1b52f774e777c6e9e08065ad57cad48e1b8cf10b64e1d1b675c43b9177c2ba3d448beceb3735bbb476c065a40e10beddcb4acfa5de3
6
+ metadata.gz: 8bf822b67930b8281bfae4eef594eec40c592f65b99086a566fc2c9ef0cfa6d9497ca9cbd34c6ef1827f8353785cd298502f5a4cc079c9b178a7cb437ee44267
7
+ data.tar.gz: 67b3ac8336ae73558e746595212b21301356d4184e2f33486ef3381b052b42698adf24a6051c27d515b1adf1d1e5ef2f872af9ef6c61156c491b0e0b84b6d79a
data/Rakefile CHANGED
@@ -65,3 +65,23 @@ namespace :spec do
65
65
  end
66
66
  end
67
67
 
68
+ namespace :release do
69
+ desc "Bump up version and commit"
70
+ task :version_up do
71
+ version_file = File.expand_path("lib/itamae/version.txt")
72
+ current_version = File.read(version_file).strip
73
+
74
+ if /\A(.+)(\d+)\z/ =~ current_version
75
+ next_version = "#{$1}#{$2.to_i + 1}"
76
+ else
77
+ raise "Invalid version"
78
+ end
79
+
80
+ open(version_file, "w") do |f|
81
+ f.write next_version
82
+ end
83
+ system "git add #{version_file}"
84
+ system "git commit -m 'Bump up version'"
85
+ end
86
+ end
87
+
data/lib/itamae.rb CHANGED
@@ -3,7 +3,7 @@ require "itamae/runner"
3
3
  require "itamae/cli"
4
4
  require "itamae/recipe"
5
5
  require "itamae/resource"
6
- require "itamae/resource_collection"
6
+ require "itamae/recipe_dependencies"
7
7
  require "itamae/logger"
8
8
  require "itamae/node"
9
9
  require "itamae/backend"
data/lib/itamae/recipe.rb CHANGED
@@ -4,16 +4,16 @@ module Itamae
4
4
  class Recipe
5
5
  attr_reader :path
6
6
  attr_reader :runner
7
- attr_reader :resources
7
+ attr_reader :dependencies
8
8
  attr_reader :delayed_actions
9
9
 
10
10
  def initialize(runner, path)
11
11
  @runner = runner
12
12
  @path = path
13
- @resources = ResourceCollection.new
13
+ @dependencies = RecipeDependencies.new
14
14
  @delayed_actions = []
15
15
 
16
- load_resources
16
+ load_dependencies
17
17
  end
18
18
 
19
19
  def node
@@ -21,9 +21,13 @@ module Itamae
21
21
  end
22
22
 
23
23
  def run(options = {})
24
- @resources.each do |resource|
25
- # do action specified in the recipe
26
- resource.run(nil, dry_run: options[:dry_run])
24
+ @dependencies.each do |resource|
25
+ case resource
26
+ when Resource::Base
27
+ resource.run(nil, dry_run: options[:dry_run])
28
+ when Recipe
29
+ resource.run(options)
30
+ end
27
31
  end
28
32
 
29
33
  @delayed_actions.uniq.each do |action, resource|
@@ -33,14 +37,20 @@ module Itamae
33
37
 
34
38
  private
35
39
 
36
- def load_resources
40
+ def load_dependencies
37
41
  instance_eval(File.read(@path), @path, 1)
38
42
  end
39
43
 
40
44
  def method_missing(method, name, &block)
41
45
  klass = Resource.get_resource_class(method)
42
46
  resource = klass.new(self, name, &block)
43
- @resources << resource
47
+ @dependencies << resource
48
+ end
49
+
50
+ def include_recipe(target)
51
+ target = ::File.expand_path(target, File.dirname(@path))
52
+ recipe = Recipe.new(@runner, target)
53
+ @dependencies << recipe
44
54
  end
45
55
  end
46
56
  end
@@ -1,10 +1,10 @@
1
1
  module Itamae
2
- class ResourceCollection < Array
2
+ class RecipeDependencies < Array
3
3
  NotFoundError = Class.new(StandardError)
4
4
 
5
5
  def find_by_description(desc)
6
6
  # desc is like 'resource_type[name]'
7
- self.find do |resource|
7
+ resources.find do |resource|
8
8
  type, name = Itamae::Resource.parse_description(desc)
9
9
  resource.resource_type == type && resource.resource_name == name
10
10
  end.tap do |resource|
@@ -15,7 +15,7 @@ module Itamae
15
15
  end
16
16
 
17
17
  def subscribing(target)
18
- self.map do |resource|
18
+ resources.map do |resource|
19
19
  resource.subscribes_resources.map do |action, r, timing|
20
20
  if r == target
21
21
  [action, resource, timing]
@@ -23,5 +23,17 @@ module Itamae
23
23
  end.compact
24
24
  end.flatten(1)
25
25
  end
26
+
27
+ def resources
28
+ self.select do |item|
29
+ item.is_a?(Resource::Base)
30
+ end
31
+ end
32
+
33
+ def recipes
34
+ self.select do |item|
35
+ item.is_a?(Recipe)
36
+ end
37
+ end
26
38
  end
27
39
  end
@@ -25,6 +25,7 @@ module Itamae
25
25
 
26
26
  define_attribute :action, type: [Symbol, Array], required: true
27
27
 
28
+ attr_reader :recipe
28
29
  attr_reader :resource_name
29
30
  attr_reader :attributes
30
31
  attr_reader :current_attributes
@@ -93,14 +94,14 @@ module Itamae
93
94
 
94
95
  def notifies_resources
95
96
  @notifies.map do |action, resource_desc, timing|
96
- resource = resources.find_by_description(resource_desc)
97
+ resource = recipe.dependencies.find_by_description(resource_desc)
97
98
  [action, resource, timing]
98
99
  end
99
100
  end
100
101
 
101
102
  def subscribes_resources
102
103
  @subscribes.map do |action, resource_desc, timing|
103
- resource = resources.find_by_description(resource_desc)
104
+ resource = recipe.dependencies.find_by_description(resource_desc)
104
105
  [action, resource, timing]
105
106
  end
106
107
  end
@@ -219,10 +220,6 @@ module Itamae
219
220
  @recipe.runner
220
221
  end
221
222
 
222
- def resources
223
- @recipe.resources
224
- end
225
-
226
223
  def run_command(*args)
227
224
  backend.run_command(*args)
228
225
  end
@@ -247,7 +244,7 @@ module Itamae
247
244
  end
248
245
 
249
246
  def notify
250
- action_resource_timing = notifies_resources + resources.subscribing(self)
247
+ action_resource_timing = notifies_resources + recipe.dependencies.subscribing(self)
251
248
  action_resource_timing.uniq.each do |action, resource, timing|
252
249
  case timing
253
250
  when :immediately
@@ -1 +1 @@
1
- 1.0.0.beta10
1
+ 1.0.0.beta11
@@ -1,5 +1,9 @@
1
1
  require 'spec_helper'
2
2
 
3
+ describe file('/tmp/included_recipe') do
4
+ it { should be_file }
5
+ end
6
+
3
7
  describe package('dstat') do
4
8
  it { should be_installed }
5
9
  end
@@ -1,3 +1,5 @@
1
+ include_recipe "./included.rb"
2
+
1
3
  # TODO: replace with user resource
2
4
  execute 'id itamae || useradd itamae'
3
5
 
@@ -0,0 +1 @@
1
+ execute "touch /tmp/included_recipe"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: itamae
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0.beta10
4
+ version: 1.0.0.beta11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ryota Arai
@@ -158,6 +158,7 @@ files:
158
158
  - lib/itamae/logger.rb
159
159
  - lib/itamae/node.rb
160
160
  - lib/itamae/recipe.rb
161
+ - lib/itamae/recipe_dependencies.rb
161
162
  - lib/itamae/resource.rb
162
163
  - lib/itamae/resource/base.rb
163
164
  - lib/itamae/resource/directory.rb
@@ -170,7 +171,6 @@ files:
170
171
  - lib/itamae/resource/remote_file.rb
171
172
  - lib/itamae/resource/service.rb
172
173
  - lib/itamae/resource/template.rb
173
- - lib/itamae/resource_collection.rb
174
174
  - lib/itamae/runner.rb
175
175
  - lib/itamae/version.rb
176
176
  - lib/itamae/version.txt
@@ -179,6 +179,7 @@ files:
179
179
  - spec/integration/recipes/default.rb
180
180
  - spec/integration/recipes/hello.erb
181
181
  - spec/integration/recipes/hello.txt
182
+ - spec/integration/recipes/included.rb
182
183
  - spec/integration/recipes/node.json
183
184
  - spec/integration/spec_helper.rb
184
185
  - spec/unit/lib/itamae/logger_spec.rb
@@ -222,6 +223,7 @@ test_files:
222
223
  - spec/integration/recipes/default.rb
223
224
  - spec/integration/recipes/hello.erb
224
225
  - spec/integration/recipes/hello.txt
226
+ - spec/integration/recipes/included.rb
225
227
  - spec/integration/recipes/node.json
226
228
  - spec/integration/spec_helper.rb
227
229
  - spec/unit/lib/itamae/logger_spec.rb