Class: ChefCookbookCopy
- Inherits:
-
Chef::Handler
- Object
- Chef::Handler
- ChefCookbookCopy
- Defined in:
- lib/chef-handler-cookbook-copy.rb
Instance Attribute Summary collapse
-
#always_copy ⇒ Object
readonly
Returns the value of attribute always_copy.
-
#mode ⇒ Object
readonly
Returns the value of attribute mode.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Instance Method Summary collapse
- #copy_cookbooks ⇒ Object
- #defaults ⇒ Object
-
#initialize(options = defaults) ⇒ ChefCookbookCopy
constructor
A new instance of ChefCookbookCopy.
- #report ⇒ Object
Constructor Details
#initialize(options = defaults) ⇒ ChefCookbookCopy
Returns a new instance of ChefCookbookCopy.
29 30 31 32 33 |
# File 'lib/chef-handler-cookbook-copy.rb', line 29 def initialize( = defaults) @path = [:path] @mode = [:mode] @always_copy = [:always_copy] end |
Instance Attribute Details
#always_copy ⇒ Object (readonly)
Returns the value of attribute always_copy.
27 28 29 |
# File 'lib/chef-handler-cookbook-copy.rb', line 27 def always_copy @always_copy end |
#mode ⇒ Object (readonly)
Returns the value of attribute mode.
27 28 29 |
# File 'lib/chef-handler-cookbook-copy.rb', line 27 def mode @mode end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
27 28 29 |
# File 'lib/chef-handler-cookbook-copy.rb', line 27 def path @path end |
Instance Method Details
#copy_cookbooks ⇒ Object
43 44 45 46 47 48 49 50 |
# File 'lib/chef-handler-cookbook-copy.rb', line 43 def copy_cookbooks cookbook_paths = Array(Chef::Config[:cookbook_path]) cookbook_paths.each_with_index do |origin, index| dst = ::File.join(@path, "cookbooks-#{index}") FileUtils.mkdir_p(dst, :mode => @mode) if !Dir.exists?(dst) FileUtils.cp_r(origin, dst) end end |
#defaults ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/chef-handler-cookbook-copy.rb', line 35 def defaults return { :path => '/var/cache/chef/cookbooks', :mode => 0755, :always_copy => true } end |
#report ⇒ Object
52 53 54 55 56 57 |
# File 'lib/chef-handler-cookbook-copy.rb', line 52 def report if run_status.success? || @always_copy Chef::Log.info "Copying cookbooks to #{@path}" copy_cookbooks end end |