file_transfer_mixin 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
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
- sftp:
12
- some_key:
13
- server: sftp.matrix.com
14
- username: neo
15
- password: the_one
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
 
@@ -22,5 +22,4 @@ Gem::Specification.new do |s|
22
22
  s.add_dependency 'enviro', '~> 0.0.4'
23
23
  s.add_development_dependency "bundler", ">= 1.0.0.rc.6"
24
24
  s.add_development_dependency "rspec", "~> 2.4.0"
25
- s.add_development_dependency "ruby-debug19"
26
25
  end
@@ -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
- Net::SFTP.start(configuration[key][:server], configuration[key][:username], :password => configuration[key][:password]) do |sftp|
21
- yield(sftp)
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
@@ -1,3 +1,3 @@
1
1
  module FileTransferMixin
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  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
- it "should respond to sftp_send" do
49
- lambda{ TestFileTransferMixin.new.sftp_send(:some_key, 'path', 'file_path') }.should_not raise_error
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 respond to sftp_fetch" do
53
- lambda{ TestFileTransferMixin.new.sftp_fetch(:some_key, 'path', 'file_path') }.should_not raise_error
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
- - 1
9
- version: 0.0.1
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-04 00:00:00 -06:00
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