Permalink
Browse files

Move upload filtering logic into its own method

  • Loading branch information...
1 parent 658e2bf commit 589e4db8b3857232c3b1415d09b7d286ffd2e8b4 @sethvargo sethvargo committed Mar 9, 2014
Showing with 26 additions and 15 deletions.
  1. +26 −15 lib/berkshelf/berksfile.rb
View
@@ -535,22 +535,8 @@ def upload(*args)
list = dependencies.select { |dependency| names.include?(dependency.name) }
end
- cookbooks = list.reduce({}) do |hash, dependency|
- if hash[dependency.name].nil?
- # TODO: make this a configurable option for advanced users to save
- # time.
- lockfile.graph.find(dependency).dependencies.each do |direct, _|
- hash[direct] ||= lockfile.retrieve(direct)
- end
-
- hash[dependency.name] = lockfile.retrieve(dependency)
- end
-
- hash
- end.values
-
+ cookbooks = cookbooks_for_upload(list)
ridley_upload(cookbooks, options)
-
cookbooks
end
@@ -698,6 +684,31 @@ def ridley_upload(cookbooks, options = {})
end
end
+ # Filter the given dependencies for upload. The dependencies of a cookbook
+ # will always be included in the filtered results, even if that
+ # dependency's name is not explicitly provided.
+ #
+ # @param [Array<Dependency>] dependencies
+ # the list of dependencies to filter for upload
+ #
+ # @return [Array<CachedCookbook>]
+ # the cookbook objects for uploading
+ def cookbooks_for_upload(dependencies)
+ dependencies.reduce({}) do |hash, dependency|
+ if hash[dependency.name].nil?
+ # TODO: make this a configurable option for advanced users to save
+ # time.
+ lockfile.graph.find(dependency).dependencies.each do |direct, _|
+ hash[direct] ||= lockfile.retrieve(direct)
+ end
+
+ hash[dependency.name] = lockfile.retrieve(dependency)
+ end
+
+ hash
+ end.values
+ end
+
# Ensure the lockfile is present on disk.
#
# @raise [LockfileNotFound]

0 comments on commit 589e4db

Please sign in to comment.