Class: Chef::Provider::CookbookFile
- Inherits:
-
File
- Object
- Chef::Provider
- File
- Chef::Provider::CookbookFile
- Defined in:
- lib/chef/provider/cookbook_file.rb
Constant Summary
Constants included from Mixin::ShellOut
Mixin::ShellOut::DEPRECATED_OPTIONS
Instance Attribute Summary
Attributes inherited from Chef::Provider
#action, #current_resource, #new_resource, #run_context
Instance Method Summary collapse
- #action_create ⇒ Object
- #backup_new_resource ⇒ Object
- #content_stale? ⇒ Boolean
- #file_cache_location ⇒ Object
- #load_current_resource ⇒ Object
-
#resource_cookbook ⇒ Object
Determine the cookbook to get the file from.
- #whyrun_supported? ⇒ Boolean
Methods inherited from File
#action_create_if_missing, #action_delete, #action_touch, #backup, #compare_content, #define_resource_requirements, #deploy_tempfile, #diff_current, #diff_current_from_content, #is_binary?, #load_current_resource_attrs, #set_all_access_controls, #set_content, #setup_acl, #update_new_file_state
Methods included from Mixin::ShellOut
#run_command_compatible_options, #shell_out, #shell_out!
Methods included from Mixin::Checksum
Methods inherited from Chef::Provider
#action_nothing, build_from_file, #cleanup_after_converge, #converge, #cookbook_name, #define_resource_requirements, #events, #initialize, #node, #process_resource_requirements, #requirements, #resource_collection, #run_action, #whyrun_mode?
Methods included from Mixin::ConvertToClassName
#convert_to_class_name, #convert_to_snake_case, #filename_to_qualified_string, #snake_case_basename
Methods included from Mixin::EnforceOwnershipAndPermissions
#access_controls, #enforce_ownership_and_permissions
Methods included from Mixin::RecipeDefinitionDSLCore
Methods included from Mixin::Language
#data_bag, #data_bag_item, #platform?, #platform_family?, #search, #value_for_platform, #value_for_platform_family
Constructor Details
This class inherits a constructor from Chef::Provider
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Chef::Mixin::RecipeDefinitionDSLCore
Instance Method Details
#action_create ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/chef/provider/cookbook_file.rb', line 35 def action_create if file_cache_location && content_stale? description = [] description << "create a new cookbook_file #{@new_resource.path}" description << diff_current(file_cache_location) converge_by(description) do Chef::Log.debug("#{@new_resource} has new contents") backup_new_resource deploy_tempfile do |tempfile| Chef::Log.debug("#{@new_resource} staging #{file_cache_location} to #{tempfile.path}") tempfile.close FileUtils.cp(file_cache_location, tempfile.path) end Chef::Log.info("#{@new_resource} created file #{@new_resource.path}") end else set_all_access_controls end end |
#backup_new_resource ⇒ Object
69 70 71 72 73 |
# File 'lib/chef/provider/cookbook_file.rb', line 69 def backup_new_resource if ::File.exists?(@new_resource.path) backup @new_resource.path end end |
#content_stale? ⇒ Boolean
75 76 77 |
# File 'lib/chef/provider/cookbook_file.rb', line 75 def content_stale? ( ! ::File.exist?(@new_resource.path)) || ( ! compare_content) end |
#file_cache_location ⇒ Object
55 56 57 58 59 60 |
# File 'lib/chef/provider/cookbook_file.rb', line 55 def file_cache_location @file_cache_location ||= begin cookbook = run_context.cookbook_collection[resource_cookbook] cookbook.preferred_filename_on_disk_location(node, :files, @new_resource.source, @new_resource.path) end end |
#load_current_resource ⇒ Object
30 31 32 33 |
# File 'lib/chef/provider/cookbook_file.rb', line 30 def load_current_resource @current_resource = Chef::Resource::CookbookFile.new(@new_resource.name) super end |
#resource_cookbook ⇒ Object
Determine the cookbook to get the file from. If new resource sets an explicit cookbook, use it, otherwise fall back to the implicit cookbook i.e., the cookbook the resource was declared in.
65 66 67 |
# File 'lib/chef/provider/cookbook_file.rb', line 65 def resource_cookbook @new_resource.cookbook || @new_resource.cookbook_name end |
#whyrun_supported? ⇒ Boolean
26 27 28 |
# File 'lib/chef/provider/cookbook_file.rb', line 26 def whyrun_supported? true end |