vfs 0.0.4 → 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. data/Rakefile +2 -2
  2. data/lib/vfs.rb +18 -0
  3. data/lib/vfs/entries/dir.rb +272 -0
  4. data/lib/vfs/entries/entry.rb +127 -0
  5. data/lib/vfs/entries/file.rb +185 -0
  6. data/lib/vfs/entries/universal_entry.rb +24 -0
  7. data/lib/vfs/entry_proxy.rb +38 -0
  8. data/lib/vfs/error.rb +4 -0
  9. data/lib/vfs/integration/string.rb +19 -0
  10. data/lib/vfs/path.rb +125 -0
  11. data/lib/vfs/storages/hash_fs.rb +194 -0
  12. data/lib/vfs/storages/local.rb +138 -0
  13. data/lib/vfs/storages/specification.rb +127 -0
  14. data/lib/vfs/support.rb +2 -0
  15. data/readme.md +110 -14
  16. data/spec/container_spec.rb +31 -0
  17. data/spec/dir_spec.rb +224 -0
  18. data/spec/entry_spec.rb +24 -0
  19. data/spec/file_spec.rb +189 -0
  20. data/spec/path_spec.rb +121 -0
  21. data/spec/spec_helper.rb +2 -9
  22. data/spec/storages/hash_fs_spec.rb +10 -0
  23. data/spec/storages/local_spec.rb +10 -0
  24. data/spec/universal_entry_spec.rb +42 -0
  25. metadata +25 -23
  26. data/lib/old/ssh.rb +0 -11
  27. data/lib/rsh.rb +0 -19
  28. data/lib/rsh/box.rb +0 -182
  29. data/lib/rsh/box/marks.rb +0 -29
  30. data/lib/rsh/drivers/abstract.rb +0 -15
  31. data/lib/rsh/drivers/local.rb +0 -48
  32. data/lib/rsh/drivers/ssh.rb +0 -147
  33. data/lib/rsh/gems.rb +0 -2
  34. data/lib/rsh/support.rb +0 -30
  35. data/spec/abstract_driver.rb +0 -82
  36. data/spec/abstract_driver/dir/dir2/file +0 -0
  37. data/spec/abstract_driver/local_file +0 -1
  38. data/spec/box_spec.rb +0 -109
  39. data/spec/box_spec/dir/dir2/file +0 -0
  40. data/spec/box_spec/local_file +0 -1
  41. data/spec/config.example.yml +0 -4
  42. data/spec/config.yml +0 -5
  43. data/spec/local_driver_spec.rb +0 -9
  44. data/spec/ssh_driver_spec.rb +0 -15
@@ -0,0 +1,24 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'Entry' do
4
+ before :each do
5
+ @fs = '/'.to_entry_on(Vfs::Storages::HashFs.new)
6
+ @path = @fs['/a/b/c']
7
+ end
8
+
9
+ it "name" do
10
+ @path.name.should == 'c'
11
+ end
12
+
13
+ it 'tmp' do
14
+ tmp = @fs.tmp
15
+ tmp.should be_dir
16
+
17
+ tmp = nil
18
+ @fs.tmp do |path|
19
+ tmp = path
20
+ tmp.should be_dir
21
+ end
22
+ tmp.should_not exist
23
+ end
24
+ end
data/spec/file_spec.rb ADDED
@@ -0,0 +1,189 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'File' do
4
+ before :each do
5
+ @fs = '/'.to_entry_on(Vfs::Storages::HashFs.new)
6
+ @path = @fs['/a/b/c']
7
+ end
8
+
9
+ describe 'existence' do
10
+ it "should check only files" do
11
+ @path.should_not exist
12
+ @path.dir.create
13
+ @path.should be_dir
14
+ @path.file.should_not exist
15
+ @path.file.create!
16
+ @path.should be_file
17
+ @path.file.should exist
18
+ end
19
+ end
20
+
21
+ describe 'read' do
22
+ it 'should raise error if not exist' do
23
+ -> {@path.read}.should raise_error(Vfs::Error, /not exist/)
24
+ -> {@path.read{|buff|}}.should raise_error(Vfs::Error, /not exist/)
25
+ end
26
+
27
+ it 'should not raise error in silent mode' do
28
+ @path.read(bang: false).should == ''
29
+ data = ""; @path.read(bang: false){|buff| data << buff}; data.should == ''
30
+ end
31
+
32
+ it "reading" do
33
+ @path.write('something')
34
+
35
+ @path.read.should == 'something'
36
+ @path.read(bang: false).should == 'something'
37
+ data = ""; @path.read{|buff| data << buff}; data.should == 'something'
38
+ end
39
+
40
+ it 'content' do
41
+ @path.write('something')
42
+ @path.content.should == 'something'
43
+ end
44
+ end
45
+
46
+ describe 'creation' do
47
+ it 'create' do
48
+ file = @path.file
49
+
50
+ file.should_receive(:write).with('', {})
51
+ file.create
52
+
53
+ file.should_receive(:write).with('', override: true)
54
+ file.create!
55
+ end
56
+
57
+ it 'should be chainable' do
58
+ @path.file.create.should == @path
59
+ @path.file.create!.should == @path
60
+ end
61
+ end
62
+
63
+ describe 'write' do
64
+ it 'should create parent dirs if not exists' do
65
+ @path.parent.should_not exist
66
+ @path.write 'something'
67
+ @path.read.should == 'something'
68
+ end
69
+
70
+ it 'should override existing file if override specified' do
71
+ @path.write 'something'
72
+ @path.should be_file
73
+ -> {@path.write 'another'}.should raise_error(Vfs::Error, /exist/)
74
+ @path.write! 'another'
75
+ @path.read.should == 'another'
76
+ end
77
+
78
+ it 'should override existing dir if override specified' do
79
+ @path.dir.create
80
+ @path.should be_dir
81
+ -> {@path.write 'another'}.should raise_error(Vfs::Error, /exist/)
82
+ @path.write! 'another'
83
+ @path.read.should == 'another'
84
+ end
85
+
86
+ it 'writing' do
87
+ @path.write 'something'
88
+ @path.read.should == 'something'
89
+
90
+ @path.write! do |writer|
91
+ writer.call 'another'
92
+ end
93
+ @path.read.should == 'another'
94
+ end
95
+
96
+ it 'append' do
97
+ file = @path.file
98
+ file.should_receive(:write).with('something', append: true)
99
+ file.append 'something'
100
+ end
101
+ end
102
+
103
+ it 'update' do
104
+ @path.write 'something'
105
+ @path.update do |data|
106
+ data.should == 'something'
107
+ 'another'
108
+ end
109
+ @path.read.should == 'another'
110
+ end
111
+
112
+ describe 'copying' do
113
+ before :each do
114
+ @from = @path.file
115
+ @from.write('something')
116
+ end
117
+
118
+ it 'should not copy to itself' do
119
+ -> {@from.copy_to @from}.should raise_error(Vfs::Error, /itself/)
120
+ end
121
+
122
+ def check_copy_for to
123
+ target = @from.copy_to to
124
+ target.read.should == 'something'
125
+ target.should == to
126
+
127
+ @from.write! 'another'
128
+ -> {@from.copy_to to}.should raise_error(Vfs::Error, /exist/)
129
+ target = @from.copy_to! to
130
+ target.read.should == 'another'
131
+ target.should == to
132
+ end
133
+
134
+ it 'should copy to file (and overwrite if forced)' do
135
+ check_copy_for @fs.file('to')
136
+ end
137
+
138
+ it 'should copy to dir (and overwrite if forced)' do
139
+ check_copy_for @fs.dir("to")
140
+ end
141
+
142
+ it 'should copy to UniversalEntry (and overwrite if forced)' do
143
+ check_copy_for @fs.entry('to')
144
+ end
145
+
146
+ it 'should be chainable' do
147
+ to = @fs['to']
148
+ @from.copy_to(to).should == to
149
+ @from.copy_to!(to).should == to
150
+ end
151
+ end
152
+
153
+ describe 'moving' do
154
+ it 'move_to' do
155
+ from, to = @path.file('from'), @path.file('to')
156
+ from.should_receive(:copy_to).with(to, {})
157
+ from.should_receive(:destroy).with({})
158
+ from.move_to to
159
+
160
+ from.should_receive(:move_to).with(to, override: true)
161
+ from.move_to! to
162
+ end
163
+
164
+ it 'should be chainable' do
165
+ from, to = @path.file('from').create, @path.file('to')
166
+ from.move_to(to).should == to
167
+ from.create
168
+ from.move_to!(to).should == to
169
+ end
170
+ end
171
+
172
+ describe 'destroying' do
173
+ it "should raise error if it's trying to destroy a dir (unless force specified)" do
174
+ @path.dir.create
175
+ -> {@path.file.destroy}.should raise_error(Vfs::Error, /can't destroy Dir/)
176
+ @path.file.destroy!
177
+ @path.entry.should_not exist
178
+ end
179
+
180
+ it "shouldn't raise if file not exist" do
181
+ @path.file.destroy
182
+ end
183
+
184
+ it 'should be chainable' do
185
+ @path.file.destroy.should == @path
186
+ @path.file.destroy!.should == @path
187
+ end
188
+ end
189
+ end
data/spec/path_spec.rb ADDED
@@ -0,0 +1,121 @@
1
+ require 'spec_helper'
2
+
3
+ describe "Path" do
4
+ before(:all){Path = Vfs::Path}
5
+ after(:all){remove_constants :Path}
6
+
7
+ it 'validations' do
8
+ %w(
9
+ /
10
+ /a
11
+ /a/b/c
12
+ /a/../c
13
+ /a/...
14
+ ~/a
15
+ ./a
16
+ ).each{|path| Path.should be_valid(path)}
17
+
18
+ special = ['']
19
+ (%w(
20
+ /a/~/c
21
+ /a/./c
22
+ /a/
23
+ ~/
24
+ ./
25
+ ) + special).each{|path| Path.should_not be_valid(path)}
26
+ end
27
+
28
+ # it 'tmp', focus: true do
29
+ # (Path.new('.') + '..').should == './..'
30
+ # end
31
+
32
+ it 'normalize' do
33
+ special = ['/a/../..', nil]
34
+ (%w(
35
+ /a /a
36
+ ~/a ~/a
37
+ ./a ./a
38
+ /a/../c /c
39
+ / /
40
+ ~ ~
41
+ . .
42
+ ) + special).each_slice(2) do |path, normalized_path|
43
+ Path.normalize(path).should == normalized_path
44
+ end
45
+ end
46
+
47
+ it "+" do
48
+ special = [
49
+ '/a', '../..', nil,
50
+ '/', '..', nil,
51
+ '.', '..', './..',
52
+ ]
53
+ (%w(
54
+ / /a /a
55
+ / ~/a ~/a
56
+ / ./a ./a
57
+ /a b/c /a/b/c
58
+ /a/b/c ../d /a/b/d
59
+ ) + special).each_slice(3) do |base, path, sum|
60
+ (Path.new(base) + path).should == sum
61
+ end
62
+ end
63
+
64
+ it 'parent' do
65
+ special = [
66
+ '/', nil,
67
+ '~', nil,
68
+ '.', './..'
69
+ ]
70
+ (%w(
71
+ /a/b/c /a/b
72
+ ) + special).each_slice(2) do |path, parent|
73
+ Path.new(path).parent.should == parent
74
+ end
75
+ end
76
+
77
+ it "should raise error if current dir outside of root" do
78
+ -> {Path.new('/a/../..')}.should raise_error(/outside.*root/)
79
+ end
80
+
81
+ it "should guess if current dir is a dir" do
82
+ [
83
+ '/a', false,
84
+ '/', true,
85
+ '~', true,
86
+ '.', true,
87
+ '/a/..', true,
88
+ '/a/../b', false,
89
+ ].each_slice 2 do |path, result|
90
+ Path.new(path).probably_dir?.should == result
91
+ end
92
+
93
+ path = Path.new('/a/b/c')
94
+ [
95
+ path, false,
96
+ (path + '..'), true,
97
+ path.parent, true,
98
+
99
+ (path + '/'), true,
100
+ (path + '/a'), false,
101
+ ].each_slice 2 do |path, result|
102
+ path.probably_dir?.should == result
103
+ end
104
+ end
105
+
106
+ it 'name' do
107
+ %w(
108
+ /a a
109
+ /a/b/c c
110
+ / /
111
+ ~ ~
112
+ . .
113
+ ).each_slice 2 do |path, name|
114
+ Path.new(path).name.should == name
115
+ end
116
+ end
117
+
118
+ it 'to_s' do
119
+ Path.new.to_s.class.should == String
120
+ end
121
+ end
data/spec/spec_helper.rb CHANGED
@@ -1,11 +1,4 @@
1
1
  require 'rspec_ext'
2
- require 'rsh'
2
+ require 'ruby_ext'
3
3
 
4
- rspec do
5
- def config
6
- dir = File.dirname __FILE__
7
- config_file_path = "#{dir}/config.yml"
8
- raise "no config '#{config_file_path}'!" unless File.exist? config_file_path
9
- @config ||= YAML.load_file config_file_path
10
- end
11
- end
4
+ require 'vfs'
@@ -0,0 +1,10 @@
1
+ require 'vfs/storages/hash_fs'
2
+ require 'vfs/storages/specification'
3
+
4
+ describe Vfs::Storages::HashFs do
5
+ it_should_behave_like "vfs storage"
6
+
7
+ before :each do
8
+ @storage = Vfs::Storages::HashFs.new
9
+ end
10
+ end
@@ -0,0 +1,10 @@
1
+ require 'vfs/storages/local'
2
+ require 'vfs/storages/specification'
3
+
4
+ describe Vfs::Storages::Local do
5
+ it_should_behave_like "vfs storage"
6
+
7
+ before :each do
8
+ @storage = Vfs::Storages::Local.new
9
+ end
10
+ end
@@ -0,0 +1,42 @@
1
+ require 'spec_helper'
2
+
3
+ describe 'UniversalEntry' do
4
+ before :each do
5
+ @fs = '/'.to_entry_on(Vfs::Storages::HashFs.new)
6
+ @path = @fs['/a/b/c']
7
+ end
8
+
9
+ describe 'existence' do
10
+ it "should check both files and dirs" do
11
+ @path.should_not exist
12
+ @path.dir.create
13
+ @path.should be_dir
14
+ @path.should exist
15
+
16
+ @path.file.create!
17
+ @path.should be_file
18
+ @path.should exist
19
+ end
20
+ end
21
+
22
+ describe 'destroying' do
23
+ it "should destroy both files and dirs" do
24
+ @path.dir.create
25
+ @path.should be_dir
26
+ @path.destroy
27
+ @path.should_not exist
28
+
29
+ @path.file.create
30
+ @path.should be_file
31
+ @path.destroy
32
+ @path.should_not exist
33
+ end
34
+
35
+ it "shouldn't raise if file not exist" do
36
+ @path.destroy
37
+ end
38
+ end
39
+
40
+ describe 'copy_to'
41
+ describe 'move_to'
42
+ end
metadata CHANGED
@@ -4,9 +4,9 @@ version: !ruby/object:Gem::Version
4
4
  prerelease: false
5
5
  segments:
6
6
  - 0
7
+ - 1
7
8
  - 0
8
- - 4
9
- version: 0.0.4
9
+ version: 0.1.0
10
10
  platform: ruby
11
11
  authors:
12
12
  - Alexey Petrushin
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-02-02 00:00:00 +03:00
17
+ date: 2011-02-08 00:00:00 +03:00
18
18
  default_executable:
19
19
  dependencies: []
20
20
 
@@ -29,26 +29,28 @@ extra_rdoc_files: []
29
29
  files:
30
30
  - Rakefile
31
31
  - readme.md
32
- - lib/old/ssh.rb
33
- - lib/rsh/box/marks.rb
34
- - lib/rsh/box.rb
35
- - lib/rsh/drivers/abstract.rb
36
- - lib/rsh/drivers/local.rb
37
- - lib/rsh/drivers/ssh.rb
38
- - lib/rsh/gems.rb
39
- - lib/rsh/support.rb
40
- - lib/rsh.rb
41
- - spec/abstract_driver/dir/dir2/file
42
- - spec/abstract_driver/local_file
43
- - spec/abstract_driver.rb
44
- - spec/box_spec/dir/dir2/file
45
- - spec/box_spec/local_file
46
- - spec/box_spec.rb
47
- - spec/config.example.yml
48
- - spec/config.yml
49
- - spec/local_driver_spec.rb
32
+ - lib/vfs/entries/dir.rb
33
+ - lib/vfs/entries/entry.rb
34
+ - lib/vfs/entries/file.rb
35
+ - lib/vfs/entries/universal_entry.rb
36
+ - lib/vfs/entry_proxy.rb
37
+ - lib/vfs/error.rb
38
+ - lib/vfs/integration/string.rb
39
+ - lib/vfs/path.rb
40
+ - lib/vfs/storages/hash_fs.rb
41
+ - lib/vfs/storages/local.rb
42
+ - lib/vfs/storages/specification.rb
43
+ - lib/vfs/support.rb
44
+ - lib/vfs.rb
45
+ - spec/container_spec.rb
46
+ - spec/dir_spec.rb
47
+ - spec/entry_spec.rb
48
+ - spec/file_spec.rb
49
+ - spec/path_spec.rb
50
50
  - spec/spec_helper.rb
51
- - spec/ssh_driver_spec.rb
51
+ - spec/storages/hash_fs_spec.rb
52
+ - spec/storages/local_spec.rb
53
+ - spec/universal_entry_spec.rb
52
54
  has_rdoc: true
53
55
  homepage: http://github.com/alexeypetrushin/vfs
54
56
  licenses: []
@@ -80,6 +82,6 @@ rubyforge_project:
80
82
  rubygems_version: 1.3.7
81
83
  signing_key:
82
84
  specification_version: 3
83
- summary: Tiny wrapper over Net::SSH/SFTP + small rake addon for cluster configuration management
85
+ summary: Virtual File System
84
86
  test_files: []
85
87