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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e422fc8c27107d8f5d11841ca0ba9169a8d96d43
4
- data.tar.gz: c82242e855e7ae69e6fba5c8d02aae82155d70ae
3
+ metadata.gz: 024488aeef1805a8ebc1ecb4deb605bf482e6256
4
+ data.tar.gz: e5993370082b5dee9fa3070597c9375e136eb70d
5
5
  SHA512:
6
- metadata.gz: 6ae075d153762c9c1af03b408ae6643a2bb19b9ffa6d3bff83caaa022144027f80d7d43a9542e9e2f0aa4a15416e7b20a7384c226fbb93aab8edf80a2d5dd444
7
- data.tar.gz: 16ddd750c8078e758eac91145d94e2b3672b9f28d8321ef65939a81a6cb177781d9bb27745cddaf88d9205057e2c732e0e187b5e7171f747266b11b60ded7d9f
6
+ metadata.gz: bdfef3b7ae0449d4478246650a184ed13b901f4d95a3896ba1cfbf5ce5fd122d4705361123cf1214be8ae6f94d07cab2b22280d915ee51bfe9f36f7e74ac26cc
7
+ data.tar.gz: d67691c08fcad0c1d4f5c59a070822b4ea7f18479c6ff18587fcb32f43803965925738ba5d62f980e8a6cd59165725a72094fb92306319db6f4324fd5dc451c5
data/.travis.yml CHANGED
@@ -5,3 +5,6 @@ rvm:
5
5
  - 2.0.0
6
6
  - 1.9.3
7
7
  script: bundle exec rspec
8
+ addons:
9
+ code_climate:
10
+ repo_token: 992df55b0c02e1be977aa24558bb46cca26ccb8bd58882b
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # Ftpmvc
1
+ # FTPMVC
2
2
 
3
3
  TODO: Write a gem description
4
4
 
data/examples/env/env.rb CHANGED
@@ -9,4 +9,7 @@ app = FTPMVC::Application.new do
9
9
  end
10
10
  end
11
11
 
12
- FTPMVC::Server.new(2222).start(app)
12
+ FTPMVC::Server.new(2121).start(app) do |server|
13
+ puts "Server listening in #{server.host}:#{server.port}..."
14
+ end
15
+
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 = Ftpmvc::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
@@ -1,3 +1,4 @@
1
+ require 'forwardable'
1
2
  require 'ftpmvc/directory'
2
3
  require 'ftpmvc/filter'
3
4
  require 'ftpmvc/access_filesystem_filter'
@@ -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
- 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
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.specific_handler_class_name(name)
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
@@ -1,3 +1,5 @@
1
+ require 'forwardable'
2
+
1
3
  module FTPMVC
2
4
  class Filter
3
5
  extend Forwardable
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 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?
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.stop
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
@@ -1,3 +1,3 @@
1
- module Ftpmvc
2
- VERSION = "0.0.1"
1
+ module FTPMVC
2
+ VERSION = "0.0.2"
3
3
  end
data/lib/ftpmvc.rb CHANGED
@@ -3,5 +3,5 @@ require 'ftpmvc/server'
3
3
  require 'ftpmvc/file'
4
4
  require 'ftpmvc/application'
5
5
 
6
- module Ftpmvc
6
+ module FTPMVC
7
7
  end
@@ -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/access_filesystem_filter'
2
4
  require 'ftpmvc/file'
3
5
 
@@ -1,3 +1,5 @@
1
+ require './spec/spec_helper'
2
+
1
3
  require 'ftpmvc/application'
2
4
  require 'ftpmvc/file'
3
5
 
@@ -1,3 +1,5 @@
1
+ require './spec/spec_helper'
2
+
1
3
  require 'ftpmvc/directory'
2
4
  require 'ftpmvc/file'
3
5
 
@@ -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 'Cannnot connect to server'
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
@@ -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.1
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-15 00:00:00.000000000 Z
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.1.11
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