ftpmvc 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/README.md +1 -1
- data/examples/env/env.rb +4 -1
- data/ftpmvc.gemspec +2 -1
- data/lib/ftpmvc/application.rb +1 -0
- data/lib/ftpmvc/directory.rb +4 -7
- data/lib/ftpmvc/filter.rb +2 -0
- data/lib/ftpmvc/server.rb +22 -9
- data/lib/ftpmvc/test_helpers.rb +30 -0
- data/lib/ftpmvc/version.rb +2 -2
- data/lib/ftpmvc.rb +1 -1
- data/spec/integration/operation_spec.rb +57 -0
- data/spec/lib/ftpmvc/access_filesystem_filter_spec.rb +2 -0
- data/spec/lib/ftpmvc/application_spec.rb +2 -0
- data/spec/lib/ftpmvc/directory_spec.rb +2 -0
- data/spec/lib/ftpmvc/server_spec.rb +4 -2
- data/spec/spec_helper.rb +13 -0
- metadata +22 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 024488aeef1805a8ebc1ecb4deb605bf482e6256
|
4
|
+
data.tar.gz: e5993370082b5dee9fa3070597c9375e136eb70d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bdfef3b7ae0449d4478246650a184ed13b901f4d95a3896ba1cfbf5ce5fd122d4705361123cf1214be8ae6f94d07cab2b22280d915ee51bfe9f36f7e74ac26cc
|
7
|
+
data.tar.gz: d67691c08fcad0c1d4f5c59a070822b4ea7f18479c6ff18587fcb32f43803965925738ba5d62f980e8a6cd59165725a72094fb92306319db6f4324fd5dc451c5
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
data/examples/env/env.rb
CHANGED
data/ftpmvc.gemspec
CHANGED
@@ -5,7 +5,7 @@ require 'ftpmvc/version'
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
7
|
spec.name = "ftpmvc"
|
8
|
-
spec.version =
|
8
|
+
spec.version = FTPMVC::VERSION
|
9
9
|
spec.authors = ["André Aizim Kelmanson"]
|
10
10
|
spec.email = ["akelmanson@gmail.com"]
|
11
11
|
spec.summary = "FTP MVC framework"
|
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
|
|
22
22
|
spec.add_development_dependency "rake"
|
23
23
|
spec.add_development_dependency "guard-rspec"
|
24
24
|
spec.add_development_dependency "terminal-notifier-guard"
|
25
|
+
spec.add_development_dependency "codeclimate-test-reporter"
|
25
26
|
spec.add_dependency "em-ftpd"
|
26
27
|
spec.add_dependency "activesupport"
|
27
28
|
end
|
data/lib/ftpmvc/application.rb
CHANGED
data/lib/ftpmvc/directory.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'active_support/dependencies'
|
1
2
|
require 'active_support/core_ext/string/inflections'
|
2
3
|
|
3
4
|
module FTPMVC
|
@@ -38,11 +39,7 @@ module FTPMVC
|
|
38
39
|
end
|
39
40
|
|
40
41
|
def self.build(name, &block)
|
41
|
-
|
42
|
-
instance = Object::const_get(specific_handler_class_name(name)).new(name, &block)
|
43
|
-
else
|
44
|
-
instance = self.new(name, &block)
|
45
|
-
end
|
42
|
+
directory_class(name).new(name, &block)
|
46
43
|
end
|
47
44
|
|
48
45
|
def directory?(path)
|
@@ -57,8 +54,8 @@ module FTPMVC
|
|
57
54
|
end
|
58
55
|
end
|
59
56
|
|
60
|
-
def self.
|
61
|
-
"#{name.to_s.camelize}Directory"
|
57
|
+
def self.directory_class(name)
|
58
|
+
ActiveSupport::Dependencies.safe_constantize("#{name.to_s.camelize}Directory") || self
|
62
59
|
end
|
63
60
|
end
|
64
61
|
end
|
data/lib/ftpmvc/filter.rb
CHANGED
data/lib/ftpmvc/server.rb
CHANGED
@@ -4,24 +4,37 @@ require 'ftpmvc/driver'
|
|
4
4
|
module FTPMVC
|
5
5
|
class Server
|
6
6
|
|
7
|
-
attr_reader :port
|
7
|
+
attr_reader :host, :port
|
8
8
|
|
9
9
|
def initialize(host='0.0.0.0', port)
|
10
10
|
@host, @port = host, port
|
11
11
|
end
|
12
12
|
|
13
|
-
def
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
13
|
+
def start_in_new_thread(application)
|
14
|
+
queue = Queue.new
|
15
|
+
server_thread = Thread.new do
|
16
|
+
begin
|
17
|
+
start(application) do
|
18
|
+
queue << true
|
19
|
+
end
|
20
|
+
rescue => e
|
21
|
+
$strerr.puts "Server error: #{e.class}: #{e.message}"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
queue.pop
|
25
|
+
end
|
26
|
+
|
27
|
+
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?
|
20
33
|
end
|
21
34
|
end
|
22
35
|
|
23
36
|
def stop
|
24
|
-
EM.
|
37
|
+
EM.stop_server(@signature)
|
25
38
|
end
|
26
39
|
end
|
27
40
|
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'net/ftp'
|
2
|
+
require 'ftpmvc/server'
|
3
|
+
|
4
|
+
module FTPMVC
|
5
|
+
module TestHelpers
|
6
|
+
def with_application(app)
|
7
|
+
FTPMVC::Server.new('127.0.0.1', 0).start_in_new_thread(app) do |server|
|
8
|
+
begin
|
9
|
+
ftp = Net::FTP.new
|
10
|
+
begin
|
11
|
+
ftp.connect('127.0.0.1', server.port)
|
12
|
+
yield ftp
|
13
|
+
ensure
|
14
|
+
ftp.close
|
15
|
+
end
|
16
|
+
ensure
|
17
|
+
server.stop
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def get(ftp, path)
|
23
|
+
''.tap do |response|
|
24
|
+
ftp.retrbinary("RETR #{path}", 1024) do |block|
|
25
|
+
response << block
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
data/lib/ftpmvc/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
|
-
module
|
2
|
-
VERSION = "0.0.
|
1
|
+
module FTPMVC
|
2
|
+
VERSION = "0.0.2"
|
3
3
|
end
|
data/lib/ftpmvc.rb
CHANGED
@@ -0,0 +1,57 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
require 'ftpmvc/application'
|
3
|
+
|
4
|
+
describe 'Operation' do
|
5
|
+
before do
|
6
|
+
music_directory_class = Class.new(FTPMVC::Directory) do
|
7
|
+
def size(path)
|
8
|
+
69
|
9
|
+
end
|
10
|
+
|
11
|
+
def get(path)
|
12
|
+
StringIO.new('content')
|
13
|
+
end
|
14
|
+
end
|
15
|
+
stub_const 'MusicDirectory', music_directory_class
|
16
|
+
end
|
17
|
+
let(:app) do
|
18
|
+
FTPMVC::Application.new do
|
19
|
+
filesystem do
|
20
|
+
directory :music
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
describe 'LIST' do
|
26
|
+
it 'lists files and directories' do
|
27
|
+
with_application(app) do |ftp|
|
28
|
+
ftp.login
|
29
|
+
expect(ftp.list('/')).to include(/music/)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
describe 'CHDIR' do
|
34
|
+
it 'checks if directory exists' do
|
35
|
+
with_application(app) do |ftp|
|
36
|
+
ftp.login
|
37
|
+
expect { ftp.chdir('/videos') }.to raise_error(Net::FTPPermError)
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
describe 'SIZE' do
|
42
|
+
it 'checks if directory exists' do
|
43
|
+
with_application(app) do |ftp|
|
44
|
+
ftp.login
|
45
|
+
expect(ftp.size('/music/pink_floyd.mp3')).to eq 69
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
49
|
+
describe 'GET' do
|
50
|
+
it 'checks if directory exists' do
|
51
|
+
with_application(app) do |ftp|
|
52
|
+
ftp.login
|
53
|
+
expect(get(ftp, '/music/pink_floyd.mp3')).to eq 'content'
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
require './spec/spec_helper'
|
2
|
+
|
1
3
|
require 'ftpmvc/server'
|
2
4
|
|
3
5
|
describe FTPMVC::Server do
|
@@ -8,8 +10,8 @@ describe FTPMVC::Server do
|
|
8
10
|
begin
|
9
11
|
socket = TCPSocket.new('127.0.0.1', server.port)
|
10
12
|
socket.close
|
11
|
-
rescue Errno::ECONNREFUSED, Errno::EADDRNOTAVAIL
|
12
|
-
fail
|
13
|
+
rescue Errno::ECONNREFUSED, Errno::EADDRNOTAVAIL => e
|
14
|
+
fail "Cannnot connect to server! (#{e.class}: #{e.message})"
|
13
15
|
ensure
|
14
16
|
server.stop
|
15
17
|
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
if ENV.include?('CODECLIMATE_REPO_TOKEN')
|
2
|
+
require "codeclimate-test-reporter"
|
3
|
+
CodeClimate::TestReporter.start
|
4
|
+
end
|
5
|
+
|
6
|
+
require 'ftpmvc/test_helpers'
|
7
|
+
|
8
|
+
RSpec.configure do |config|
|
9
|
+
config.include FTPMVC::TestHelpers
|
10
|
+
config.before :each do
|
11
|
+
ActiveSupport::Dependencies.clear
|
12
|
+
end
|
13
|
+
end
|
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.0.
|
4
|
+
version: 0.0.2
|
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-
|
11
|
+
date: 2014-10-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - '>='
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: codeclimate-test-reporter
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: em-ftpd
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -122,11 +136,14 @@ files:
|
|
122
136
|
- lib/ftpmvc/file.rb
|
123
137
|
- lib/ftpmvc/filter.rb
|
124
138
|
- lib/ftpmvc/server.rb
|
139
|
+
- lib/ftpmvc/test_helpers.rb
|
125
140
|
- lib/ftpmvc/version.rb
|
141
|
+
- spec/integration/operation_spec.rb
|
126
142
|
- spec/lib/ftpmvc/access_filesystem_filter_spec.rb
|
127
143
|
- spec/lib/ftpmvc/application_spec.rb
|
128
144
|
- spec/lib/ftpmvc/directory_spec.rb
|
129
145
|
- spec/lib/ftpmvc/server_spec.rb
|
146
|
+
- spec/spec_helper.rb
|
130
147
|
homepage: https://github.com/investtools/ftpmvc
|
131
148
|
licenses:
|
132
149
|
- MIT
|
@@ -147,12 +164,14 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
164
|
version: '0'
|
148
165
|
requirements: []
|
149
166
|
rubyforge_project:
|
150
|
-
rubygems_version: 2.
|
167
|
+
rubygems_version: 2.2.2
|
151
168
|
signing_key:
|
152
169
|
specification_version: 4
|
153
170
|
summary: FTP MVC framework
|
154
171
|
test_files:
|
172
|
+
- spec/integration/operation_spec.rb
|
155
173
|
- spec/lib/ftpmvc/access_filesystem_filter_spec.rb
|
156
174
|
- spec/lib/ftpmvc/application_spec.rb
|
157
175
|
- spec/lib/ftpmvc/directory_spec.rb
|
158
176
|
- spec/lib/ftpmvc/server_spec.rb
|
177
|
+
- spec/spec_helper.rb
|