ftpmvc 0.2.2 → 0.3.0

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: db6918bfb3978caecece0f47529a1e836dac2dfb
4
- data.tar.gz: 79a3e106de3a7e3a80d0845804b3e84b59af5f9e
3
+ metadata.gz: bf2e9baaad49d9a071156187fb937b34bad1034a
4
+ data.tar.gz: 8af18d576a62518dc608c109b0a1714857d7c864
5
5
  SHA512:
6
- metadata.gz: c601daf5f12119af5952dae5a1d2ad1b6f9468feea6c9895c405899263fb7bbbd8b6ff8babcd8d46a2b62f22c3aaa5c24922e9ffc5a1733c8cacf4b519493574
7
- data.tar.gz: 15c01d4753f94966c89878047aa6894ec82f912fa231d8f174a9f0a45d25c2241fc4ed5ab2351db1c9d606299796ca5aa09ad889fe79d7f05446cea95cef077d
6
+ metadata.gz: 48e3c95a03c80d3765ca612b176a68e28eadebd76d3b6c55164947324edc253bcc2657699e614a96525e3164c2357380d9b2cb9309c867a3a4980e14ae88487f
7
+ data.tar.gz: 5c232bcd9e543591d318431a41abf286763717a2879267ca6152a867e229787468139b2d47b5c84a15c8aec9b9a2429130d55ed601d6b5ab0749b746cdaf281a
data/ftpmvc.gemspec CHANGED
@@ -23,6 +23,6 @@ Gem::Specification.new do |spec|
23
23
  spec.add_development_dependency "guard-rspec"
24
24
  spec.add_development_dependency "terminal-notifier-guard"
25
25
  spec.add_development_dependency "codeclimate-test-reporter"
26
- spec.add_dependency "em-ftpd"
26
+ spec.add_dependency "ftpd"
27
27
  spec.add_dependency "activesupport"
28
28
  end
@@ -12,12 +12,12 @@ module FTPMVC
12
12
  @fs.resolve(path).index
13
13
  end
14
14
 
15
- def size(path)
16
- @fs.resolve(::File.dirname(path)).size(::File.basename(path))
15
+ def directory?(path)
16
+ @fs.resolve(path).kind_of?(Directory)
17
17
  end
18
18
 
19
- def directory?(path)
20
- @fs.directory?(path)
19
+ def exists?(path)
20
+ not @fs.resolve(path).nil?
21
21
  end
22
22
  end
23
23
  end
@@ -8,7 +8,7 @@ module FTPMVC
8
8
  class Application
9
9
  extend Forwardable
10
10
 
11
- def_delegators :@filter_chain, :index, :size, :get, :directory?
11
+ def_delegators :@filter_chain, :index, :get, :directory?, :exists?
12
12
  def_delegators :auth, :authenticate
13
13
 
14
14
  def initialize(&block)
@@ -11,16 +11,6 @@ module FTPMVC
11
11
  instance_eval(&block) if block_given?
12
12
  end
13
13
 
14
- def size(path)
15
- io = get(path)
16
- return nil if io.nil?
17
- total_size = 0
18
- while buffer = io.read(1024)
19
- total_size += buffer.size
20
- end
21
- total_size
22
- end
23
-
24
14
  def get(path)
25
15
  file = resolve(path)
26
16
  file ? file.data : nil
@@ -42,10 +32,6 @@ module FTPMVC
42
32
  directory_class(name).new(name, &block)
43
33
  end
44
34
 
45
- def directory?(path)
46
- resolve(path).kind_of?(Directory)
47
- end
48
-
49
35
  protected
50
36
 
51
37
  def directory(name, &block)
data/lib/ftpmvc/filter.rb CHANGED
@@ -4,7 +4,7 @@ module FTPMVC
4
4
  class Filter
5
5
  extend Forwardable
6
6
 
7
- def_delegators :@chain, :index, :size, :get, :directory?
7
+ def_delegators :@chain, :index, :get, :directory?, :exists?
8
8
 
9
9
  def initialize(fs, chain, options={})
10
10
  @fs, @chain, @options = fs, chain, options
@@ -0,0 +1,2 @@
1
+ require 'ftpmvc/ftpd/driver'
2
+ require 'ftpmvc/ftpd/file_system'
@@ -0,0 +1,20 @@
1
+ require 'ftpmvc/ftpd/file_system'
2
+
3
+ module FTPMVC
4
+ module Ftpd
5
+ class Driver
6
+ def initialize(application)
7
+ @application = application
8
+ end
9
+
10
+ def authenticate(username, password)
11
+ @application.authenticate(username, password)
12
+ end
13
+
14
+ def file_system(username)
15
+ FileSystem.new(@application)
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,41 @@
1
+ module FTPMVC
2
+ module Ftpd
3
+ class FileSystem
4
+ def initialize(application)
5
+ @application = application
6
+ end
7
+
8
+ def dir(path)
9
+ @application.index(path[/^[^*]*/]).map { |node| ::File.join(path, node.name) }
10
+ end
11
+
12
+ def directory?(path)
13
+ @application.directory?(path)
14
+ end
15
+
16
+ def read(path)
17
+ yield @application.get(path)
18
+ end
19
+
20
+ def accessible?(path)
21
+ true
22
+ end
23
+
24
+ def exists?(path)
25
+ @application.exists?(path)
26
+ end
27
+
28
+ def file_info(path)
29
+ ::Ftpd::FileInfo.new(
30
+ :ftype => directory?(path) ? 'directory' : 'file',
31
+ :group => 'nogroup',
32
+ :mode => 0777,
33
+ :mtime => Time.now,
34
+ :nlink => 33,
35
+ :owner => 'nobody',
36
+ :path => path,
37
+ :size => 0)
38
+ end
39
+ end
40
+ end
41
+ end
data/lib/ftpmvc/server.rb CHANGED
@@ -1,5 +1,5 @@
1
- require 'em-ftpd'
2
- require 'ftpmvc/driver'
1
+ require 'ftpd'
2
+ require 'ftpmvc/ftpd'
3
3
 
4
4
  module FTPMVC
5
5
  class Server
@@ -11,30 +11,25 @@ module FTPMVC
11
11
  end
12
12
 
13
13
  def start_in_new_thread(application)
14
- queue = Queue.new
15
- server_thread = Thread.new do
16
- begin
17
- start(application) do |server|
18
- queue << server
19
- end
20
- rescue => e
21
- $strerr.puts "Server error: #{e.class}: #{e.message}"
22
- end
23
- end
24
- queue.pop
14
+ driver = Ftpd::Driver.new(application)
15
+ @server = ::Ftpd::FtpServer.new(driver)
16
+ @server.interface, @server.port = @address, @port
17
+ @server.start
18
+ @port = @server.bound_port
19
+ self
25
20
  end
26
21
 
27
22
  def start(application)
28
- EM.epoll
29
- EM::run do
30
- @signature = EM::start_server(@host, @port, EM::FTPD::Server, Driver, application)
31
- @port = Socket.unpack_sockaddr_in(EM.get_sockname(@signature)).first
32
- yield self if block_given?
33
- end
23
+ start_in_new_thread(application)
24
+ yield self if block_given?
25
+ # Manter o instance_variable_get até o pull request #29 ser aprovado
26
+ # o uma nova versão ficar disponível.
27
+ @server.instance_variable_get(:@server_thread).join
28
+ # @server.join
34
29
  end
35
30
 
36
31
  def stop
37
- EM.stop_server(@signature)
32
+ @server.stop
38
33
  end
39
34
  end
40
35
  end
@@ -11,7 +11,7 @@ module FTPMVC
11
11
  ftp.connect('127.0.0.1', server.port)
12
12
  yield ftp
13
13
  ensure
14
- ftp.close
14
+ ftp.close rescue nil
15
15
  end
16
16
  ensure
17
17
  server.stop
@@ -1,3 +1,3 @@
1
1
  module FTPMVC
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -1,11 +1,12 @@
1
1
  require './spec/spec_helper'
2
- require 'ftpmvc/application'
2
+
3
+ require 'ftpmvc'
3
4
 
4
5
  describe 'Operation' do
5
6
  before do
6
7
  music_directory_class = Class.new(FTPMVC::Directory) do
7
- def size(path)
8
- 69
8
+ def index
9
+ [ FTPMVC::File.new('pink_floyd.mp3') ]
9
10
  end
10
11
 
11
12
  def get(path)
@@ -39,19 +40,35 @@ describe 'Operation' do
39
40
  end
40
41
  end
41
42
  describe 'SIZE' do
42
- it 'checks if directory exists' do
43
+ it 'is the file size' do
43
44
  with_application(app) do |ftp|
44
45
  ftp.login
45
- expect(ftp.size('/music/pink_floyd.mp3')).to eq 69
46
+ expect(ftp.size('/music/pink_floyd.mp3')).to eq 7
46
47
  end
47
48
  end
48
49
  end
49
50
  describe 'GET' do
50
- it 'checks if directory exists' do
51
+ it 'is the file content' do
51
52
  with_application(app) do |ftp|
52
53
  ftp.login
53
54
  expect(get(ftp, '/music/pink_floyd.mp3')).to eq 'content'
54
55
  end
55
56
  end
56
57
  end
58
+ describe 'GET' do
59
+ it 'is the file content' do
60
+ with_application(app) do |ftp|
61
+ ftp.login
62
+ expect(get(ftp, '/music/pink_floyd.mp3')).to eq 'content'
63
+ end
64
+ end
65
+ end
66
+ describe 'MDTM' do
67
+ it 'is the modification time of a file' do
68
+ with_application(app) do |ftp|
69
+ ftp.login
70
+ expect(ftp.mdtm('/music/pink_floyd.mp3')).to be_a_kind_of String
71
+ end
72
+ end
73
+ end
57
74
  end
@@ -57,19 +57,4 @@ describe FTPMVC::AccessFilesystemFilter do
57
57
  .to eq 'Pink Floyd'
58
58
  end
59
59
  end
60
-
61
- describe '#bytes' do
62
- before do
63
- allow_any_instance_of(MusicDirectory)
64
- .to receive(:get).with('songs.txt')
65
- .and_return StringIO.new('Pink Floyd')
66
- allow_any_instance_of(MusicDirectory)
67
- .to receive(:get).with('documents.txt')
68
- .and_return nil
69
- end
70
- it 'is the return of the directory' do
71
- expect(filter.size('/music/songs.txt'))
72
- .to eq 10
73
- end
74
- end
75
60
  end
@@ -75,25 +75,6 @@ describe FTPMVC::Directory do
75
75
  end
76
76
  end
77
77
 
78
- describe '#size' do
79
- before do
80
- allow(documents)
81
- .to receive(:get).with('password.txt')
82
- .and_return StringIO.new('12345678')
83
- allow(documents)
84
- .to receive(:get).with('users.txt')
85
- .and_return nil
86
- end
87
- it 'is the size in bytes of #get return' do
88
- expect(documents.size('password.txt')).to eq 8
89
- end
90
- context 'when #get returns nil' do
91
- it 'is nil' do
92
- expect(documents.size('users.txt')).to be_nil
93
- end
94
- end
95
- end
96
-
97
78
  describe '#get' do
98
79
  let(:password_txt) { FTPMVC::File.new('password.txt') }
99
80
  before do
@@ -1,6 +1,7 @@
1
1
  require './spec/spec_helper'
2
2
 
3
3
  require 'ftpmvc/server'
4
+ require 'ftpmvc/directory'
4
5
 
5
6
  describe FTPMVC::Server do
6
7
  describe '#start' do
data/spec/spec_helper.rb CHANGED
@@ -4,6 +4,7 @@ if ENV.include?('CODECLIMATE_REPO_TOKEN')
4
4
  end
5
5
 
6
6
  require 'ftpmvc/test_helpers'
7
+ require 'active_support/dependencies'
7
8
 
8
9
  RSpec.configure do |config|
9
10
  config.include FTPMVC::TestHelpers
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ftpmvc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - André Aizim Kelmanson
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-10-31 00:00:00.000000000 Z
11
+ date: 2014-11-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -81,7 +81,7 @@ dependencies:
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
- name: em-ftpd
84
+ name: ftpd
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
87
  - - '>='
@@ -135,11 +135,13 @@ files:
135
135
  - lib/ftpmvc/authenticator/basic.rb
136
136
  - lib/ftpmvc/authenticator/promiscuous.rb
137
137
  - lib/ftpmvc/directory.rb
138
- - lib/ftpmvc/driver.rb
139
138
  - lib/ftpmvc/file.rb
140
139
  - lib/ftpmvc/filter.rb
141
140
  - lib/ftpmvc/format.rb
142
141
  - lib/ftpmvc/format/csv.rb
142
+ - lib/ftpmvc/ftpd.rb
143
+ - lib/ftpmvc/ftpd/driver.rb
144
+ - lib/ftpmvc/ftpd/file_system.rb
143
145
  - lib/ftpmvc/server.rb
144
146
  - lib/ftpmvc/test_helpers.rb
145
147
  - lib/ftpmvc/version.rb
@@ -186,3 +188,4 @@ test_files:
186
188
  - spec/lib/ftpmvc/format/csv_spec.rb
187
189
  - spec/lib/ftpmvc/server_spec.rb
188
190
  - spec/spec_helper.rb
191
+ has_rdoc:
data/lib/ftpmvc/driver.rb DELETED
@@ -1,30 +0,0 @@
1
- require 'em-ftpd'
2
- require 'ftpmvc/directory'
3
-
4
- module FTPMVC
5
- class Driver
6
- def initialize(application)
7
- @application = application
8
- end
9
-
10
- def dir_contents(path)
11
- yield @application.index(path).map { |node| EM::FTPD::DirectoryItem.new(name: node.name) }
12
- end
13
-
14
- def authenticate(username, password)
15
- yield @application.authenticate(username, password)
16
- end
17
-
18
- def change_dir(path)
19
- yield @application.directory?(path)
20
- end
21
-
22
- def get_file(path)
23
- yield @application.get(path)
24
- end
25
-
26
- def bytes(path)
27
- yield @application.size(path)
28
- end
29
- end
30
- end