itamae-mitsurin 0.50 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (172) hide show
  1. checksums.yaml +5 -5
  2. data/lib/itamae-mitsurin/cli.rb +0 -2
  3. data/lib/itamae-mitsurin/logger.rb +74 -20
  4. data/lib/itamae-mitsurin/mitsurin/base.rb +109 -0
  5. data/lib/itamae-mitsurin/mitsurin/base_task.rb +147 -0
  6. data/lib/itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/recipes/default.rb +0 -11
  7. data/lib/itamae-mitsurin/mitsurin/itamae_task.rb +44 -130
  8. data/lib/itamae-mitsurin/mitsurin/itamae_with_target_task.rb +64 -157
  9. data/lib/itamae-mitsurin/mitsurin/local_task.rb +57 -131
  10. data/lib/itamae-mitsurin/mitsurin/serverspec_task.rb +56 -81
  11. data/lib/itamae-mitsurin/mitsurin/serverspec_with_target_task.rb +80 -143
  12. data/lib/itamae-mitsurin/node.rb +0 -1
  13. data/lib/itamae-mitsurin/notification.rb +0 -1
  14. data/lib/itamae-mitsurin/recipe.rb +2 -5
  15. data/lib/itamae-mitsurin/resource.rb +1 -1
  16. data/lib/itamae-mitsurin/resource/base.rb +0 -12
  17. data/lib/itamae-mitsurin/resource/http_request.rb +23 -8
  18. data/lib/itamae-mitsurin/resource/s3_file.rb +33 -0
  19. data/lib/itamae-mitsurin/runner.rb +4 -5
  20. data/lib/itamae-mitsurin/version.txt +1 -1
  21. metadata +6 -221
  22. data/lib/itamae-mitsurin/mitsurin/itamae_with_git_task.rb +0 -159
  23. data/lib/itamae-mitsurin/mitsurin/task_base.rb +0 -100
  24. data/test/test_itamae-mitsurin.rb +0 -18
  25. data/test/test_itamae-mitsurin/ext/test_specinfra.rb +0 -39
  26. data/test/test_itamae-mitsurin/handler/test_base.rb +0 -40
  27. data/test/test_itamae-mitsurin/handler/test_debug.rb +0 -10
  28. data/test/test_itamae-mitsurin/handler/test_fluentd.rb +0 -44
  29. data/test/test_itamae-mitsurin/handler/test_json.rb +0 -22
  30. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/.rspec +0 -2
  31. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/Gemfile +0 -3
  32. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/Rakefile +0 -2
  33. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/environments/.keep +0 -0
  34. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/environments/sample.json +0 -7
  35. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/keys/.keep +0 -0
  36. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/nodes/.keep +0 -0
  37. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/nodes/sample01.json +0 -9
  38. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/roles/.keep +0 -0
  39. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/attributes/.keep +0 -0
  40. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/files/.keep +0 -0
  41. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/recipes/default.rb +0 -1
  42. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/spec/default_spec.rb +0 -1
  43. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/site-cookbooks/_base/_base/templates/.keep +0 -0
  44. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/spec/spec_helper.rb +0 -33
  45. data/test/test_itamae-mitsurin/mitsurin/creators/templates/project/tmp-nodes/.keep +0 -0
  46. data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/attributes/.keep +0 -0
  47. data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/files/.keep +0 -0
  48. data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/recipes/default.rb +0 -0
  49. data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/spec/.keep +0 -0
  50. data/test/test_itamae-mitsurin/mitsurin/creators/templates/site-cookbooks/templates/.keep +0 -0
  51. data/test/test_itamae-mitsurin/mitsurin/creators/test_cookbook.rb +0 -24
  52. data/test/test_itamae-mitsurin/mitsurin/creators/test_project.rb +0 -24
  53. data/test/test_itamae-mitsurin/mitsurin/test_cli.rb +0 -56
  54. data/test/test_itamae-mitsurin/mitsurin/test_creators.rb +0 -19
  55. data/test/test_itamae-mitsurin/mitsurin/test_itamae_task.rb +0 -197
  56. data/test/test_itamae-mitsurin/mitsurin/test_itamae_with_git_task.rb +0 -213
  57. data/test/test_itamae-mitsurin/mitsurin/test_serverspec_task.rb +0 -123
  58. data/test/test_itamae-mitsurin/resource/test_aws_ebs_volume.rb +0 -84
  59. data/test/test_itamae-mitsurin/resource/test_base.rb +0 -374
  60. data/test/test_itamae-mitsurin/resource/test_directory.rb +0 -63
  61. data/test/test_itamae-mitsurin/resource/test_execute.rb +0 -26
  62. data/test/test_itamae-mitsurin/resource/test_file.rb +0 -176
  63. data/test/test_itamae-mitsurin/resource/test_gem_package.rb +0 -81
  64. data/test/test_itamae-mitsurin/resource/test_git.rb +0 -94
  65. data/test/test_itamae-mitsurin/resource/test_group.rb +0 -42
  66. data/test/test_itamae-mitsurin/resource/test_http_request.rb +0 -71
  67. data/test/test_itamae-mitsurin/resource/test_link.rb +0 -33
  68. data/test/test_itamae-mitsurin/resource/test_local_ruby_block.rb +0 -15
  69. data/test/test_itamae-mitsurin/resource/test_package.rb +0 -44
  70. data/test/test_itamae-mitsurin/resource/test_remote_directory.rb +0 -84
  71. data/test/test_itamae-mitsurin/resource/test_remote_file.rb +0 -54
  72. data/test/test_itamae-mitsurin/resource/test_service.rb +0 -69
  73. data/test/test_itamae-mitsurin/resource/test_template.rb +0 -53
  74. data/test/test_itamae-mitsurin/resource/test_user.rb +0 -93
  75. data/test/test_itamae-mitsurin/test_backend.rb +0 -297
  76. data/test/test_itamae-mitsurin/test_cli.rb +0 -88
  77. data/test/test_itamae-mitsurin/test_definition.rb +0 -40
  78. data/test/test_itamae-mitsurin/test_ext.rb +0 -1
  79. data/test/test_itamae-mitsurin/test_handler.rb +0 -21
  80. data/test/test_itamae-mitsurin/test_handler_proxy.rb +0 -38
  81. data/test/test_itamae-mitsurin/test_logger.rb +0 -124
  82. data/test/test_itamae-mitsurin/test_mitsurin.rb +0 -14
  83. data/test/test_itamae-mitsurin/test_node.rb +0 -74
  84. data/test/test_itamae-mitsurin/test_notification.rb +0 -46
  85. data/test/test_itamae-mitsurin/test_recipe.rb +0 -171
  86. data/test/test_itamae-mitsurin/test_recipe_children.rb +0 -86
  87. data/test/test_itamae-mitsurin/test_resource.rb +0 -73
  88. data/test/test_itamae-mitsurin/test_runner.rb +0 -124
  89. data/test/test_itamae-mitsurin/test_version.rb +0 -3
  90. data/test/test_itamae-mitsurin/version.txt +0 -1
  91. data/test_project/.rspec +0 -2
  92. data/test_project/Gemfile +0 -4
  93. data/test_project/Rakefile +0 -3
  94. data/test_project/environments/.keep +0 -0
  95. data/test_project/keys/.keep +0 -0
  96. data/test_project/nodes/.keep +0 -0
  97. data/test_project/nodes/test.json +0 -9
  98. data/test_project/roles/.keep +0 -0
  99. data/test_project/roles/test.json +0 -14
  100. data/test_project/site-cookbooks/_base/_base/attributes/.keep +0 -0
  101. data/test_project/site-cookbooks/_base/_base/files/.keep +0 -0
  102. data/test_project/site-cookbooks/_base/_base/recipes/default.rb +0 -1
  103. data/test_project/site-cookbooks/_base/_base/spec/default_spec.rb +0 -1
  104. data/test_project/site-cookbooks/_base/_base/templates/.keep +0 -0
  105. data/test_project/site-cookbooks/a_test/directory/attributes/.keep +0 -0
  106. data/test_project/site-cookbooks/a_test/directory/files/.keep +0 -0
  107. data/test_project/site-cookbooks/a_test/directory/recipes/default.rb +0 -8
  108. data/test_project/site-cookbooks/a_test/directory/spec/.keep +0 -0
  109. data/test_project/site-cookbooks/a_test/directory/spec/default_spec.rb +0 -4
  110. data/test_project/site-cookbooks/a_test/directory/templates/.keep +0 -0
  111. data/test_project/site-cookbooks/a_test/package/attributes/.keep +0 -0
  112. data/test_project/site-cookbooks/a_test/package/files/.keep +0 -0
  113. data/test_project/site-cookbooks/a_test/package/recipes/default.rb +0 -2
  114. data/test_project/site-cookbooks/a_test/package/spec/.keep +0 -0
  115. data/test_project/site-cookbooks/a_test/package/spec/default_spec.rb +0 -4
  116. data/test_project/site-cookbooks/a_test/package/templates/.keep +0 -0
  117. data/test_project/site-cookbooks/a_test/service/attributes/.keep +0 -0
  118. data/test_project/site-cookbooks/a_test/service/files/.keep +0 -0
  119. data/test_project/site-cookbooks/a_test/service/recipes/default.rb +0 -5
  120. data/test_project/site-cookbooks/a_test/service/spec/.keep +0 -0
  121. data/test_project/site-cookbooks/a_test/service/spec/default_spec.rb +0 -6
  122. data/test_project/site-cookbooks/a_test/service/templates/.keep +0 -0
  123. data/test_project/site-cookbooks/b_test/git/attributes/.keep +0 -0
  124. data/test_project/site-cookbooks/b_test/git/files/.keep +0 -0
  125. data/test_project/site-cookbooks/b_test/git/recipes/default.rb +0 -5
  126. data/test_project/site-cookbooks/b_test/git/spec/.keep +0 -0
  127. data/test_project/site-cookbooks/b_test/git/spec/default_spec.rb +0 -5
  128. data/test_project/site-cookbooks/b_test/git/templates/.keep +0 -0
  129. data/test_project/site-cookbooks/b_test/link/attributes/.keep +0 -0
  130. data/test_project/site-cookbooks/b_test/link/files/.keep +0 -0
  131. data/test_project/site-cookbooks/b_test/link/recipes/default.rb +0 -5
  132. data/test_project/site-cookbooks/b_test/link/spec/.keep +0 -0
  133. data/test_project/site-cookbooks/b_test/link/spec/default_spec.rb +0 -5
  134. data/test_project/site-cookbooks/b_test/link/templates/.keep +0 -0
  135. data/test_project/site-cookbooks/b_test/remote_file/attributes/.keep +0 -0
  136. data/test_project/site-cookbooks/b_test/remote_file/files/.keep +0 -0
  137. data/test_project/site-cookbooks/b_test/remote_file/files/remote_file.sh +0 -1
  138. data/test_project/site-cookbooks/b_test/remote_file/recipes/default.rb +0 -9
  139. data/test_project/site-cookbooks/b_test/remote_file/spec/.keep +0 -0
  140. data/test_project/site-cookbooks/b_test/remote_file/spec/default_spec.rb +0 -7
  141. data/test_project/site-cookbooks/b_test/remote_file/templates/.keep +0 -0
  142. data/test_project/site-cookbooks/b_test/template/attributes/.keep +0 -0
  143. data/test_project/site-cookbooks/b_test/template/files/.keep +0 -0
  144. data/test_project/site-cookbooks/b_test/template/recipes/default.rb +0 -5
  145. data/test_project/site-cookbooks/b_test/template/spec/.keep +0 -0
  146. data/test_project/site-cookbooks/b_test/template/spec/default_spec.rb +0 -7
  147. data/test_project/site-cookbooks/b_test/template/templates/.keep +0 -0
  148. data/test_project/site-cookbooks/b_test/template/templates/template.erb +0 -2
  149. data/test_project/site-cookbooks/c_test/execute/attributes/.keep +0 -0
  150. data/test_project/site-cookbooks/c_test/execute/files/.keep +0 -0
  151. data/test_project/site-cookbooks/c_test/execute/recipes/default.rb +0 -6
  152. data/test_project/site-cookbooks/c_test/execute/spec/.keep +0 -0
  153. data/test_project/site-cookbooks/c_test/execute/spec/default_spec.rb +0 -6
  154. data/test_project/site-cookbooks/c_test/execute/templates/.keep +0 -0
  155. data/test_project/site-cookbooks/c_test/remote_directory/attributes/.keep +0 -0
  156. data/test_project/site-cookbooks/c_test/remote_directory/files/.keep +0 -0
  157. data/test_project/site-cookbooks/c_test/remote_directory/recipes/default.rb +0 -10
  158. data/test_project/site-cookbooks/c_test/remote_directory/spec/.keep +0 -0
  159. data/test_project/site-cookbooks/c_test/remote_directory/spec/default_spec.rb +0 -20
  160. data/test_project/site-cookbooks/c_test/remote_directory/templates/.keep +0 -0
  161. data/test_project/site-cookbooks/c_test/remote_directory/templates/remote_dir/a.txt +0 -0
  162. data/test_project/site-cookbooks/c_test/remote_directory/templates/remote_dir/b.txt +0 -0
  163. data/test_project/site-cookbooks/c_test/remote_directory/templates/remote_dir/c.txt +0 -0
  164. data/test_project/site-cookbooks/d_spec/air/attributes/.keep +0 -0
  165. data/test_project/site-cookbooks/d_spec/air/files/.keep +0 -0
  166. data/test_project/site-cookbooks/d_spec/air/recipes/default.rb +0 -0
  167. data/test_project/site-cookbooks/d_spec/air/spec/.keep +0 -0
  168. data/test_project/site-cookbooks/d_spec/air/spec/default_spec.rb +0 -0
  169. data/test_project/site-cookbooks/d_spec/air/templates/.keep +0 -0
  170. data/test_project/spec/spec_helper.rb +0 -33
  171. data/test_project/tmp-nodes/.keep +0 -0
  172. data/test_project/tmp-nodes/test.json +0 -12
@@ -1,38 +0,0 @@
1
- module ItamaeMitsurin
2
- class HandlerProxy
3
- def initialize
4
- @instances = []
5
- end
6
-
7
- def register_instance(instance)
8
- @instances << instance
9
- end
10
-
11
- def event(*args, &block)
12
- if block_given?
13
- _event_with_block(*args, &block)
14
- else
15
- _event(*args)
16
- end
17
- end
18
-
19
- private
20
-
21
- def _event(*args)
22
- @instances.each do |i|
23
- i.event(*args)
24
- end
25
- end
26
-
27
- def _event_with_block(event_name, *args, &block)
28
- event("#{event_name}_started".to_sym, *args)
29
- block.call
30
- rescue
31
- event("#{event_name}_failed".to_sym, *args)
32
- raise
33
- else
34
- event("#{event_name}_completed".to_sym, *args)
35
- end
36
- end
37
- end
38
-
@@ -1,124 +0,0 @@
1
- require 'itamae-mitsurin'
2
- require 'logger'
3
- require 'ansi/code'
4
-
5
- module ItamaeMitsurin
6
- module Logger
7
- module Helper
8
- def with_indent
9
- indent
10
- yield
11
- ensure
12
- outdent
13
- end
14
-
15
- def with_indent_if(condition, &block)
16
- if condition
17
- with_indent(&block)
18
- else
19
- block.call
20
- end
21
- end
22
-
23
- def indent
24
- self.indent_depth += 1
25
- end
26
-
27
- def outdent
28
- self.indent_depth -= 1
29
- self.indent_depth = 0 if self.indent_depth < 0
30
- end
31
-
32
- def indent_depth
33
- @indent_depth ||= 0
34
- end
35
-
36
- def indent_depth=(val)
37
- @indent_depth = val
38
- end
39
-
40
- def color(code, &block)
41
- if self.formatter.respond_to?(:color)
42
- self.formatter.color(code, &block)
43
- else
44
- block.call
45
- end
46
- end
47
-
48
- %w!debug info warn error fatal unknown!.each do |level|
49
- module_eval(<<-EOC, __FILE__, __LINE__ + 1)
50
- def #{level}(msg)
51
- super(" " * indent_depth + msg)
52
- end
53
- EOC
54
- end
55
- end
56
-
57
- class Formatter
58
- attr_accessor :colored
59
-
60
- def call(severity, datetime, progname, msg)
61
- log = "%s : %s\n" % ["%5s" % severity, msg2str(msg)]
62
- if colored
63
- colorize(log, severity)
64
- else
65
- log
66
- end
67
- end
68
-
69
- def color(code)
70
- prev_color = @color
71
- @color = code
72
- yield
73
- ensure
74
- @color = prev_color
75
- end
76
-
77
- private
78
-
79
- def msg2str(msg)
80
- case msg
81
- when ::String
82
- msg
83
- when ::Exception
84
- "#{ msg.message } (#{ msg.class })\n" <<
85
- (msg.backtrace || []).join("\n")
86
- else
87
- msg.inspect
88
- end
89
- end
90
-
91
- def colorize(str, severity)
92
- if @color
93
- color_code = @color
94
- else
95
- color_code = case severity
96
- when "INFO"
97
- :clear
98
- when "WARN"
99
- :magenta
100
- when "ERROR"
101
- :red
102
- else
103
- :clear
104
- end
105
- end
106
- ANSI.public_send(color_code) { str }
107
- end
108
- end
109
- end
110
-
111
- @logger = ::Logger.new($stdout).tap do |l|
112
- l.formatter = ItamaeMitsurin::Logger::Formatter.new
113
- end.extend(ItamaeMitsurin::Logger::Helper)
114
-
115
- class << self
116
- def logger
117
- @logger
118
- end
119
-
120
- def logger=(l)
121
- @logger = l.extend(ItamaeMitsurin::Logger::Helper)
122
- end
123
- end
124
- end
@@ -1,14 +0,0 @@
1
- require 'itamae-mitsurin/version'
2
- require 'itamae-mitsurin/mitsurin/cli'
3
- require 'itamae-mitsurin/mitsurin/creators'
4
- require 'aws-sdk'
5
- #require 'itamae-mitsurin/mitsurin/itamae_task'
6
- #require 'itamae-mitsurin/mitsurin/serverspec_task'
7
- #require 'itamae-mitsurin/mitsurin/itamae_with_git_task'
8
-
9
-
10
- module ItamaeMitsurin
11
- module Mitsurin
12
- # TODO
13
- end
14
- end
@@ -1,74 +0,0 @@
1
- require 'itamae-mitsurin'
2
- require 'hashie'
3
- require 'json'
4
- require 'schash'
5
-
6
- module ItamaeMitsurin
7
- class Node
8
- ValidationError = Class.new(StandardError)
9
-
10
- attr_reader :mash
11
-
12
- def initialize(hash, backend)
13
- @mash = Hashie::Mash.new(hash)
14
- @backend = backend
15
- end
16
-
17
- def reverse_merge(other_hash)
18
- self.class.new(_reverse_merge(other_hash), @backend)
19
- end
20
-
21
- def reverse_merge!(other_hash)
22
- @mash.replace(_reverse_merge(other_hash))
23
- end
24
-
25
- def [](key)
26
- if @mash.has_key?(key)
27
- @mash[key]
28
- else
29
- fetch_inventory_value(key)
30
- end
31
- end
32
-
33
- def validate!(&block)
34
- errors = Schash::Validator.new(&block).validate(@mash)
35
- unless errors.empty?
36
- errors.each do |error|
37
- ItamaeMitsurin.logger.error "'#{error.position.join('->')}' #{error.message}"
38
- end
39
- raise ValidationError
40
- end
41
- end
42
-
43
- private
44
-
45
- def _reverse_merge(other_hash)
46
- Hashie::Mash.new(other_hash).merge(@mash)
47
- end
48
-
49
- def method_missing(method, *args)
50
- if @mash.respond_to?(method)
51
- return @mash.public_send(method, *args)
52
- elsif args.empty? && value = fetch_inventory_value(method)
53
- return value
54
- end
55
-
56
- super
57
- end
58
-
59
- def respond_to?(method, priv = false)
60
- @mash.respond_to?(method, priv) || super
61
- end
62
-
63
- def fetch_inventory_value(key)
64
- value = @backend.host_inventory[key]
65
- if value.is_a?(Hash)
66
- value = Hashie::Mash.new(value)
67
- end
68
-
69
- value
70
- rescue NotImplementedError, NameError
71
- nil
72
- end
73
- end
74
- end
@@ -1,46 +0,0 @@
1
- require 'itamae-mitsurin'
2
-
3
- module ItamaeMitsurin
4
- class Notification < Struct.new(:defined_in_resource, :action, :target_resource_desc, :timing)
5
- def self.create(*args)
6
- self.new(*args).tap(&:validate!)
7
- end
8
-
9
- def resource
10
- runner.children.find_resource_by_description(target_resource_desc)
11
- end
12
-
13
- def run
14
- action_resource.run(action)
15
- end
16
-
17
- def action_resource
18
- resource
19
- end
20
-
21
- def runner
22
- defined_in_resource.recipe.runner
23
- end
24
-
25
- def delayed?
26
- [:delay, :delayed].include?(timing)
27
- end
28
-
29
- def immediately?
30
- timing == :immediately
31
- end
32
-
33
- def validate!
34
- unless [:delay, :delayed, :immediately].include?(timing)
35
- ItamaeMitsurin.logger.error "'#{timing}' is not valid notification timing. (Valid option is delayed or immediately)"
36
- abort
37
- end
38
- end
39
- end
40
-
41
- class Subscription < Notification
42
- def action_resource
43
- defined_in_resource
44
- end
45
- end
46
- end
@@ -1,171 +0,0 @@
1
- require 'itamae-mitsurin'
2
-
3
- module ItamaeMitsurin
4
- class Recipe
5
- NotFoundError = Class.new(StandardError)
6
-
7
- attr_reader :path
8
- attr_reader :runner
9
- attr_reader :children
10
- attr_reader :delayed_notifications
11
-
12
- class << self
13
- def find_recipe_in_gem(recipe)
14
- plugin_name, recipe_file = recipe.split('::', 2)
15
- recipe_file = recipe_file.gsub("::", "/") if recipe_file
16
-
17
- gem_name = "itamae-plugin-recipe-#{plugin_name}"
18
- begin
19
- gem gem_name
20
- rescue LoadError
21
- end
22
- spec = Gem.loaded_specs.values.find do |spec|
23
- spec.name == gem_name
24
- end
25
-
26
- return nil unless spec
27
-
28
- candidate_files = []
29
- if recipe_file
30
- recipe_file += '.rb' unless recipe_file.end_with?('.rb')
31
- candidate_files << "#{plugin_name}/#{recipe_file}"
32
- else
33
- candidate_files << "#{plugin_name}/default.rb"
34
- candidate_files << "#{plugin_name}.rb"
35
- end
36
-
37
- candidate_files.map do |file|
38
- File.join(spec.lib_dirs_glob, 'itamae', 'plugin', 'recipe', file)
39
- end.find do |path|
40
- File.exist?(path)
41
- end
42
- end
43
- end
44
-
45
- def initialize(runner, path)
46
- @runner = runner
47
- @path = path
48
- @delayed_notifications = []
49
- @children = RecipeChildren.new
50
- end
51
-
52
- def dir
53
- ::File.dirname(@path)
54
- end
55
-
56
- def load(vars = {})
57
- context = EvalContext.new(self, vars)
58
- context.instance_eval(File.read(path), path, 1)
59
- end
60
-
61
- def run
62
- show_banner
63
-
64
- @runner.handler.event(:recipe, path: @path) do
65
- ItamaeMitsurin.logger.with_indent do
66
- @children.run
67
- run_delayed_notifications
68
- end
69
- end
70
- end
71
-
72
- private
73
-
74
- def run_delayed_notifications
75
- @delayed_notifications.uniq! do |notification|
76
- [notification.action, notification.action_resource]
77
- end
78
-
79
- while notification = @delayed_notifications.shift
80
- notification.run
81
- end
82
- end
83
-
84
- def show_banner
85
- ItamaeMitsurin.logger.info "Recipe: #{@path}"
86
- end
87
-
88
- class EvalContext
89
- def initialize(recipe, vars)
90
- @recipe = recipe
91
-
92
- vars.each do |k, v|
93
- define_singleton_method(k) { v }
94
- end
95
- end
96
-
97
- def respond_to_missing?(method, include_private = false)
98
- Resource.get_resource_class(method)
99
- true
100
- rescue NameError
101
- false
102
- end
103
-
104
- def method_missing(*args, &block)
105
- super unless args.size == 2
106
-
107
- method, name = args
108
- begin
109
- klass = Resource.get_resource_class(method)
110
- rescue NameError
111
- super
112
- end
113
-
114
- resource = klass.new(@recipe, name, &block)
115
- @recipe.children << resource
116
- end
117
-
118
- def define(name, params = {}, &block)
119
- Resource.define_resource(name, Definition.create_class(name, params, @recipe, &block))
120
- end
121
-
122
- def include_recipe(target)
123
- expanded_path = ::File.expand_path(target, File.dirname(@recipe.path))
124
- expanded_path = ::File.join(expanded_path, 'default.rb') if ::Dir.exists?(expanded_path)
125
- expanded_path.concat('.rb') unless expanded_path.end_with?('.rb')
126
- candidate_paths = [expanded_path, Recipe.find_recipe_in_gem(target)].compact
127
- path = candidate_paths.find {|path| File.exist?(path) }
128
-
129
- unless path
130
- raise NotFoundError, "Recipe not found. (#{target})"
131
- end
132
-
133
- if runner.children.find_recipe_by_path(path)
134
- ItamaeMitsurin.logger.debug "Recipe, #{path}, is skipped because it is already included"
135
- return
136
- end
137
-
138
- recipe = Recipe.new(runner, path)
139
- @recipe.children << recipe
140
- recipe.load
141
- end
142
-
143
- def node
144
- runner.node
145
- end
146
-
147
- def runner
148
- @recipe.runner
149
- end
150
-
151
- def run_command(*args)
152
- runner.backend.run_command(*args)
153
- end
154
- end
155
-
156
- class RecipeFromDefinition < Recipe
157
- attr_accessor :definition
158
-
159
- def load(vars = {})
160
- context = EvalContext.new(self, vars)
161
- context.instance_eval(&@definition.class.definition_block)
162
- end
163
-
164
- private
165
-
166
- def show_banner
167
- ItamaeMitsurin.logger.debug "#{@definition.resource_type}[#{@definition.resource_name}]"
168
- end
169
- end
170
- end
171
- end