diff --git a/lib/itamae/recipe.rb b/lib/itamae/recipe.rb index 04658af0..390b71c2 100644 --- a/lib/itamae/recipe.rb +++ b/lib/itamae/recipe.rb @@ -46,20 +46,20 @@ def run(options = {}) show_banner Logger.formatter.with_indent do - @children.run(options) - run_delayed_notifications(options) + @children.run(@options) + run_delayed_notifications end end private - def run_delayed_notifications(options) + def run_delayed_notifications @delayed_notifications.uniq! do |notification| [notification.action, notification.action_resource] end while notification = @delayed_notifications.shift - notification.run(options) + notification.run(@options) end end diff --git a/lib/itamae/recipe_children.rb b/lib/itamae/recipe_children.rb index 947ab691..a39c46be 100644 --- a/lib/itamae/recipe_children.rb +++ b/lib/itamae/recipe_children.rb @@ -57,7 +57,7 @@ def run(options) self.each do |resource| case resource when Resource::Base - resource.run(nil, dry_run: options[:dry_run]) + resource.run when Recipe resource.run(options) end diff --git a/lib/itamae/resource/base.rb b/lib/itamae/resource/base.rb index 54ab2c22..b08125f6 100644 --- a/lib/itamae/resource/base.rb +++ b/lib/itamae/resource/base.rb @@ -133,11 +133,11 @@ def run(specific_action = nil, options = {}) end [specific_action || attributes.action].flatten.each do |action| - run_action(action, options) + run_action(action) end - verify unless options[:dry_run] - notify(options) if updated? + verify unless @options[:dry_run] + notify if updated? end @updated = false @@ -166,7 +166,7 @@ def resource_type alias_method :current, :current_attributes - def run_action(action, options) + def run_action(action, options = {}) @current_action = action clear_current_attributes @@ -186,12 +186,12 @@ def run_action(action, options) show_differences method_name = "action_#{action}" - if options[:dry_run] + if @options[:dry_run] unless respond_to?(method_name) Logger.error "action #{action.inspect} is unavailable" end else - public_send(method_name, options) + public_send(method_name, @options) end updated! if different? @@ -324,7 +324,7 @@ def updated? @updated end - def notify(options) + def notify(options = {}) (notifications + recipe.children.subscribing(self)).each do |notification| message = "Notifying #{notification.action} to #{notification.action_resource.resource_type} resource '#{notification.action_resource.resource_name}'" @@ -343,7 +343,7 @@ def notify(options) if notification.delayed? @recipe.delayed_notifications << notification elsif notification.immediately? - notification.run(options) + notification.run(@options) end end end diff --git a/spec/unit/lib/itamae/resource/base_spec.rb b/spec/unit/lib/itamae/resource/base_spec.rb index 64f18dfd..fc49084f 100644 --- a/spec/unit/lib/itamae/resource/base_spec.rb +++ b/spec/unit/lib/itamae/resource/base_spec.rb @@ -122,10 +122,12 @@ class TestResource < Itamae::Resource::Base end context 'with dry_run' do + subject(:dry_run_resource) { described_class.new(recipe, "name", dry_run: true) } + context 'when specified action is unavailable' do it 'logs error' do expect(Itamae::Logger).to receive(:error).with(/action :name is unavailable/) - subject.run(nil, dry_run: true) + subject.run end end end