Skip to content
This repository has been archived by the owner on Mar 19, 2022. It is now read-only.

Automatically add Librarian's install directory to cookbook_paths #226

Merged
merged 7 commits into from
Apr 9, 2013
16 changes: 13 additions & 3 deletions lib/chef/knife/solo_cook.rb
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,17 @@ def sync_kitchen
end

def cookbook_paths
Array(Chef::Config[:cookbook_path]) + [KnifeSolo.resource('patch_cookbooks').to_s]
unless @cookbook_paths
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we really need to memoize this? Seems like it might not be worth the code bloat. If you take out memoization and add a helper method this could be expanded_config_paths + [patch_cookbooks_path]. Or with the helper methods you could just add a ||= to memoize that.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I understand and like the use of helper methods, but how could the dynamic adding work unless we store the updated list in an instance variable? Adding is done when running Librarian or Berkshelf, and later we use the list when rsyncing and generating solo.rb. Sorry if I'm not following...

@cookbook_paths = Array(Chef::Config[:cookbook_path]).map do |path|
Pathname.new(path).expand_path
end
@cookbook_paths << KnifeSolo.resource('patch_cookbooks')
end
@cookbook_paths
end

def add_cookbook_path(path)
cookbook_paths.unshift(path) unless cookbook_paths.include?(path)
end

def nodes_path
Expand Down Expand Up @@ -166,6 +176,7 @@ def librarian_install
ui.msg "Installing Librarian cookbooks..."
Librarian::Action::Resolve.new(librarian_env).run
Librarian::Action::Install.new(librarian_env).run
add_cookbook_path librarian_env.install_path
end
end

Expand Down Expand Up @@ -205,8 +216,7 @@ def upload_to_provision_path(src, dest, key_name = 'path')
elsif !File.exist?(src)
ui.warn "Local #{key_name} '#{src}' does not exist"
else
src << '/' if File.directory? src
upload(src, File.join(provisioning_path, dest))
upload("#{src}#{'/' if File.directory?(src)}", File.join(provisioning_path, dest))
end
end

Expand Down