vfs 0.4.8 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 912da8917a494c212593b79a0b180ab7938df9e1
4
+ data.tar.gz: 1bf02fc5cb03e6ce27320956a80ac035cfe07d34
5
+ SHA512:
6
+ metadata.gz: e24ebb55a45cc9c031231c2e0b792776b206431d7760906bca065227acc72469c444a84757cad7ce60125d8e0bf9b517636134f37f03bfbdaa78fe8f560821fa
7
+ data.tar.gz: 45d5f24d6d93992d445409107dd858738c1809a09d6283ef14ac393a8df25f16ebcf9756127c5d14744ed820f6f41e80d813f8c4d166f3ddc938e1fced5e34ae
@@ -30,9 +30,8 @@ module Vfs
30
30
  @buffer || DEFAULT_BUFFER
31
31
  end
32
32
 
33
- #
34
- # Attributes
35
- #
33
+ # Attributes.
34
+
36
35
  def attributes path
37
36
  path = with_root path
38
37
 
@@ -53,14 +52,12 @@ module Vfs
53
52
  end
54
53
 
55
54
  def set_attributes path, attrs
56
- # TODO2 set attributes
55
+ # TODO2 set attributes.
57
56
  not_implemented
58
57
  end
59
58
 
59
+ # File.
60
60
 
61
- #
62
- # File
63
- #
64
61
  def read_file path, &block
65
62
  path = with_root path
66
63
  ::File.open path, 'r' do |is|
@@ -88,10 +85,7 @@ module Vfs
88
85
  # FileUtils.mv from, to
89
86
  # end
90
87
 
91
-
92
- #
93
- # Dir
94
- #
88
+ # Dir.
95
89
  def create_dir path
96
90
  path = with_root path
97
91
  ::Dir.mkdir path
@@ -110,21 +104,11 @@ module Vfs
110
104
  ::Dir["#{path_with_trailing_slash}#{query}"].each do |absolute_path|
111
105
  name = absolute_path.sub path_with_trailing_slash, ''
112
106
  block.call name, ->{::File.directory?(absolute_path) ? :dir : :file}
113
- # if ::File.directory? absolute_path
114
- # block.call relative_path, :dir
115
- # else
116
- # block.call relative_path, :file
117
- # end
118
107
  end
119
108
  else
120
109
  ::Dir.foreach path do |name|
121
110
  next if name == '.' or name == '..'
122
111
  block.call name, ->{::File.directory?("#{path}/#{name}") ? :dir : :file}
123
- # if ::File.directory? "#{path}/#{relative_name}"
124
- # block.call relative_name, :dir
125
- # else
126
- # block.call relative_name, :file
127
- # end
128
112
  end
129
113
  end
130
114
  end
@@ -144,14 +128,12 @@ module Vfs
144
128
  # end
145
129
  # end
146
130
 
147
- #
148
- # Other
149
- #
131
+ # Other.
132
+
150
133
  def local?; true end
151
134
 
152
135
  def tmp &block
153
136
  path = "/tmp/#{rand(10**6)}"
154
- # tmp_dir = "#{::Dir.tmpdir}/#{rand(10**6)}"
155
137
  if block
156
138
  begin
157
139
  ::FileUtils.mkdir_p with_root(path)
@@ -1,6 +1,3 @@
1
- require 'rspec_ext'
2
- require 'ruby_ext'
3
-
4
1
  shared_examples_for 'vfs driver basic' do
5
2
  it 'should respond to :local?' do
6
3
  @driver.should respond_to(:local?)
@@ -35,16 +32,16 @@ shared_examples_for 'vfs driver files' do
35
32
  end
36
33
 
37
34
  it "read, write, append" do
38
- # write
35
+ # Write.
39
36
  @driver.write_file('/file', false){|w| w.write 'something'}
40
37
  @driver.attributes('/file')[:file].should == true
41
38
 
42
- # read
39
+ # Read.
43
40
  data = ""
44
41
  @driver.read_file('/file'){|buff| data << buff}
45
42
  data.should == 'something'
46
43
 
47
- # append
44
+ # Append.
48
45
  @driver.write_file('/file', true){|w| w.write ' another'}
49
46
  data = ""
50
47
  @driver.read_file('/file'){|buff| data << buff}
@@ -1,8 +1,7 @@
1
1
  module Vfs
2
2
  class Dir < Entry
3
- #
4
- # Container
5
- #
3
+
4
+ # Container.
6
5
  def [] path
7
6
  path = path.to_s
8
7
  if path =~ /.+[\/]$/
@@ -17,15 +16,11 @@ module Vfs
17
16
  alias_method :/, :[]
18
17
 
19
18
 
20
- #
21
- # Attributes
22
- #
19
+ # Attributes.
23
20
  alias_method :exist?, :dir?
24
21
 
22
+ # CRUD.
25
23
 
26
- #
27
- # CRUD
28
- #
29
24
  def create options = {}
30
25
  driver.open do
31
26
  try = 0
@@ -36,7 +31,7 @@ module Vfs
36
31
  entry = self.entry
37
32
  attrs = entry.get
38
33
  if attrs and attrs[:file] #entry.exist?
39
- entry.destroy
34
+ entry.delete
40
35
  elsif attrs and attrs[:dir]
41
36
  # dir already exist, no need to recreate it
42
37
  return self
@@ -56,14 +51,12 @@ module Vfs
56
51
  self
57
52
  end
58
53
 
59
- def destroy options = {}
60
- destroy_entry :dir, :file
54
+ def delete options = {}
55
+ delete_entry :dir, :file
61
56
  end
62
57
 
58
+ # Content.
63
59
 
64
- #
65
- # Content
66
- #
67
60
  def entries *args, &block
68
61
  raise "invalid arguments #{args.inspect}!" if args.size > 2
69
62
  options = args.last.is_a?(Hash) ? args.pop : {}
@@ -75,9 +68,9 @@ module Vfs
75
68
  driver.open do
76
69
  begin
77
70
  list = []
78
- # query option is optional and supported only for some drivers (local driver for example)
71
+ # Query option is optional and supported only for some drivers (local driver for example).
79
72
  driver.each_entry path, query do |name, type|
80
- # for performance reasons some drivers may return the type of entry as
73
+ # For performance reasons some drivers may return the type of entry as
81
74
  # optionally evaluated callback.
82
75
  type = type.call if (filter or type_required) and type.is_a?(Proc)
83
76
 
@@ -98,10 +91,10 @@ module Vfs
98
91
  if attrs and attrs[:file]
99
92
  raise Error, "can't query entries on File ('#{self}')!"
100
93
  elsif attrs and attrs[:dir]
101
- # some unknown error
94
+ # Some unknown error.
102
95
  raise error
103
96
  else
104
- # TODO2 remove :bang
97
+ # TODO2 remove :bang.
105
98
  raise Error, "'#{self}' not exist!" if options[:bang]
106
99
  []
107
100
  end
@@ -138,10 +131,8 @@ module Vfs
138
131
  end
139
132
  end
140
133
 
134
+ # Transfers.
141
135
 
142
- #
143
- # Transfers
144
- #
145
136
  def copy_to to, options = {}
146
137
  options[:bang] = true unless options.include? :bang
147
138
 
@@ -151,10 +142,9 @@ module Vfs
151
142
  target = if to.is_a? File
152
143
  to.dir
153
144
  elsif to.is_a? Dir
154
- to.dir #(name)
145
+ to.dir
155
146
  elsif to.is_a? UniversalEntry
156
- # raise "can't copy Dir to File ('#{self}')!" if to.file? and !options[:override]
157
- to.dir #.create
147
+ to.dir
158
148
  else
159
149
  raise "can't copy to unknown Entry!"
160
150
  end
@@ -167,14 +157,10 @@ module Vfs
167
157
 
168
158
  def move_to to, options = {}
169
159
  copy_to to, options
170
- destroy options
160
+ delete options
171
161
  to
172
162
  end
173
163
 
174
- # class << self
175
- # attr_accessor :dont_use_efficient_dir_copy
176
- # end
177
-
178
164
  protected
179
165
  def unefficient_dir_copy to, options
180
166
  to.create options
@@ -189,7 +175,6 @@ module Vfs
189
175
  end
190
176
  end
191
177
 
192
-
193
178
  # def efficient_dir_copy to, options
194
179
  # return false if self.class.dont_use_efficient_dir_copy
195
180
  #
@@ -215,14 +200,14 @@ module Vfs
215
200
  # attrs = to.get
216
201
  # if attrs and attrs[:file]
217
202
  # if options[:override]
218
- # to.destroy
203
+ # to.delete
219
204
  # else
220
205
  # raise Vfs::Error, "entry #{to} already exist!"
221
206
  # end
222
207
  # elsif attrs and attrs[:dir]
223
208
  # unknown_errors += 1
224
209
  # # if options[:override]
225
- # # to.destroy
210
+ # # to.delete
226
211
  # # else
227
212
  # # dir_already_exist = true
228
213
  # # # raise Vfs::Error, "entry #{to} already exist!"
@@ -15,17 +15,13 @@ module Vfs
15
15
  raise "driver not defined!" unless self.driver
16
16
  end
17
17
 
18
- #
19
- # Navigation
20
- #
18
+ # Navigation.
21
19
  def parent
22
20
  Dir.new(driver, path_cache.parent)
23
21
  end
24
22
 
23
+ # Transformations.
25
24
 
26
- #
27
- # Transformations
28
- #
29
25
  def dir path = nil
30
26
  if path
31
27
  new_path = path_cache + path
@@ -58,10 +54,8 @@ module Vfs
58
54
  end
59
55
  alias_method :to_entry, :entry
60
56
 
57
+ # Attributes.
61
58
 
62
- #
63
- # Attributes
64
- #
65
59
  def get attr_name = nil
66
60
  attrs = driver.open{driver.attributes(path)}
67
61
  (attr_name and attrs) ? attrs[attr_name] : attrs
@@ -77,10 +71,8 @@ module Vfs
77
71
  def created_at; get :created_at end
78
72
  def updated_at; get :updated_at end
79
73
 
74
+ # Miscellaneous.
80
75
 
81
- #
82
- # Miscellaneous
83
- #
84
76
  def name
85
77
  path_cache.name
86
78
  end
@@ -101,10 +93,8 @@ module Vfs
101
93
  driver.local?
102
94
  end
103
95
 
96
+ # Utils.
104
97
 
105
- #
106
- # Utils
107
- #
108
98
  def inspect
109
99
  "#{driver}#{':' unless driver.to_s.empty?}#{path}"
110
100
  end
@@ -124,13 +114,11 @@ module Vfs
124
114
  driver.eql?(other.driver) and path.eql?(other.path)
125
115
  end
126
116
 
127
- def delete *args
128
- raise "use :destroy!"
129
- end
130
- alias_method :remove, :delete
117
+ def destroy *args; delete *args end
118
+ def remove *args; delete *args end
131
119
 
132
120
  protected
133
- def destroy_entry first = :file, second = :dir
121
+ def delete_entry first = :file, second = :dir
134
122
  driver.open do
135
123
  begin
136
124
  driver.send :"delete_#{first}", path
@@ -142,7 +130,7 @@ module Vfs
142
130
  elsif attrs and attrs[second]
143
131
  driver.send :"delete_#{second}", path
144
132
  else
145
- # do nothing, entry already not exist
133
+ # Do nothing, entry already not exist.
146
134
  end
147
135
  end
148
136
  end
@@ -1,14 +1,10 @@
1
1
  module Vfs
2
2
  class File < Entry
3
- #
4
- # Attributes
5
- #
3
+ # Attributes.
6
4
  alias_method :exist?, :file?
7
5
 
6
+ # CRUD.
8
7
 
9
- #
10
- # CRUD
11
- #
12
8
  def read options = {}, &block
13
9
  options[:bang] = true unless options.include? :bang
14
10
  driver.open do
@@ -70,7 +66,7 @@ module Vfs
70
66
  rescue StandardError => error
71
67
  parent = self.parent
72
68
  if entry.exist?
73
- entry.destroy
69
+ entry.delete
74
70
  elsif !parent.exist?
75
71
  parent.create(options)
76
72
  else
@@ -95,14 +91,12 @@ module Vfs
95
91
  write block.call(data), options
96
92
  end
97
93
 
98
- def destroy
99
- destroy_entry
94
+ def delete
95
+ delete_entry
100
96
  end
101
97
 
98
+ # Transfers.
102
99
 
103
- #
104
- # Transfers
105
- #
106
100
  def copy_to to, options = {}
107
101
  raise Error, "you can't copy to itself" if self == to
108
102
 
@@ -125,14 +119,12 @@ module Vfs
125
119
 
126
120
  def move_to to
127
121
  copy_to to
128
- destroy
122
+ delete
129
123
  to
130
124
  end
131
125
 
126
+ # Extra Stuff.
132
127
 
133
- #
134
- # Extra Stuff
135
- #
136
128
  def render *args
137
129
  require 'tilt'
138
130
 
@@ -1,24 +1,20 @@
1
1
  module Vfs
2
2
  class UniversalEntry < Entry
3
- #
4
- # Attributes
5
- #
3
+ # Attributes.
4
+
6
5
  def exist?
7
6
  !!get
8
7
  end
9
8
 
10
-
11
9
  def copy_to to, options = {}
12
10
  from = file? ? to_file : to_dir
13
11
  from.copy_to to, options
14
12
  end
15
13
 
14
+ # CRUD.
16
15
 
17
- #
18
- # CRUD
19
- #
20
- def destroy
21
- destroy_entry
16
+ def delete
17
+ delete_entry
22
18
  end
23
19
  end
24
20
  end
@@ -1,6 +1,4 @@
1
- #
2
- # It allows dynamically (magically) switching between UniversalEntry/Dir/File
3
- #
1
+ # It allows dynamically (magically) switching between UniversalEntry/Dir/File.
4
2
  module Vfs
5
3
  class EntryProxy < BasicObject
6
4
  attr_reader :_target
metadata CHANGED
@@ -1,15 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vfs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.8
5
- prerelease:
4
+ version: 0.5.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - Alexey Petrushin
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2011-10-27 00:00:00.000000000Z
11
+ date: 2013-05-05 00:00:00.000000000 Z
13
12
  dependencies: []
14
13
  description:
15
14
  email:
@@ -17,8 +16,6 @@ executables: []
17
16
  extensions: []
18
17
  extra_rdoc_files: []
19
18
  files:
20
- - Rakefile
21
- - readme.md
22
19
  - lib/vfs/drivers/local.rb
23
20
  - lib/vfs/drivers/specification.rb
24
21
  - lib/vfs/entries/dir.rb
@@ -31,39 +28,28 @@ files:
31
28
  - lib/vfs/path.rb
32
29
  - lib/vfs/vfs.rb
33
30
  - lib/vfs.rb
34
- - spec/container_spec.rb
35
- - spec/dir_spec.rb
36
- - spec/entry_spec.rb
37
- - spec/file_spec.rb
38
- - spec/misc_spec.rb
39
- - spec/path_spec.rb
40
- - spec/spec_helper.rb
41
- - spec/storages/local_spec/emptygit
42
- - spec/storages/local_spec.rb
43
- - spec/universal_entry_spec.rb
44
- homepage: http://alexeypetrushin.github.com/vfs
31
+ homepage: http://alexeypetrushin.github.io/vfs
45
32
  licenses: []
33
+ metadata: {}
46
34
  post_install_message:
47
35
  rdoc_options: []
48
36
  require_paths:
49
37
  - lib
50
38
  required_ruby_version: !ruby/object:Gem::Requirement
51
- none: false
52
39
  requirements:
53
40
  - - ! '>='
54
41
  - !ruby/object:Gem::Version
55
42
  version: '0'
56
43
  required_rubygems_version: !ruby/object:Gem::Requirement
57
- none: false
58
44
  requirements:
59
45
  - - ! '>='
60
46
  - !ruby/object:Gem::Version
61
47
  version: '0'
62
48
  requirements: []
63
49
  rubyforge_project:
64
- rubygems_version: 1.8.6
50
+ rubygems_version: 2.0.3
65
51
  signing_key:
66
- specification_version: 3
52
+ specification_version: 4
67
53
  summary: Virtual File System - simple and unified API over different storages (Local,
68
54
  S3, SFTP, ...)
69
55
  test_files: []