Skip to content

Commit

Permalink
Use instance variable options
Browse files Browse the repository at this point in the history
In `Itame::Recipe` and `Itamae::Resource::Base`
  • Loading branch information
ganmacs committed Jul 13, 2015
1 parent cf7f563 commit 5d30ac9
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 14 deletions.
8 changes: 4 additions & 4 deletions lib/itamae/recipe.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
2 changes: 1 addition & 1 deletion lib/itamae/recipe_children.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 8 additions & 8 deletions lib/itamae/resource/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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?
Expand Down Expand Up @@ -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}'"

Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion spec/unit/lib/itamae/resource/base_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 5d30ac9

Please sign in to comment.