file_transfer_mixin 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
data/README
CHANGED
@@ -8,11 +8,15 @@ for now is focused on SFTP servers.
|
|
8
8
|
- It expects an ENV variable named FILE_TRANSFER_MIXIN_CONFIG_PATH to be set.
|
9
9
|
- It expects a yml configuration file in FILE_TRANSFER_MIXIN_CONFIG_PATH that looks like the following:
|
10
10
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
11
|
+
:development:
|
12
|
+
:sftp:
|
13
|
+
:some_key:
|
14
|
+
:server: 127.0.0.1
|
15
|
+
:username: user
|
16
|
+
:password: pass
|
17
|
+
:test: {}
|
18
|
+
|
19
|
+
:production: {}
|
16
20
|
|
17
21
|
Then in a class, you would deal with it thusly:
|
18
22
|
|
data/file_transfer_mixin.gemspec
CHANGED
@@ -2,7 +2,7 @@ module FileTransferMixin
|
|
2
2
|
module InstanceMethods
|
3
3
|
extend Forwardable
|
4
4
|
|
5
|
-
def_delegators :file_transfer_mixin_sftp_instance, :sftp_send, :sftp_fetch
|
5
|
+
def_delegators :file_transfer_mixin_sftp_instance, :sftp_send, :sftp_fetch, :sftp_block
|
6
6
|
|
7
7
|
private
|
8
8
|
def file_transfer_mixin_sftp_instance
|
@@ -17,8 +17,10 @@ module FileTransferMixin
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def sftp_block(key, &block)
|
20
|
-
|
21
|
-
|
20
|
+
if perform_network_operations?
|
21
|
+
Net::SFTP.start(configuration[key][:server], configuration[key][:username], :password => configuration[key][:password]) do |sftp|
|
22
|
+
yield(sftp)
|
23
|
+
end
|
22
24
|
end
|
23
25
|
end
|
24
26
|
|
@@ -33,6 +35,10 @@ module FileTransferMixin
|
|
33
35
|
sftp.download!(remote_path, local_path)
|
34
36
|
end
|
35
37
|
end
|
38
|
+
|
39
|
+
def perform_network_operations?
|
40
|
+
FileTransferMixin.env != 'test'
|
41
|
+
end
|
36
42
|
end
|
37
43
|
end
|
38
44
|
end
|
@@ -28,11 +28,6 @@ describe ::FileTransferMixin::Interfaces::SFTP do
|
|
28
28
|
class TestFileTransferMixin
|
29
29
|
include FileTransferMixin
|
30
30
|
end
|
31
|
-
|
32
|
-
sftp_mock = mock('sftp')
|
33
|
-
sftp_mock.stub!(:upload!).and_return(true)
|
34
|
-
sftp_mock.stub!(:download!).and_return(true)
|
35
|
-
Net::SFTP.stub(:start).and_return(sftp_mock)
|
36
31
|
end
|
37
32
|
|
38
33
|
it "should know its parent configuration key" do
|
@@ -45,11 +40,27 @@ describe ::FileTransferMixin::Interfaces::SFTP do
|
|
45
40
|
subject.configuration[:some_key][:password].should == 'pass'
|
46
41
|
end
|
47
42
|
|
48
|
-
|
49
|
-
|
43
|
+
describe "network operations" do
|
44
|
+
before(:each) do
|
45
|
+
sftp_mock = mock('sftp')
|
46
|
+
sftp_mock.stub!(:upload!).and_return(true)
|
47
|
+
sftp_mock.stub!(:download!).and_return(true)
|
48
|
+
Net::SFTP.stub(:start).and_return(sftp_mock)
|
49
|
+
@sftp_interface = TestFileTransferMixin.new
|
50
|
+
@sftp_interface.stub!(:perform_network_operations?).and_return(true)
|
51
|
+
end
|
52
|
+
|
53
|
+
it "should respond to sftp_send" do
|
54
|
+
lambda{ @sftp_interface.sftp_send(:some_key, 'path', 'file_path') }.should_not raise_error
|
55
|
+
end
|
56
|
+
|
57
|
+
it "should respond to sftp_fetch" do
|
58
|
+
lambda{ @sftp_interface.sftp_fetch(:some_key, 'path', 'file_path') }.should_not raise_error
|
59
|
+
end
|
50
60
|
end
|
51
61
|
|
52
|
-
it "should
|
53
|
-
|
62
|
+
it "should not perform network operations in the test environment" do
|
63
|
+
FileTransferMixin.stub!(:env).and_return('test')
|
64
|
+
TestFileTransferMixin::Interfaces::SFTP.new.perform_network_operations?.should == false
|
54
65
|
end
|
55
66
|
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 0
|
8
|
-
-
|
9
|
-
version: 0.0.
|
8
|
+
- 2
|
9
|
+
version: 0.0.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Josh Adams
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-03-
|
17
|
+
date: 2011-03-07 00:00:00 -06:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -79,19 +79,6 @@ dependencies:
|
|
79
79
|
version: 2.4.0
|
80
80
|
type: :development
|
81
81
|
version_requirements: *id004
|
82
|
-
- !ruby/object:Gem::Dependency
|
83
|
-
name: ruby-debug19
|
84
|
-
prerelease: false
|
85
|
-
requirement: &id005 !ruby/object:Gem::Requirement
|
86
|
-
none: false
|
87
|
-
requirements:
|
88
|
-
- - ">="
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
segments:
|
91
|
-
- 0
|
92
|
-
version: "0"
|
93
|
-
type: :development
|
94
|
-
version_requirements: *id005
|
95
82
|
description:
|
96
83
|
email:
|
97
84
|
- josh@isotope11.com
|