Skip to content

Commit

Permalink
More defensive checks to see if lock file exists
Browse files Browse the repository at this point in the history
  • Loading branch information
nesquena committed Aug 21, 2011
1 parent f72256e commit 22f23c1
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 2 deletions.
2 changes: 1 addition & 1 deletion lib/vendor/cli.rb
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def update(lib_name=nil)
def list
manager = Vendor::Manager.new(Dir.pwd)
say "Dependencies:\n"
manager.locked_libraries.each do |lib|
manager.libraries.each do |lib|
say " #{lib}", :yellow
end
end
Expand Down
6 changes: 6 additions & 0 deletions lib/vendor/lock_file.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ def initialize(lock_path, depfile, options={})
@depfile = depfile
end

# Returns if the file exists
# @lockfile.exists? => true
def exists?
File.exist?(@path)
end

# Returns libraries specified in Vendor.lock
# @lockfile.libraries => [<Library>, <Library>]
def libraries
Expand Down
9 changes: 8 additions & 1 deletion lib/vendor/manager.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ def update!(library_name=nil)
end
end

# Returns the most accurate library list possible
# @manager.libraries => [<Library>, ...]
def libraries
self.locked_libraries || self.required_libraries
end

# Returns the libraries required by Vendors file
# @manager.required_libraries => [<Library>, ...]
def required_libraries
Expand All @@ -46,12 +52,13 @@ def required_libraries
# Returns libraries that are locked as dependencies in Vendors.lock
# @manager.locked_libraries => [<Library>, ...]
def locked_libraries
@lockfile.libraries
@lockfile.libraries if @lockfile.exists?
end

# Returns libraries that are missing from local installation
# @manager.locked_libraries => [<Library>, ...]
def missing_libraries
return self.required_libraries unless @lockfile.exists?
self.locked_libraries.select do |lib|
local_path = File.join(@vendored_path, lib.name)
installed = @depfile.libraries.find { |l| l.name == lib.name }
Expand Down

0 comments on commit 22f23c1

Please sign in to comment.