Module: Poise::Utils
- Extended by:
- Utils
- Included in:
- Utils
- Defined in:
- lib/poise/utils.rb,
lib/poise/utils/resource_provider_mixin.rb
Defined Under Namespace
Modules: ResourceProviderMixin
Class Method Summary collapse
-
.find_cookbook_name(run_context, filename) ⇒ String
Find the cookbook name for a given filename.
Instance Method Summary collapse
-
#find_cookbook_name(run_context, filename) ⇒ String
Find the cookbook name for a given filename.
Class Method Details
.find_cookbook_name(run_context, filename) ⇒ String
Find the cookbook name for a given filename. The can used to find the cookbook that corresponds to a caller of a file.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/poise/utils.rb', line 38 def find_cookbook_name(run_context, filename) possibles = {} Chef::Log.debug("[Poise] Checking cookbook for #{filename.inspect}") run_context.cookbook_collection.each do |name, ver| # This special method is added by Halite::Gem#as_cookbook_version. if ver.respond_to?(:halite_root) # The join is there because ../poise-ruby/lib starts with ../poise so # we want a trailing /. Chef::Log.debug("") if filename.start_with?(File.join(ver.halite_root, '')) Chef::Log.debug("[Poise] Found matching halite_root in #{name}: #{ver.halite_root.inspect}") possibles[ver.halite_root] = name end else Chef::CookbookVersion::COOKBOOK_SEGMENTS.each do |seg| ver.segment_filenames(seg).each do |file| # Put this behind an environment variable because it is verbose # even for normal debugging-level output. Chef::Log.debug("[Poise] Checking #{seg} in #{name}: #{file.inspect}") if ENV['POISE_DEBUG'] if file == filename Chef::Log.debug("[Poise] Found matching #{seg} in #{name}: #{file.inspect}") possibles[file] = name end end end end end raise Poise::Error.new("Unable to find cookbook for file #{filename.inspect}") if possibles.empty? # Sort the items by matching path length, pick the name attached to the longest. possibles.sort_by{|key, value| key.length }.last[1] end |
Instance Method Details
#find_cookbook_name(run_context, filename) ⇒ String
Find the cookbook name for a given filename. The can used to find the cookbook that corresponds to a caller of a file.
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/poise/utils.rb', line 38 def find_cookbook_name(run_context, filename) possibles = {} Chef::Log.debug("[Poise] Checking cookbook for #{filename.inspect}") run_context.cookbook_collection.each do |name, ver| # This special method is added by Halite::Gem#as_cookbook_version. if ver.respond_to?(:halite_root) # The join is there because ../poise-ruby/lib starts with ../poise so # we want a trailing /. Chef::Log.debug("") if filename.start_with?(File.join(ver.halite_root, '')) Chef::Log.debug("[Poise] Found matching halite_root in #{name}: #{ver.halite_root.inspect}") possibles[ver.halite_root] = name end else Chef::CookbookVersion::COOKBOOK_SEGMENTS.each do |seg| ver.segment_filenames(seg).each do |file| # Put this behind an environment variable because it is verbose # even for normal debugging-level output. Chef::Log.debug("[Poise] Checking #{seg} in #{name}: #{file.inspect}") if ENV['POISE_DEBUG'] if file == filename Chef::Log.debug("[Poise] Found matching #{seg} in #{name}: #{file.inspect}") possibles[file] = name end end end end end raise Poise::Error.new("Unable to find cookbook for file #{filename.inspect}") if possibles.empty? # Sort the items by matching path length, pick the name attached to the longest. possibles.sort_by{|key, value| key.length }.last[1] end |