ftpmvc 0.7.0 → 0.8.0

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: 6696ff1bddf6f75d9672d0204132a12796e3fba9
4
- data.tar.gz: b15c4843e0990bdbafd9798d25c5e0ab38237c83
3
+ metadata.gz: 5bc917bf062bc477474a6f8b1376c79689e04902
4
+ data.tar.gz: 8f254536940d5ee5ddd35e095083f5fff1c1e21e
5
5
  SHA512:
6
- metadata.gz: 728265569fd9b89de5813500922b834e767708b4b2627f75527f281d632aab7516a68a91da2c367ebbd1438f15e510625358f0e1ab6dfa2ed9babaa508badce7
7
- data.tar.gz: 9b11c9548e0d017e567f56ff2f219a0a7e6fdb98033fdb3f8e570c2d047fc611ca58669d404d18e5a21a70010391df6dbc71fec182f0d1630f86b92c4d40ab0c
6
+ metadata.gz: e33c6c0b4452e338d183fa1fd9152ff9fd7a8051b4e26b38ac7a2a898c13b9d9eb68afd169442b4b678d2cb91977356b9c4496fab7753982613332bff4dc6357
7
+ data.tar.gz: 94bdfacbedaa060c50846bfb75159912fa08017b0b5a2eff35b57d6413c4ada58d84731a4942db08704a18b8923dbeca54ba4e4a019ce1996f8e3133e2c86b24
@@ -12,7 +12,7 @@ module FTPMVC
12
12
  def_delegators :auth, :authenticate
13
13
 
14
14
  def initialize(&block)
15
- @fs = Directory.new('/')
15
+ @fs = Directory.new
16
16
  @filter_chain = Filter::FilesystemAccess.new(@fs, nil)
17
17
  instance_eval(&block) if block_given?
18
18
  end
@@ -5,8 +5,8 @@ module FTPMVC
5
5
  class Directory
6
6
  attr_reader :name, :index
7
7
 
8
- def initialize(name, &block)
9
- @name = name.to_s
8
+ def initialize(options={}, &block)
9
+ @name = options[:name]
10
10
  @index = []
11
11
  instance_eval(&block) if block_given?
12
12
  end
@@ -16,10 +16,6 @@ module FTPMVC
16
16
  file ? file.data : nil
17
17
  end
18
18
 
19
- def put(path, stream)
20
- puts 'foooi!!!'
21
- end
22
-
23
19
  def resolve(path)
24
20
  path = path.gsub(%r{^/}, '')
25
21
  return self if path.empty?
@@ -32,20 +28,40 @@ module FTPMVC
32
28
  end
33
29
  end
34
30
 
35
- def self.build(name, &block)
36
- directory_class(name).new(name, &block)
37
- end
38
-
39
31
  protected
40
32
 
41
- def directory(name, &block)
42
- Directory.build(name, &block).tap do |directory|
43
- @index << directory
33
+ def directory(*args, &block)
34
+ first_arg, second_arg = args
35
+
36
+ if first_arg.kind_of?(self.class)
37
+ add_directory(first_arg)
38
+ else
39
+ if first_arg.kind_of?(Hash)
40
+ create_and_add_directory(self.class, first_arg, &block)
41
+ else
42
+ create_and_add_directory(first_arg, second_arg || {}, &block)
43
+ end
44
+ end
45
+ end
46
+
47
+ def create_and_add_directory(dir, options, &block)
48
+ if dir.kind_of?(Symbol)
49
+ options[:name] = options[:name] || dir.to_s
50
+ dir = symbol_to_class(dir)
44
51
  end
52
+ add_directory(create_directory(dir, options, &block))
53
+ end
54
+
55
+ def add_directory(dir)
56
+ dir.tap { |directory| @index << directory }
57
+ end
58
+
59
+ def create_directory(dir_class, options, &block)
60
+ dir_class.new(options, &block)
45
61
  end
46
62
 
47
- def self.directory_class(name)
48
- ActiveSupport::Dependencies.safe_constantize("#{name.to_s.camelize}Directory") || self
63
+ def symbol_to_class(symbol)
64
+ ActiveSupport::Dependencies.safe_constantize("#{symbol.to_s.camelize}Directory")
49
65
  end
50
66
  end
51
67
  end
@@ -1,3 +1,3 @@
1
1
  module FTPMVC
2
- VERSION = "0.7.0"
2
+ VERSION = "0.8.0"
3
3
  end
@@ -18,7 +18,7 @@ describe FTPMVC::Application do
18
18
  FTPMVC::Application.new do
19
19
  filter FTPMVC::Filter::Foo
20
20
  filesystem do
21
- directory :music
21
+ directory name: 'music'
22
22
  end
23
23
  end
24
24
  end
@@ -30,7 +30,7 @@ describe FTPMVC::Application do
30
30
  FTPMVC::Application.new do
31
31
  filter FTPMVC::Filter::Base
32
32
  filesystem do
33
- directory :music
33
+ directory name: 'music'
34
34
  end
35
35
  end
36
36
  end
@@ -7,24 +7,14 @@ describe FTPMVC::Directory do
7
7
  before do
8
8
  stub_const 'DocumentsDirectory', Class.new(FTPMVC::Directory)
9
9
  end
10
- let(:documents) { DocumentsDirectory.new('documents') }
11
- describe '.build' do
12
- context 'when there is a specific directory class' do
13
- it 'is an instance this specific class' do
14
- expect(FTPMVC::Directory.build(:documents)).to be_a DocumentsDirectory
15
- end
16
- it 'is an instance of DirectoryHandler' do
17
- expect(FTPMVC::Directory.build(:music)).to be_a FTPMVC::Directory
18
- end
19
- end
20
- end
10
+ let(:documents) { DocumentsDirectory.new(name: 'documents') }
21
11
 
22
12
  describe '#resolve' do
23
13
  before do
24
14
  stub_const 'ConfidentialDirectory', Class.new(FTPMVC::Directory)
25
15
  allow(documents)
26
16
  .to receive(:index)
27
- .and_return [ FTPMVC::File.new('contract.doc'), ConfidentialDirectory.new('confidential') ]
17
+ .and_return [ FTPMVC::File.new('contract.doc'), ConfidentialDirectory.new(name: 'confidential') ]
28
18
  allow_any_instance_of(ConfidentialDirectory)
29
19
  .to receive(:index)
30
20
  .and_return [ FTPMVC::File.new('passwords.txt') ]
@@ -56,23 +46,60 @@ describe FTPMVC::Directory do
56
46
  end
57
47
 
58
48
  describe '#initialize' do
59
- it 'converts name to string' do
60
- expect(FTPMVC::Directory.new(:pictures).name).to eq 'pictures'
61
- end
62
49
  it 'yields with instance_eval' do
63
50
  my_class = nil
64
- FTPMVC::Directory.new('pictures') { my_class = self.class }
51
+ FTPMVC::Directory.new(name: 'pictures') { my_class = self.class }
65
52
  expect(my_class).to be FTPMVC::Directory
66
53
  end
67
54
  end
68
55
 
69
56
  describe '#directory' do
70
57
  it 'adds a Directory object to content' do
71
- pictures = FTPMVC::Directory.new('pictures') do
72
- directory :safari
58
+ pictures = FTPMVC::Directory.new(name: 'pictures') do
59
+ directory FTPMVC::Directory, name: 'safari'
73
60
  end
74
61
  expect(pictures.resolve('safari')).to be_a FTPMVC::Directory
75
62
  end
63
+ context 'when a symbol is given' do
64
+ it 'creates an instance of the directory based on that symnol' do
65
+ home = FTPMVC::Directory.new(name: 'home') do
66
+ directory :documents, name: 'documents'
67
+ end
68
+ expect(home.resolve('documents')).to be_a DocumentsDirectory
69
+ end
70
+ end
71
+ context 'when a class is given' do
72
+ it 'creates an instance of the given class' do
73
+ home = FTPMVC::Directory.new(name: 'home') do
74
+ directory DocumentsDirectory, name: 'documents'
75
+ end
76
+ expect(home.resolve('documents')).to be_a DocumentsDirectory
77
+ end
78
+ end
79
+ context 'when a symbol is given and name is not' do
80
+ it 'sets the name based on that symbol' do
81
+ home = FTPMVC::Directory.new(name: 'home') do
82
+ directory :documents
83
+ end
84
+ expect(home.resolve('documents')).to be_a DocumentsDirectory
85
+ end
86
+ end
87
+ context 'when no symbol or class is given' do
88
+ it 'creates a FTPMVC::Directory' do
89
+ pictures = FTPMVC::Directory.new(name: 'pictures') do
90
+ directory name: 'safari'
91
+ end
92
+ expect(pictures.resolve('safari')).to be_a FTPMVC::Directory
93
+ end
94
+ end
95
+ context 'when an instance of directory is given' do
96
+ it 'uses that instance' do
97
+ pictures = FTPMVC::Directory.new(name: 'pictures') do
98
+ directory FTPMVC::Directory.new(name: 'safari')
99
+ end
100
+ expect(pictures.resolve('safari')).to be_a FTPMVC::Directory
101
+ end
102
+ end
76
103
  end
77
104
 
78
105
  describe '#get' do
@@ -7,7 +7,7 @@ describe FTPMVC::Server do
7
7
  describe '#start' do
8
8
  let(:server) { FTPMVC::Server.new('127.0.0.1', 0) }
9
9
  it 'starts the FTP server' do
10
- server.start(FTPMVC::Directory.new('/')) do
10
+ server.start(FTPMVC::Directory.new) do
11
11
  begin
12
12
  socket = TCPSocket.new('127.0.0.1', server.port)
13
13
  socket.close
metadata CHANGED
@@ -1,111 +1,111 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ftpmvc
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.7.0
4
+ version: 0.8.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: 2015-01-19 00:00:00.000000000 Z
11
+ date: 2015-02-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - "~>"
17
+ - - ~>
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.6'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - "~>"
24
+ - - ~>
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.6'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: guard-rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: terminal-notifier-guard
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - ">="
59
+ - - '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - ">="
66
+ - - '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
70
70
  name: codeclimate-test-reporter
71
71
  requirement: !ruby/object:Gem::Requirement
72
72
  requirements:
73
- - - ">="
73
+ - - '>='
74
74
  - !ruby/object:Gem::Version
75
75
  version: '0'
76
76
  type: :development
77
77
  prerelease: false
78
78
  version_requirements: !ruby/object:Gem::Requirement
79
79
  requirements:
80
- - - ">="
80
+ - - '>='
81
81
  - !ruby/object:Gem::Version
82
82
  version: '0'
83
83
  - !ruby/object:Gem::Dependency
84
84
  name: ftpd
85
85
  requirement: !ruby/object:Gem::Requirement
86
86
  requirements:
87
- - - ">="
87
+ - - '>='
88
88
  - !ruby/object:Gem::Version
89
89
  version: 1.1.1
90
90
  type: :runtime
91
91
  prerelease: false
92
92
  version_requirements: !ruby/object:Gem::Requirement
93
93
  requirements:
94
- - - ">="
94
+ - - '>='
95
95
  - !ruby/object:Gem::Version
96
96
  version: 1.1.1
97
97
  - !ruby/object:Gem::Dependency
98
98
  name: activesupport
99
99
  requirement: !ruby/object:Gem::Requirement
100
100
  requirements:
101
- - - ">="
101
+ - - '>='
102
102
  - !ruby/object:Gem::Version
103
103
  version: '0'
104
104
  type: :runtime
105
105
  prerelease: false
106
106
  version_requirements: !ruby/object:Gem::Requirement
107
107
  requirements:
108
- - - ">="
108
+ - - '>='
109
109
  - !ruby/object:Gem::Version
110
110
  version: '0'
111
111
  description: FTP MVC framework
@@ -115,9 +115,9 @@ executables: []
115
115
  extensions: []
116
116
  extra_rdoc_files: []
117
117
  files:
118
- - ".gitignore"
119
- - ".rspec"
120
- - ".travis.yml"
118
+ - .gitignore
119
+ - .rspec
120
+ - .travis.yml
121
121
  - Gemfile
122
122
  - Guardfile
123
123
  - LICENSE.txt
@@ -165,12 +165,12 @@ require_paths:
165
165
  - lib
166
166
  required_ruby_version: !ruby/object:Gem::Requirement
167
167
  requirements:
168
- - - ">="
168
+ - - '>='
169
169
  - !ruby/object:Gem::Version
170
170
  version: '0'
171
171
  required_rubygems_version: !ruby/object:Gem::Requirement
172
172
  requirements:
173
- - - ">="
173
+ - - '>='
174
174
  - !ruby/object:Gem::Version
175
175
  version: '0'
176
176
  requirements: []