vfs 0.3.11 → 0.3.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -67,7 +67,7 @@ module Vfs
67
67
  if block
68
68
  fs.write_file(path, options[:append], &block)
69
69
  else
70
- fs.write_file(path, options[:append]){|writer| writer.call data}
70
+ fs.write_file(path, options[:append]){|writer| writer.write data}
71
71
  end
72
72
  rescue StandardError => error
73
73
  entry = self.entry
@@ -162,7 +162,7 @@ module Vfs
162
162
  end
163
163
 
164
164
  target.write options do |writer|
165
- read(options){|buff| writer.call buff}
165
+ read(options){|buff| writer.write buff}
166
166
  end
167
167
 
168
168
  target
@@ -4,6 +4,16 @@ require 'tempfile'
4
4
  module Vfs
5
5
  module Storages
6
6
  class Local
7
+ class Writer
8
+ def initialize out
9
+ @out = out
10
+ end
11
+
12
+ def write data
13
+ @out.write data
14
+ end
15
+ end
16
+
7
17
  module LocalVfsHelper
8
18
  DEFAULT_BUFFER = 1000 * 1024
9
19
 
@@ -51,9 +61,8 @@ module Vfs
51
61
  raise "can't write, entry #{path} already exist!" if !append and ::File.exist?(path)
52
62
 
53
63
  option = append ? 'a' : 'w'
54
- ::File.open path, option do |os|
55
- writer = -> buff {os.write buff}
56
- block.call writer
64
+ ::File.open path, option do |out|
65
+ block.call Writer.new(out)
57
66
  end
58
67
  end
59
68
 
@@ -36,7 +36,7 @@ shared_examples_for 'vfs storage' do
36
36
  it "file attributes" do
37
37
  @storage.open_fs do |fs|
38
38
  fs.attributes(@remote_file).should == {}
39
- fs.write_file(@remote_file, false){|w| w.call 'something'}
39
+ fs.write_file(@remote_file, false){|w| w.write 'something'}
40
40
  attrs = fs.attributes(@remote_file)
41
41
  fs.attributes(@remote_file).subset(:file, :dir).should == {file: true, dir: false}
42
42
  end
@@ -44,7 +44,7 @@ shared_examples_for 'vfs storage' do
44
44
 
45
45
  it "read, write & append" do
46
46
  @storage.open_fs do |fs|
47
- fs.write_file(@remote_file, false){|w| w.call 'something'}
47
+ fs.write_file(@remote_file, false){|w| w.write 'something'}
48
48
  fs.attributes(@remote_file)[:file].should be_true
49
49
 
50
50
  data = ""
@@ -52,7 +52,7 @@ shared_examples_for 'vfs storage' do
52
52
  data.should == 'something'
53
53
 
54
54
  # append
55
- fs.write_file(@remote_file, true){|w| w.call ' another'}
55
+ fs.write_file(@remote_file, true){|w| w.write ' another'}
56
56
  data = ""
57
57
  fs.read_file(@remote_file){|buff| data << buff}
58
58
  data.should == 'something another'
@@ -61,7 +61,7 @@ shared_examples_for 'vfs storage' do
61
61
 
62
62
  it "delete_file" do
63
63
  @storage.open_fs do |fs|
64
- fs.write_file(@remote_file, false){|w| w.call 'something'}
64
+ fs.write_file(@remote_file, false){|w| w.write 'something'}
65
65
  fs.attributes(@remote_file)[:file].should be_true
66
66
  fs.delete_file(@remote_file)
67
67
  fs.attributes(@remote_file).should == {}
@@ -92,7 +92,7 @@ shared_examples_for 'vfs storage' do
92
92
  @storage.open_fs do |fs|
93
93
  fs.create_dir(@remote_dir)
94
94
  fs.create_dir("#{@remote_dir}/dir")
95
- fs.write_file("#{@remote_dir}/dir/file", false){|w| w.call 'something'}
95
+ fs.write_file("#{@remote_dir}/dir/file", false){|w| w.write 'something'}
96
96
  fs.delete_dir(@remote_dir)
97
97
  fs.attributes(@remote_dir).should == {}
98
98
  end
@@ -106,7 +106,7 @@ shared_examples_for 'vfs storage' do
106
106
 
107
107
  dir, file = "#{@tmp_dir}/dir", "#{@tmp_dir}/file"
108
108
  fs.create_dir(dir)
109
- fs.write_file(file, false){|w| w.call 'something'}
109
+ fs.write_file(file, false){|w| w.write 'something'}
110
110
 
111
111
  list = {}
112
112
  fs.each_entry(@tmp_dir, nil){|path, type| list[path] = type}
data/readme.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # Vfs - Virtual File System
2
2
 
3
3
  Handy and simple abstraction over any storage that can represent concept of File and Directory (or at least part of it).
4
- The Vfs for File System is the same as ActiveRecord is for Relational Databases.
4
+ The Vfs for File System is kinda the same as ActiveRecord is for Relational Databases.
5
5
 
6
6
  Currently, there are following implementations available:
7
7
 
@@ -11,45 +11,53 @@ Currently, there are following implementations available:
11
11
  ## Goals
12
12
 
13
13
  - **handy, simple and clean** API.
14
- - **high performance** - the same as by using low-level storage API, there should be no extra calls **.
15
14
  - same API for different storages (Local FS, SSH, Hadoop, or any other , ...).
16
15
  - should work **simultaneously with different storages**.
17
16
  - small codebase, easy to extend by others.
18
17
  - simple storage-driver implementation, easy add new storage types (Hadoop DFS, LDAP, Document Oriented DB, In-Memory, ...).
19
18
 
20
- ** all methods should have the same performance as native system calls, except for :move and :rename. Right now they are implemented
21
- ASAP by using copy+destroy approach, will be fixed as soon as I'll have free time to do it.
19
+ **Performance**:
20
+
21
+ - sometimes there's extra call to check if file or dir exist before overriding it
22
+ - copy: it doesn't use FileUtils.cp_r, it walks on the directory tree and copy each entry individually, so it's probably a little slover.
23
+ - right now :move and :rename implemented ASAP by copy & destroy, will be fixed as soon as I'll have time to do it.
22
24
 
23
25
  ## Installation
24
26
 
25
- ```bash
27
+ ``` bash
26
28
  $ gem install vfs
27
29
  $ gem install vos
28
30
  ```
29
31
 
30
32
  ## Code samples:
31
33
 
32
- ```ruby
34
+ ``` ruby
33
35
  gem 'vfs' # Virtual File System
34
36
  require 'vfs'
35
37
 
36
38
  gem 'vos' # Virtual Operating System
37
39
  require 'vos'
38
-
40
+ ```
39
41
 
40
42
  # Connections, let's deploy our 'cool_app' project from our local box to remote server
43
+
44
+ ``` ruby
41
45
  server = Box.new('cool_app.com') # it will use id_rsa, or You can add {user: 'me', password: 'secret'}
42
46
  me = '~'.to_dir # handy shortcut for local FS
43
47
 
44
48
  deploy_dir = server['apps/cool_app']
45
49
  projects = me['projects']
46
-
50
+ ```
47
51
 
48
52
  # Working with dirs, copying dir from any source to any destination (local/remote/custom_storage_type)
49
- projects['cool_app'].copy_to deploy_dir
50
53
 
54
+ ``` ruby
55
+ projects['cool_app'].copy_to deploy_dir
56
+ ```
51
57
 
52
58
  # Working with files
59
+
60
+ ``` ruby
53
61
  dbc = deploy_dir.file('config/database.yml') # <= the 'config' dir not exist yet
54
62
  dbc.write("user: root\npassword: secret") # <= now the 'database.yml' and parent 'config' has been created
55
63
  dbc.content =~ /database/ # => false, we forgot to add the database
@@ -61,9 +69,9 @@ end
61
69
 
62
70
  projects['cool_app/config/database.yml']. # or just overwrite it with our local dev version
63
71
  copy_to! dbc
72
+ ```
64
73
 
65
- # there are also streaming support (read/write/append) with &block, please go to specs for details
66
-
74
+ There are also streaming support (read/write/append) with &block, please go to specs for details
67
75
 
68
76
  # Checks
69
77
  deploy_dir['config'].exist? # => true
data/spec/file_spec.rb CHANGED
@@ -90,7 +90,7 @@ describe 'File' do
90
90
  @path.read.should == 'something'
91
91
 
92
92
  @path.write! do |writer|
93
- writer.call 'another'
93
+ writer.write 'another'
94
94
  end
95
95
  @path.read.should == 'another'
96
96
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: vfs
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.11
4
+ version: 0.3.12
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: