raval 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +3 -0
- data/MIT-LICENSE +20 -0
- data/README.markdown +202 -0
- data/examples/fake.rb +110 -0
- data/examples/fog.rb +183 -0
- data/lib/raval.rb +8 -0
- data/lib/raval/active_socket.rb +49 -0
- data/lib/raval/app.rb +137 -0
- data/lib/raval/connection.rb +50 -0
- data/lib/raval/handler.rb +549 -0
- data/lib/raval/list_formatter.rb +48 -0
- data/lib/raval/passive_socket.rb +86 -0
- data/lib/raval/server.rb +45 -0
- data/spec/handler_spec.rb +832 -0
- data/spec/list_formatter_spec.rb +71 -0
- data/spec/spec_helper.rb +16 -0
- data/spec/support/test_driver.rb +88 -0
- metadata +165 -0
@@ -0,0 +1,71 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require "spec_helper"
|
4
|
+
require "ostruct"
|
5
|
+
|
6
|
+
|
7
|
+
def a_valid_directory
|
8
|
+
OpenStruct.new(:directory => true,
|
9
|
+
:permissions => "r--r--r--",
|
10
|
+
:owner => "auser",
|
11
|
+
:group => "agroup",
|
12
|
+
:size => 0,
|
13
|
+
:time => Time.mktime(2012,10,10,10,10),
|
14
|
+
:name => "files")
|
15
|
+
end
|
16
|
+
|
17
|
+
def a_valid_file
|
18
|
+
OpenStruct.new(:directory => false,
|
19
|
+
:permissions => "r--r--r--",
|
20
|
+
:owner => "auser",
|
21
|
+
:group => "agroup",
|
22
|
+
:size => 1024,
|
23
|
+
:time => Time.mktime(2012,10,10,10,10),
|
24
|
+
:name => "one.txt")
|
25
|
+
end
|
26
|
+
describe Raval::ListFormatter, "initialisation" do
|
27
|
+
context "with a directory and a file" do
|
28
|
+
let!(:files) { [a_valid_directory, a_valid_file] }
|
29
|
+
|
30
|
+
it "should initialise without error" do
|
31
|
+
lambda {
|
32
|
+
Raval::ListFormatter.new(files)
|
33
|
+
}.should_not raise_error(ArgumentError)
|
34
|
+
end
|
35
|
+
end
|
36
|
+
context "with a string" do
|
37
|
+
let!(:files) { ["foo"] }
|
38
|
+
|
39
|
+
it "should raise an exception" do
|
40
|
+
lambda {
|
41
|
+
Raval::ListFormatter.new(files)
|
42
|
+
}.should raise_error(ArgumentError)
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
end
|
47
|
+
|
48
|
+
describe Raval::ListFormatter, "#short" do
|
49
|
+
context "with a directory and a file" do
|
50
|
+
let!(:files) { [a_valid_directory, a_valid_file] }
|
51
|
+
subject { Raval::ListFormatter.new(files)}
|
52
|
+
|
53
|
+
it "should return an array of the names" do
|
54
|
+
subject.short.should == ["files","one.txt"]
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe Raval::ListFormatter, "#detailed" do
|
60
|
+
context "with a directory and a file" do
|
61
|
+
let!(:files) { [a_valid_directory, a_valid_file] }
|
62
|
+
subject { Raval::ListFormatter.new(files)}
|
63
|
+
|
64
|
+
it "should return an array of the names" do
|
65
|
+
subject.detailed.should == [
|
66
|
+
"dr--r--r-- 1 auser agroup 0 Oct 10 10:10 files",
|
67
|
+
"-r--r--r-- 1 auser agroup 1024 Oct 10 10:10 one.txt",
|
68
|
+
]
|
69
|
+
end
|
70
|
+
end
|
71
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
require "rubygems"
|
4
|
+
require "bundler"
|
5
|
+
Bundler.setup
|
6
|
+
|
7
|
+
require 'raval'
|
8
|
+
|
9
|
+
|
10
|
+
# Requires supporting ruby files with custom matchers and macros, etc,
|
11
|
+
# in spec/support/ and its subdirectories.
|
12
|
+
Dir[File.dirname(__FILE__) + "/support/**/*.rb"].each {|f| require f }
|
13
|
+
|
14
|
+
#RSpec.configure do |config|
|
15
|
+
# config.include ReaderSpecHelper
|
16
|
+
#end
|
@@ -0,0 +1,88 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
|
3
|
+
# a super simple driver that is used in our specs
|
4
|
+
|
5
|
+
require 'ostruct'
|
6
|
+
require 'stringio'
|
7
|
+
|
8
|
+
class TestDriver
|
9
|
+
FILE_ONE = "This is the first file available for download.\n\nBy James"
|
10
|
+
FILE_TWO = "This is the file number two.\n\n2009-03-21"
|
11
|
+
|
12
|
+
def change_dir(path)
|
13
|
+
path == "/" || path == "/files"
|
14
|
+
end
|
15
|
+
|
16
|
+
def dir_contents(path)
|
17
|
+
case path
|
18
|
+
when "/" then
|
19
|
+
[ dir_item("files"), file_item("one.txt", FILE_ONE.bytesize) ]
|
20
|
+
when "/files" then
|
21
|
+
[ file_item("two.txt", FILE_TWO.bytesize) ]
|
22
|
+
else
|
23
|
+
[]
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def authenticate(user, pass)
|
28
|
+
user == "test" && pass == "1234"
|
29
|
+
end
|
30
|
+
|
31
|
+
def bytes(path)
|
32
|
+
case path
|
33
|
+
when "/one.txt" then FILE_ONE.bytesize
|
34
|
+
when "/files/two.txt" then FILE_TWO.bytesize
|
35
|
+
else
|
36
|
+
false
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def modified_time(path)
|
41
|
+
case path
|
42
|
+
when "/one.txt" then Time.mktime(2012,10,10,10,10)
|
43
|
+
when "/files/two.txt" then Time.mktime(2012,11,11,11,11)
|
44
|
+
else
|
45
|
+
false
|
46
|
+
end
|
47
|
+
end
|
48
|
+
|
49
|
+
def get_file(path)
|
50
|
+
case path
|
51
|
+
when "/one.txt" then StringIO.new(FILE_ONE)
|
52
|
+
when "/files/two.txt" then StringIO.new(FILE_TWO)
|
53
|
+
else
|
54
|
+
false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def put_file(path, tmp_path)
|
59
|
+
File.size(tmp_path)
|
60
|
+
end
|
61
|
+
|
62
|
+
def delete_file(path)
|
63
|
+
path == "/four.txt"
|
64
|
+
end
|
65
|
+
|
66
|
+
def delete_dir(path)
|
67
|
+
path == "/four"
|
68
|
+
end
|
69
|
+
|
70
|
+
def rename(from, to)
|
71
|
+
from == "/one.txt"
|
72
|
+
end
|
73
|
+
|
74
|
+
def make_dir(path)
|
75
|
+
path == "/four"
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def dir_item(name)
|
81
|
+
OpenStruct.new(:name => name, :directory => true, :size => 0)
|
82
|
+
end
|
83
|
+
|
84
|
+
def file_item(name, bytes)
|
85
|
+
OpenStruct.new(:name => name, :directory => false, :size => bytes)
|
86
|
+
end
|
87
|
+
|
88
|
+
end
|
metadata
ADDED
@@ -0,0 +1,165 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: raval
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- James Healy
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-12-01 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rake
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rdoc
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ! '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ! '>='
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: '0'
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: rspec
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '2.6'
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.6'
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: cane
|
64
|
+
requirement: !ruby/object:Gem::Requirement
|
65
|
+
none: false
|
66
|
+
requirements:
|
67
|
+
- - ~>
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
version: 2.2.3
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
version_requirements: !ruby/object:Gem::Requirement
|
73
|
+
none: false
|
74
|
+
requirements:
|
75
|
+
- - ~>
|
76
|
+
- !ruby/object:Gem::Version
|
77
|
+
version: 2.2.3
|
78
|
+
- !ruby/object:Gem::Dependency
|
79
|
+
name: morecane
|
80
|
+
requirement: !ruby/object:Gem::Requirement
|
81
|
+
none: false
|
82
|
+
requirements:
|
83
|
+
- - ! '>='
|
84
|
+
- !ruby/object:Gem::Version
|
85
|
+
version: '0'
|
86
|
+
type: :development
|
87
|
+
prerelease: false
|
88
|
+
version_requirements: !ruby/object:Gem::Requirement
|
89
|
+
none: false
|
90
|
+
requirements:
|
91
|
+
- - ! '>='
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: celluloid-io
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
110
|
+
description: Build a custom FTP daemon backed by a datastore of your choice
|
111
|
+
email:
|
112
|
+
- jamed@yob.id.au
|
113
|
+
executables: []
|
114
|
+
extensions: []
|
115
|
+
extra_rdoc_files:
|
116
|
+
- README.markdown
|
117
|
+
- MIT-LICENSE
|
118
|
+
files:
|
119
|
+
- examples/fog.rb
|
120
|
+
- examples/fake.rb
|
121
|
+
- lib/raval.rb
|
122
|
+
- lib/raval/app.rb
|
123
|
+
- lib/raval/list_formatter.rb
|
124
|
+
- lib/raval/handler.rb
|
125
|
+
- lib/raval/passive_socket.rb
|
126
|
+
- lib/raval/connection.rb
|
127
|
+
- lib/raval/server.rb
|
128
|
+
- lib/raval/active_socket.rb
|
129
|
+
- spec/handler_spec.rb
|
130
|
+
- spec/list_formatter_spec.rb
|
131
|
+
- spec/support/test_driver.rb
|
132
|
+
- spec/spec_helper.rb
|
133
|
+
- Gemfile
|
134
|
+
- README.markdown
|
135
|
+
- MIT-LICENSE
|
136
|
+
homepage: http://github.com/yob/raval
|
137
|
+
licenses: []
|
138
|
+
post_install_message:
|
139
|
+
rdoc_options:
|
140
|
+
- --title
|
141
|
+
- raval FTPd Documentation
|
142
|
+
- --main
|
143
|
+
- README.markdown
|
144
|
+
- -q
|
145
|
+
require_paths:
|
146
|
+
- lib
|
147
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
148
|
+
none: false
|
149
|
+
requirements:
|
150
|
+
- - ! '>='
|
151
|
+
- !ruby/object:Gem::Version
|
152
|
+
version: 1.9.2
|
153
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
|
+
none: false
|
155
|
+
requirements:
|
156
|
+
- - ! '>='
|
157
|
+
- !ruby/object:Gem::Version
|
158
|
+
version: '0'
|
159
|
+
requirements: []
|
160
|
+
rubyforge_project:
|
161
|
+
rubygems_version: 1.8.23
|
162
|
+
signing_key:
|
163
|
+
specification_version: 3
|
164
|
+
summary: A threaded FTP daemon (ftpd) framework
|
165
|
+
test_files: []
|