ftpmvc 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/.rspec +1 -0
- data/.travis.yml +7 -0
- data/Gemfile +4 -0
- data/Guardfile +33 -0
- data/LICENSE.txt +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/examples/env/Gemfile +3 -0
- data/examples/env/env.rb +12 -0
- data/examples/env/env_directory.rb +7 -0
- data/examples/env/env_file.rb +10 -0
- data/ftpmvc.gemspec +27 -0
- data/lib/ftpmvc/access_filesystem_filter.rb +23 -0
- data/lib/ftpmvc/application.rb +27 -0
- data/lib/ftpmvc/directory.rb +64 -0
- data/lib/ftpmvc/driver.rb +30 -0
- data/lib/ftpmvc/file.rb +7 -0
- data/lib/ftpmvc/filter.rb +11 -0
- data/lib/ftpmvc/server.rb +27 -0
- data/lib/ftpmvc/version.rb +3 -0
- data/lib/ftpmvc.rb +7 -0
- data/spec/lib/ftpmvc/access_filesystem_filter_spec.rb +73 -0
- data/spec/lib/ftpmvc/application_spec.rb +38 -0
- data/spec/lib/ftpmvc/directory_spec.rb +114 -0
- data/spec/lib/ftpmvc/server_spec.rb +19 -0
- metadata +158 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e422fc8c27107d8f5d11841ca0ba9169a8d96d43
|
4
|
+
data.tar.gz: c82242e855e7ae69e6fba5c8d02aae82155d70ae
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 6ae075d153762c9c1af03b408ae6643a2bb19b9ffa6d3bff83caaa022144027f80d7d43a9542e9e2f0aa4a15416e7b20a7384c226fbb93aab8edf80a2d5dd444
|
7
|
+
data.tar.gz: 16ddd750c8078e758eac91145d94e2b3672b9f28d8321ef65939a81a6cb177781d9bb27745cddaf88d9205057e2c732e0e187b5e7171f747266b11b60ded7d9f
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/.travis.yml
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
# Note: The cmd option is now required due to the increasing number of ways
|
5
|
+
# rspec may be run, below are examples of the most common uses.
|
6
|
+
# * bundler: 'bundle exec rspec'
|
7
|
+
# * bundler binstubs: 'bin/rspec'
|
8
|
+
# * spring: 'bin/rsspec' (This will use spring if running and you have
|
9
|
+
# installed the spring binstubs per the docs)
|
10
|
+
# * zeus: 'zeus rspec' (requires the server to be started separetly)
|
11
|
+
# * 'just' rspec: 'rspec'
|
12
|
+
guard :rspec, cmd: 'bundle exec rspec' do
|
13
|
+
watch(%r{^spec/.+_spec\.rb$})
|
14
|
+
watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
15
|
+
watch('spec/spec_helper.rb') { "spec" }
|
16
|
+
|
17
|
+
# Rails example
|
18
|
+
watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
|
19
|
+
watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
|
20
|
+
watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
|
21
|
+
watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
|
22
|
+
watch('config/routes.rb') { "spec/routing" }
|
23
|
+
watch('app/controllers/application_controller.rb') { "spec/controllers" }
|
24
|
+
watch('spec/rails_helper.rb') { "spec" }
|
25
|
+
|
26
|
+
# Capybara features specs
|
27
|
+
watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
|
28
|
+
|
29
|
+
# Turnip features and steps
|
30
|
+
watch(%r{^spec/acceptance/(.+)\.feature$})
|
31
|
+
watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
|
32
|
+
end
|
33
|
+
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 André Aizim Kelmanson
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# Ftpmvc
|
2
|
+
|
3
|
+
TODO: Write a gem description
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'ftpmvc'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install ftpmvc
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it ( https://github.com/[my-github-username]/ftpmvc/fork )
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/examples/env/env.rb
ADDED
data/ftpmvc.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'ftpmvc/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "ftpmvc"
|
8
|
+
spec.version = Ftpmvc::VERSION
|
9
|
+
spec.authors = ["André Aizim Kelmanson"]
|
10
|
+
spec.email = ["akelmanson@gmail.com"]
|
11
|
+
spec.summary = "FTP MVC framework"
|
12
|
+
spec.description = "FTP MVC framework"
|
13
|
+
spec.homepage = "https://github.com/investtools/ftpmvc"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "guard-rspec"
|
24
|
+
spec.add_development_dependency "terminal-notifier-guard"
|
25
|
+
spec.add_dependency "em-ftpd"
|
26
|
+
spec.add_dependency "activesupport"
|
27
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'ftpmvc/directory'
|
2
|
+
require 'ftpmvc/filter'
|
3
|
+
|
4
|
+
module FTPMVC
|
5
|
+
class AccessFilesystemFilter < FTPMVC::Filter
|
6
|
+
|
7
|
+
def get(path)
|
8
|
+
@fs.resolve(::File.dirname(path)).get(::File.basename(path))
|
9
|
+
end
|
10
|
+
|
11
|
+
def index(path)
|
12
|
+
@fs.resolve(path).index
|
13
|
+
end
|
14
|
+
|
15
|
+
def size(path)
|
16
|
+
@fs.resolve(::File.dirname(path)).size(::File.basename(path))
|
17
|
+
end
|
18
|
+
|
19
|
+
def directory?(path)
|
20
|
+
@fs.directory?(path)
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'ftpmvc/directory'
|
2
|
+
require 'ftpmvc/filter'
|
3
|
+
require 'ftpmvc/access_filesystem_filter'
|
4
|
+
|
5
|
+
module FTPMVC
|
6
|
+
class Application
|
7
|
+
extend Forwardable
|
8
|
+
|
9
|
+
def_delegators :@filter_chain, :index, :size, :get, :directory?
|
10
|
+
|
11
|
+
def initialize(&block)
|
12
|
+
@fs = FTPMVC::Directory.new('/')
|
13
|
+
@filter_chain = AccessFilesystemFilter.new(@fs, nil)
|
14
|
+
instance_eval(&block)
|
15
|
+
end
|
16
|
+
|
17
|
+
protected
|
18
|
+
|
19
|
+
def filter(filter_class, options={})
|
20
|
+
@filter_chain = filter_class.new(@fs, @filter_chain, options)
|
21
|
+
end
|
22
|
+
|
23
|
+
def filesystem(&block)
|
24
|
+
@fs.instance_eval(&block)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,64 @@
|
|
1
|
+
require 'active_support/core_ext/string/inflections'
|
2
|
+
|
3
|
+
module FTPMVC
|
4
|
+
class Directory
|
5
|
+
attr_reader :name, :index
|
6
|
+
|
7
|
+
def initialize(name, &block)
|
8
|
+
@name = name.to_s
|
9
|
+
@index = []
|
10
|
+
instance_eval(&block) if block_given?
|
11
|
+
end
|
12
|
+
|
13
|
+
def size(path)
|
14
|
+
io = get(path)
|
15
|
+
return nil if io.nil?
|
16
|
+
total_size = 0
|
17
|
+
while buffer = io.read(1024)
|
18
|
+
total_size += buffer.size
|
19
|
+
end
|
20
|
+
total_size
|
21
|
+
end
|
22
|
+
|
23
|
+
def get(path)
|
24
|
+
file = resolve(path)
|
25
|
+
file ? file.data : nil
|
26
|
+
end
|
27
|
+
|
28
|
+
def resolve(path)
|
29
|
+
path = path.gsub(%r{^/}, '')
|
30
|
+
return self if path.empty?
|
31
|
+
name, subpath = path.split('/', 2)
|
32
|
+
child = index.find { |node| node.name == name }
|
33
|
+
if subpath == nil or child == nil
|
34
|
+
child
|
35
|
+
else
|
36
|
+
child.resolve(subpath)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.build(name, &block)
|
41
|
+
if Object.const_defined?(specific_handler_class_name(name))
|
42
|
+
instance = Object::const_get(specific_handler_class_name(name)).new(name, &block)
|
43
|
+
else
|
44
|
+
instance = self.new(name, &block)
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def directory?(path)
|
49
|
+
resolve(path).kind_of?(Directory)
|
50
|
+
end
|
51
|
+
|
52
|
+
protected
|
53
|
+
|
54
|
+
def directory(name, &block)
|
55
|
+
Directory.build(name, &block).tap do |directory|
|
56
|
+
@index << directory
|
57
|
+
end
|
58
|
+
end
|
59
|
+
|
60
|
+
def self.specific_handler_class_name(name)
|
61
|
+
"#{name.to_s.camelize}Directory"
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
@@ -0,0 +1,30 @@
|
|
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 true
|
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
|
data/lib/ftpmvc/file.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
require 'em-ftpd'
|
2
|
+
require 'ftpmvc/driver'
|
3
|
+
|
4
|
+
module FTPMVC
|
5
|
+
class Server
|
6
|
+
|
7
|
+
attr_reader :port
|
8
|
+
|
9
|
+
def initialize(host='0.0.0.0', port)
|
10
|
+
@host, @port = host, port
|
11
|
+
end
|
12
|
+
|
13
|
+
def start(root)
|
14
|
+
EventMachine.epoll
|
15
|
+
EventMachine::run do
|
16
|
+
signature = EventMachine::start_server(@host, @port, EM::FTPD::Server, Driver, root)
|
17
|
+
@port = Socket.unpack_sockaddr_in(EM.get_sockname(signature)).first
|
18
|
+
puts "Server listening on #{@host}:#{@port}..."
|
19
|
+
Thread.new { yield self } if block_given?
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def stop
|
24
|
+
EM.stop
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/ftpmvc.rb
ADDED
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'ftpmvc/access_filesystem_filter'
|
2
|
+
require 'ftpmvc/file'
|
3
|
+
|
4
|
+
describe FTPMVC::AccessFilesystemFilter do
|
5
|
+
let(:filesystem) do
|
6
|
+
FTPMVC::Directory.new('/') do
|
7
|
+
directory :music
|
8
|
+
end
|
9
|
+
end
|
10
|
+
let(:filter) { FTPMVC::AccessFilesystemFilter.new(filesystem, nil) }
|
11
|
+
before do
|
12
|
+
stub_const 'MusicDirectory', Class.new(FTPMVC::Directory)
|
13
|
+
end
|
14
|
+
|
15
|
+
describe '#dir_contents' do
|
16
|
+
it 'is an array' do
|
17
|
+
expect(filter.index('/')).to be_kind_of Array
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
describe '#directory?' do
|
22
|
+
context 'when path exists' do
|
23
|
+
it 'is true' do
|
24
|
+
expect(filter.directory?('/music')).to be true
|
25
|
+
end
|
26
|
+
end
|
27
|
+
context 'when path is not a directory' do
|
28
|
+
before do
|
29
|
+
allow_any_instance_of(MusicDirectory)
|
30
|
+
.to receive(:index)
|
31
|
+
.and_return [ FTPMVC::File.new('bob_marley.mp3') ]
|
32
|
+
end
|
33
|
+
it 'is false' do
|
34
|
+
expect(filter.directory?('/music/bob_marley.mp3')).to be false
|
35
|
+
end
|
36
|
+
end
|
37
|
+
context 'when path does not exist' do
|
38
|
+
it 'is false' do
|
39
|
+
expect(filter.directory?('/documents')).to be false
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#get' do
|
45
|
+
before do
|
46
|
+
allow_any_instance_of(MusicDirectory)
|
47
|
+
.to receive(:index)
|
48
|
+
.and_return [ FTPMVC::File.new('songs.txt') ]
|
49
|
+
allow_any_instance_of(MusicDirectory)
|
50
|
+
.to receive(:get).with('songs.txt')
|
51
|
+
.and_return StringIO.new('Pink Floyd')
|
52
|
+
end
|
53
|
+
it 'is the return of the directory' do
|
54
|
+
expect(filter.get('/music/songs.txt').read)
|
55
|
+
.to eq 'Pink Floyd'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe '#bytes' do
|
60
|
+
before do
|
61
|
+
allow_any_instance_of(MusicDirectory)
|
62
|
+
.to receive(:get).with('songs.txt')
|
63
|
+
.and_return StringIO.new('Pink Floyd')
|
64
|
+
allow_any_instance_of(MusicDirectory)
|
65
|
+
.to receive(:get).with('documents.txt')
|
66
|
+
.and_return nil
|
67
|
+
end
|
68
|
+
it 'is the return of the directory' do
|
69
|
+
expect(filter.size('/music/songs.txt'))
|
70
|
+
.to eq 10
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
require 'ftpmvc/application'
|
2
|
+
require 'ftpmvc/file'
|
3
|
+
|
4
|
+
describe FTPMVC::Application do
|
5
|
+
describe '#filter' do
|
6
|
+
before do
|
7
|
+
stub_const 'FooFilter', Class.new(FTPMVC::Filter)
|
8
|
+
allow_any_instance_of(FooFilter)
|
9
|
+
.to receive(:index)
|
10
|
+
.and_return [ foo_file ]
|
11
|
+
end
|
12
|
+
let(:foo_file) { FTPMVC::File.new('foo') }
|
13
|
+
let(:application) do
|
14
|
+
FTPMVC::Application.new do
|
15
|
+
filter FooFilter
|
16
|
+
filesystem do
|
17
|
+
directory :music
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
it 'applies filter on index' do
|
22
|
+
expect(application.index('/')).to eq [ foo_file ]
|
23
|
+
end
|
24
|
+
context 'when filter chains' do
|
25
|
+
let(:application) do
|
26
|
+
FTPMVC::Application.new do
|
27
|
+
filter FTPMVC::Filter
|
28
|
+
filesystem do
|
29
|
+
directory :music
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
it 'works' do
|
34
|
+
expect(application.index('/').first.name).to eq 'music'
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,114 @@
|
|
1
|
+
require 'ftpmvc/directory'
|
2
|
+
require 'ftpmvc/file'
|
3
|
+
|
4
|
+
describe FTPMVC::Directory do
|
5
|
+
before do
|
6
|
+
stub_const 'DocumentsDirectory', Class.new(FTPMVC::Directory)
|
7
|
+
end
|
8
|
+
let(:documents) { DocumentsDirectory.new('documents') }
|
9
|
+
describe '.build' do
|
10
|
+
context 'when there is a specific directory class' do
|
11
|
+
it 'is an instance this specific class' do
|
12
|
+
expect(FTPMVC::Directory.build(:documents)).to be_a DocumentsDirectory
|
13
|
+
end
|
14
|
+
it 'is an instance of DirectoryHandler' do
|
15
|
+
expect(FTPMVC::Directory.build(:music)).to be_a FTPMVC::Directory
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe '#resolve' do
|
21
|
+
before do
|
22
|
+
stub_const 'ConfidentialDirectory', Class.new(FTPMVC::Directory)
|
23
|
+
allow(documents)
|
24
|
+
.to receive(:index)
|
25
|
+
.and_return [ FTPMVC::File.new('contract.doc'), ConfidentialDirectory.new('confidential') ]
|
26
|
+
allow_any_instance_of(ConfidentialDirectory)
|
27
|
+
.to receive(:index)
|
28
|
+
.and_return [ FTPMVC::File.new('passwords.txt') ]
|
29
|
+
end
|
30
|
+
it 'finds files' do
|
31
|
+
expect(documents.resolve('contract.doc')).to eq FTPMVC::File.new('contract.doc')
|
32
|
+
end
|
33
|
+
it 'finds files inside child directories' do
|
34
|
+
expect(documents.resolve('confidential/passwords.txt')).to eq FTPMVC::File.new('passwords.txt')
|
35
|
+
end
|
36
|
+
it 'accepts slash as the first character' do
|
37
|
+
expect(documents.resolve('/contract.doc')).to eq FTPMVC::File.new('contract.doc')
|
38
|
+
end
|
39
|
+
context 'when path does not exist' do
|
40
|
+
it 'is nil' do
|
41
|
+
expect(documents.resolve('phones.txt')).to be_nil
|
42
|
+
end
|
43
|
+
end
|
44
|
+
context 'when path is /' do
|
45
|
+
it 'is self' do
|
46
|
+
expect(documents.resolve('/')).to be documents
|
47
|
+
end
|
48
|
+
end
|
49
|
+
context 'when directory does not exist' do
|
50
|
+
it 'is nil' do
|
51
|
+
expect(documents.resolve('phones/home.txt')).to be_nil
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
describe '#initialize' do
|
57
|
+
it 'converts name to string' do
|
58
|
+
expect(FTPMVC::Directory.new(:pictures).name).to eq 'pictures'
|
59
|
+
end
|
60
|
+
it 'yields with instance_eval' do
|
61
|
+
my_class = nil
|
62
|
+
FTPMVC::Directory.new('pictures') { my_class = self.class }
|
63
|
+
expect(my_class).to be FTPMVC::Directory
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
describe '#directory' do
|
68
|
+
it 'adds a Directory object to content' do
|
69
|
+
pictures = FTPMVC::Directory.new('pictures') do
|
70
|
+
directory :safari
|
71
|
+
end
|
72
|
+
expect(pictures.resolve('safari')).to be_a FTPMVC::Directory
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
describe '#size' do
|
77
|
+
before do
|
78
|
+
allow(documents)
|
79
|
+
.to receive(:get).with('password.txt')
|
80
|
+
.and_return StringIO.new('12345678')
|
81
|
+
allow(documents)
|
82
|
+
.to receive(:get).with('users.txt')
|
83
|
+
.and_return nil
|
84
|
+
end
|
85
|
+
it 'is the size in bytes of #get return' do
|
86
|
+
expect(documents.size('password.txt')).to eq 8
|
87
|
+
end
|
88
|
+
context 'when #get returns nil' do
|
89
|
+
it 'is nil' do
|
90
|
+
expect(documents.size('users.txt')).to be_nil
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
describe '#get' do
|
96
|
+
let(:password_txt) { FTPMVC::File.new('password.txt') }
|
97
|
+
before do
|
98
|
+
allow(documents)
|
99
|
+
.to receive(:index)
|
100
|
+
.and_return [ password_txt ]
|
101
|
+
allow(password_txt)
|
102
|
+
.to receive(:data)
|
103
|
+
.and_return StringIO.new('12345678')
|
104
|
+
end
|
105
|
+
it 'calls File#data' do
|
106
|
+
expect(documents.get('password.txt').read).to eq '12345678'
|
107
|
+
end
|
108
|
+
context 'when path does not exist' do
|
109
|
+
it 'is nil' do
|
110
|
+
expect(documents.get('users.txt')).to be_nil
|
111
|
+
end
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require 'ftpmvc/server'
|
2
|
+
|
3
|
+
describe FTPMVC::Server do
|
4
|
+
describe '#start' do
|
5
|
+
let(:server) { FTPMVC::Server.new('127.0.0.1', 0) }
|
6
|
+
it 'starts the FTP server' do
|
7
|
+
server.start(FTPMVC::Directory.new('/')) do
|
8
|
+
begin
|
9
|
+
socket = TCPSocket.new('127.0.0.1', server.port)
|
10
|
+
socket.close
|
11
|
+
rescue Errno::ECONNREFUSED, Errno::EADDRNOTAVAIL
|
12
|
+
fail 'Cannnot connect to server'
|
13
|
+
ensure
|
14
|
+
server.stop
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,158 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: ftpmvc
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- André Aizim Kelmanson
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-10-15 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '1.6'
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '1.6'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: guard-rspec
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: terminal-notifier-guard
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: em-ftpd
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :runtime
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: activesupport
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :runtime
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: FTP MVC framework
|
98
|
+
email:
|
99
|
+
- akelmanson@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- .rspec
|
106
|
+
- .travis.yml
|
107
|
+
- Gemfile
|
108
|
+
- Guardfile
|
109
|
+
- LICENSE.txt
|
110
|
+
- README.md
|
111
|
+
- Rakefile
|
112
|
+
- examples/env/Gemfile
|
113
|
+
- examples/env/env.rb
|
114
|
+
- examples/env/env_directory.rb
|
115
|
+
- examples/env/env_file.rb
|
116
|
+
- ftpmvc.gemspec
|
117
|
+
- lib/ftpmvc.rb
|
118
|
+
- lib/ftpmvc/access_filesystem_filter.rb
|
119
|
+
- lib/ftpmvc/application.rb
|
120
|
+
- lib/ftpmvc/directory.rb
|
121
|
+
- lib/ftpmvc/driver.rb
|
122
|
+
- lib/ftpmvc/file.rb
|
123
|
+
- lib/ftpmvc/filter.rb
|
124
|
+
- lib/ftpmvc/server.rb
|
125
|
+
- lib/ftpmvc/version.rb
|
126
|
+
- spec/lib/ftpmvc/access_filesystem_filter_spec.rb
|
127
|
+
- spec/lib/ftpmvc/application_spec.rb
|
128
|
+
- spec/lib/ftpmvc/directory_spec.rb
|
129
|
+
- spec/lib/ftpmvc/server_spec.rb
|
130
|
+
homepage: https://github.com/investtools/ftpmvc
|
131
|
+
licenses:
|
132
|
+
- MIT
|
133
|
+
metadata: {}
|
134
|
+
post_install_message:
|
135
|
+
rdoc_options: []
|
136
|
+
require_paths:
|
137
|
+
- lib
|
138
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
139
|
+
requirements:
|
140
|
+
- - '>='
|
141
|
+
- !ruby/object:Gem::Version
|
142
|
+
version: '0'
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
requirements:
|
145
|
+
- - '>='
|
146
|
+
- !ruby/object:Gem::Version
|
147
|
+
version: '0'
|
148
|
+
requirements: []
|
149
|
+
rubyforge_project:
|
150
|
+
rubygems_version: 2.1.11
|
151
|
+
signing_key:
|
152
|
+
specification_version: 4
|
153
|
+
summary: FTP MVC framework
|
154
|
+
test_files:
|
155
|
+
- spec/lib/ftpmvc/access_filesystem_filter_spec.rb
|
156
|
+
- spec/lib/ftpmvc/application_spec.rb
|
157
|
+
- spec/lib/ftpmvc/directory_spec.rb
|
158
|
+
- spec/lib/ftpmvc/server_spec.rb
|