Skip to content

Commit

Permalink
Add options to pre_action to avoid raise error in file edit action wh…
Browse files Browse the repository at this point in the history
…en dry-run
  • Loading branch information
ganmacs committed Jul 12, 2015
1 parent 1b9aa72 commit fae8160
Show file tree
Hide file tree
Showing 12 changed files with 21 additions and 26 deletions.
5 changes: 2 additions & 3 deletions lib/itamae/resource/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -176,7 +176,7 @@ def run_action(action, options)

Logger.formatter.with_indent_if(Logger.debug?) do
Logger.debug "(in pre_action)"
pre_action
pre_action(options)

Logger.debug "(in set_current_attributes)"
set_current_attributes
Expand All @@ -203,7 +203,7 @@ def clear_current_attributes
@current_attributes = Hashie::Mash.new
end

def pre_action
def pre_action(options = {})
# do nothing
end

Expand Down Expand Up @@ -360,4 +360,3 @@ def verify
end
end
end

3 changes: 1 addition & 2 deletions lib/itamae/resource/directory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Directory < Base
define_attribute :owner, type: String
define_attribute :group, type: String

def pre_action
def pre_action(options = {})
case @current_action
when :create
attributes.exist = true
Expand Down Expand Up @@ -60,4 +60,3 @@ def action_delete(options)
end
end
end

3 changes: 1 addition & 2 deletions lib/itamae/resource/execute.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class Execute < Base
define_attribute :command, type: String, default_name: true
define_attribute :cwd, type: String

def pre_action
def pre_action(options = {})
case @current_action
when :run
attributes.executed = true
Expand All @@ -25,4 +25,3 @@ def action_run(options)
end
end
end

15 changes: 9 additions & 6 deletions lib/itamae/resource/file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class File < Base
define_attribute :group, type: String
define_attribute :block, type: Proc, default: proc {}

def pre_action
def pre_action(options = {})
case @current_action
when :create
attributes.exist = true
Expand All @@ -20,12 +20,16 @@ def pre_action
when :edit
attributes.exist = true

content = backend.receive_file(attributes.path)
attributes.block.call(content)
attributes.content = content
unless options[:dry_run]
content = backend.receive_file(attributes.path)
attributes.block.call(content)
attributes.content = content
end
end

send_tempfile
unless options[:dry_run]
send_tempfile
end
end

def set_current_attributes
Expand Down Expand Up @@ -145,4 +149,3 @@ def send_tempfile
end
end
end

3 changes: 1 addition & 2 deletions lib/itamae/resource/gem_package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class GemPackage < Base
define_attribute :version, type: String
define_attribute :source, type: String

def pre_action
def pre_action(options = {})
case @current_action
when :install
attributes.installed = true
Expand Down Expand Up @@ -78,4 +78,3 @@ def install!
end
end
end

3 changes: 1 addition & 2 deletions lib/itamae/resource/git.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Git < Base
define_attribute :revision, type: String
define_attribute :recursive, default: false

def pre_action
def pre_action(options = {})
case @current_action
when :sync
attributes.exist = true
Expand Down Expand Up @@ -81,4 +81,3 @@ def get_revision(branch)
end
end
end

2 changes: 1 addition & 1 deletion lib/itamae/resource/link.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Link < Base
define_attribute :to, type: String, required: true
define_attribute :force, default: false

def pre_action
def pre_action(options = {})
case @current_action
when :create
attributes.exist = true
Expand Down
3 changes: 1 addition & 2 deletions lib/itamae/resource/package.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Package < Base
define_attribute :version, type: String
define_attribute :options, type: String

def pre_action
def pre_action(options = {})
case @current_action
when :install
attributes.installed = true
Expand Down Expand Up @@ -41,4 +41,3 @@ def action_remove(action_options)
end
end
end

2 changes: 1 addition & 1 deletion lib/itamae/resource/remote_directory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class RemoteDirectory < Base
define_attribute :owner, type: String
define_attribute :group, type: String

def pre_action
def pre_action(options = {})
directory = ::File.expand_path(attributes.source, ::File.dirname(@recipe.path))
src = ::File.expand_path(directory, ::File.dirname(@recipe.path))

Expand Down
3 changes: 1 addition & 2 deletions lib/itamae/resource/service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def initialize(*args)
@under = attributes.provider ? "_under_#{attributes.provider}" : ""
end

def pre_action
def pre_action(options = {})
case @current_action
when :start, :restart
attributes.running = true
Expand Down Expand Up @@ -66,4 +66,3 @@ def action_disable(options)
end
end
end

3 changes: 1 addition & 2 deletions lib/itamae/resource/template.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ module Resource
class Template < RemoteFile
define_attribute :variables, type: Hash, default: {}

def pre_action
def pre_action(options = {})
attributes.content = RenderContext.new(self).render_file(source_file)

super
Expand Down Expand Up @@ -50,4 +50,3 @@ def node
end
end
end

2 changes: 1 addition & 1 deletion lib/itamae/resource/user.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class User < Base
define_attribute :shell, type: String
define_attribute :create_home, type: [TrueClass, FalseClass], default: false

def pre_action
def pre_action(options = {})
case @current_action
when :create
attributes.exist = true
Expand Down

0 comments on commit fae8160

Please sign in to comment.