borrower 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,21 +7,32 @@ module Borrower
7
7
  end
8
8
 
9
9
  def find file
10
- path = @_manifest.files.fetch(file) { false }
11
- return path if path
10
+ return file if Path.remote?(file) || Path.exists?(file)
12
11
 
13
- matches = []
14
- @_manifest.directories.each do |dir|
15
- Dir[File.join( dir, '*' )].each do |possibility|
16
- matches << possibility if possibility.match( file )
17
- end
18
- end
12
+ path = check_for_file_in_manifest_files(file) || false
13
+ return path if path
19
14
 
20
- path = matches.sort { |a,b| a.length <=> b.length }.first
15
+ path = check_for_file_in_manifest_directories(file) || false
21
16
  return path if path
22
17
 
23
18
  raise "Could not file #{file}"
24
19
  end
20
+
21
+ private
22
+
23
+ def check_for_file_in_manifest_files file
24
+ @_manifest.files.fetch(file) { false }
25
+ end
26
+
27
+ def check_for_file_in_manifest_directories file
28
+ matches = []
29
+ @_manifest.directories.each do |dir|
30
+ Dir[File.join( dir, '*' )].each do |possibility|
31
+ matches << possibility if possibility.match( file )
32
+ end
33
+ end
34
+ path = matches.sort { |a,b| a.length <=> b.length }.first
35
+ end
25
36
  end
26
37
 
27
38
  class Manifest
@@ -28,7 +28,7 @@ module Borrower
28
28
  end
29
29
 
30
30
  def contents_from_file path
31
- ::Borrower::Path.contents(::Borrower.find(path))
31
+ ::Borrower::Path.contents(path)
32
32
  end
33
33
 
34
34
  end
@@ -6,15 +6,15 @@ module Borrower
6
6
  # @param path [String]
7
7
  # @return [String] the contents
8
8
  def contents path
9
- if exists? path
10
- if remote? path
11
- fetch_from_remote(path).body
12
- else
13
- return IO.read(path)
14
- end
9
+ path = Borrower.find(path)
10
+
11
+ if remote?(path) && exists?(path)
12
+ return fetch_from_remote(path).body
15
13
  else
16
- raise "nothing exists at the provided path '#{path}'"
14
+ return IO.read(path)
17
15
  end
16
+
17
+ raise "nothing exists at the provided path '#{path}'"
18
18
  end
19
19
 
20
20
  # check if the file exists for borrowing
@@ -1,3 +1,3 @@
1
1
  module Borrower
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -6,6 +6,7 @@ describe Borrower::Manifest do
6
6
  given_files [ "baz.txt", "files/baz.txt", "files/woo.txt", "files/foo.txt" ]
7
7
  Borrower.manifest do |m|
8
8
  m.file "me", File.join( TMP, "test.txt" )
9
+ m.file "remote", "https://gist.github.com/stevenosloan/5578606/raw/97ab1305184bdeac33472f9f1fcc1c9e278a1bb3/dummy.txt"
9
10
  m.dir File.join( TMP )
10
11
  m.dir File.join( TMP, 'files' )
11
12
  end
@@ -19,6 +20,14 @@ describe Borrower::Manifest do
19
20
  Borrower.find("me").should == File.join( TMP, "test.txt" )
20
21
  end
21
22
 
23
+ it "returns remote paths if given fully resolved" do
24
+ Borrower.find("http://google.com").should == "http://google.com"
25
+ end
26
+
27
+ it "finds named remote files" do
28
+ Borrower.find("remote").should == "https://gist.github.com/stevenosloan/5578606/raw/97ab1305184bdeac33472f9f1fcc1c9e278a1bb3/dummy.txt"
29
+ end
30
+
22
31
  it "creates list of files from directories" do
23
32
  Borrower.find("baz.txt").should == File.join( TMP, "baz.txt" )
24
33
  Borrower.find("files/baz.txt").should == File.join( TMP, "files/baz.txt" )
@@ -26,6 +26,18 @@ describe Borrower do
26
26
  Borrower::Transport.take( file_destination ).should == "Hello I'm a file"
27
27
  end
28
28
 
29
+ it "borrows named local and remote files" do
30
+ Borrower.manifest do |m|
31
+ m.file "local", local_file
32
+ m.file "remote", remote_file
33
+ end
34
+ borrow "local", to: file_destination
35
+ borrow "remote", to: File.join( TMP, "remote.txt" )
36
+
37
+ Borrower::Transport.take( file_destination ).should == "Hi I'm a file"
38
+ Borrower::Transport.take( File.join( TMP, "remote.txt" ) ).should == "Hello I'm a file"
39
+ end
40
+
29
41
  it "merges files if merge is set to true" do
30
42
  borrow merge_file, to: file_destination, merge: true
31
43
  Borrower::Transport.take( file_destination ).should == "Hi I'm a file"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: borrower
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: