vfs 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
data/Rakefile CHANGED
@@ -4,7 +4,7 @@ project(
4
4
  name: "vfs",
5
5
  gem: true,
6
6
  summary: "Virtual File System",
7
- version: '0.4.0',
7
+ # version: '0.4.0',
8
8
 
9
9
  author: "Alexey Petrushin",
10
10
  homepage: "http://github.com/alexeypetrushin/vfs"
@@ -19,7 +19,7 @@ module Vfs
19
19
  # Navigation
20
20
  #
21
21
  def parent
22
- Dir.new(driver, path_cache + '..')
22
+ Dir.new(driver, path_cache.parent)
23
23
  end
24
24
 
25
25
 
data/lib/vfs/path.rb CHANGED
@@ -84,12 +84,10 @@ module Vfs
84
84
  parts = path.split('/')[1..-1]
85
85
  if parts
86
86
  parts.each do |part|
87
- if part == '..' and root != '.'
87
+ if part == '..' and (root != '.' or (root == '.' and result.size > 0))
88
88
  return nil, false unless result.size > 0
89
89
  result.pop
90
90
  probably_dir ||= true
91
- # elsif part == '.'
92
- # # do nothing
93
91
  else
94
92
  result << part
95
93
  probably_dir &&= false
data/readme.md CHANGED
@@ -1,111 +1,118 @@
1
- # Vfs - Virtual File System
1
+ Virtual File System provides **clean, simple and unified API over different storage systems** (Local File System, AWS S3, SFTP, Hadoop DFS, LDAP, Document Oriented DBs, In-Memory, ...).
2
+ It is possible to provide such unified API because although those storages have different API the core concept are almost the same.
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 kinda the same as ActiveRecord is for Relational Databases.
5
-
6
- Currently, there are following implementations available:
7
-
8
- - local file system
9
- - remote file system (over ssh)
4
+ Currently, there are following implementations available: Local FS, SFTP, S3.
10
5
 
11
6
  ## Goals
12
7
 
13
8
  - **handy, simple and clean** API.
14
9
  - same API for different storages (Local FS, SSH, Hadoop, or any other , ...).
15
10
  - should work **simultaneously with different storages**.
16
- - small codebase, easy to extend by others.
17
- - simple storage-driver implementation, easy add new storage types (Hadoop DFS, LDAP, Document Oriented DB, In-Memory, ...).
11
+ - small codebase, easy to extend and understand.
12
+ - driver implementation should be simple, is should be easy to create new drivers.
18
13
 
19
- **Performance**:
14
+ ## Example:
20
15
 
21
- - sometimes there's extra call to check if file or dir exist before overriding it
22
- - copy: right now 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.
16
+ The script below runs on local file system, to see this script running on S3 and SFTP please take a look at the examples folder, there are also samples for S3 backup and deployment over SSH/SFTP.
24
17
 
25
- ## Installation
18
+ ``` ruby
19
+ require 'vfs'
26
20
 
27
- ``` bash
28
- $ gem install vfs
29
- $ gem install vos
30
- ```
21
+ # Preparing temporary dir for sample and cleaning it before starting.
22
+ sandbox = '/tmp/vfs_sandbox'.to_dir.destroy
31
23
 
32
- ## Code samples:
24
+ # Let's create simple Hello World project.
25
+ project = sandbox['hello_world'] # Our Hello World project.
33
26
 
34
- ``` ruby
35
- require 'vfs' # Virtual File System
36
- require 'vos' # Virtual Operating System
27
+ project['readme.txt'].write 'My shiny App' # Writing readme file, note that parent dirs
28
+ # where created automatically.
37
29
 
38
- # Connections, let's deploy our 'cool_app' project from our local box to remote server
30
+ # File operations.
31
+ readme = project['readme.txt']
39
32
 
40
- server = Box.new('cool_app.com') # it will use id_rsa, or You can add {user: 'me', password: 'secret'}
41
- me = '~'.to_dir # handy shortcut for local FS
33
+ # Checking that it's all ok with our readme.
34
+ p readme.name # => readme.txt
35
+ p readme.path # => /.../readme.txt
36
+ p readme.exist? # => true
37
+ p readme.file? # => true
38
+ p readme.dir? # => false
39
+ p readme.size # => 12
40
+ p readme.created_at # => 2011-09-09 13:20:43 +0400
41
+ p readme.updated_at # => 2011-09-09 13:20:43 +0400
42
42
 
43
- deploy_dir = server['apps/cool_app']
44
- projects = me['projects']
43
+ # Reading.
44
+ p readme.read # => "My shiny App"
45
+ readme.read{|chunk| p chunk} # => "My shiny App"
45
46
 
46
- # Working with dirs, copying dir from any source to any destination (local/remote/custom_storage_type)
47
+ # Writing.
48
+ readme.append "2 + 2 = 4"
49
+ p readme.size # => 21
47
50
 
48
- projects['cool_app'].copy_to deploy_dir
51
+ readme.write "My shiny App v2" # Writing new version of readme.
52
+ p readme.read # => "My shiny App v2"
49
53
 
50
- # Working with files
54
+ readme.write{|s| s.write "My shiny App v3"} # Writing another new version of readme.
55
+ p readme.read # => "My shiny App v3"
51
56
 
52
- dbc = deploy_dir.file('config/database.yml') # <= the 'config' dir not exist yet
53
- dbc.write("user: root\npassword: secret") # <= now the 'database.yml' and parent 'config' has been created
54
- dbc.read =~ /database/ # => false, we forgot to add the database
55
- dbc.append("\ndatabase: mysql") # let's do it
57
+ # Copying & Moving.
58
+ readme.copy_to project['docs/readme.txt'] # Copying to ./docs folder.
59
+ p project['docs/readme.txt'].exist? # => true
60
+ p readme.exist? # => true
56
61
 
57
- dbc.update do |content| # and add host info
58
- content + "\nhost: cool_app.com "
59
- end
62
+ readme.move_to project['docs/readme.txt'] # Moving to ./docs folder.
63
+ p project['docs/readme.txt'].exist? # => true
64
+ p readme.exist? # => false
60
65
 
61
- projects['cool_app/config/database.yml']. # or just overwrite it with our local dev version
62
- copy_to! dbc
63
- ```
64
66
 
65
- There are also streaming support (read/write/append) with &block, please go to specs for details
67
+ # Dir operations.
68
+ project.file('Rakefile').create # Creating empty Rakefile.
66
69
 
67
- # Checks
70
+ # Checking our project exists and not empty.
71
+ p project.exist? # => true
72
+ p project.empty? # => false
68
73
 
69
- ``` ruby
70
- deploy_dir['config'].exist? # => true
71
- deploy_dir.dir('config').exist? # => true
72
- deploy_dir.file('config').exist? # => false
74
+ # Listing dir content.
75
+ p project.entries # => [/.../docs, .../Rakefile]
76
+ p project.files # => [/.../Rakefile]
77
+ p project.dirs # => [/.../docs]
78
+ project.entries do |entry| # => ["docs", false]
79
+ p [entry.name, entry.file?] # => ["Rakefile", true]
80
+ end
81
+ p project.include?('Rakefile') # => true
82
+
83
+ # Copying & Moving, let's create another project by cloning our hello_world.
84
+ project.copy_to sandbox['another_project']
85
+ p sandbox['another_project'].entries # => [/.../docs, .../Rakefile]
73
86
 
74
- deploy_dir['config'].dir? # => true
75
- deploy_dir['config'].file? # => false
87
+ # Cleaning sandbox.
88
+ sandbox.destroy
76
89
  ```
77
90
 
78
- # Navigation
91
+ API is the same for all storage types (Local, S3, SFTP, ...). Also API are the same for transfers (copy_to, move_to, ...) between any storage types.
92
+ So, for example backup from S3 looks exactly the same as if files are located on the local folder.
79
93
 
80
- ``` ruby
81
- config = deploy_dir['config']
82
- config.parent # => </apps/cool_app>
83
- config['../..'] # => </>
84
- config['../..'].dir? # => true
85
-
86
- deploy_dir.entries # => list of dirs and files, also support &block
87
- deploy_dir.files # => list of files, also support &block
88
- deploy_dir.dirs # => list of dirs, also support &block
89
- ```
94
+ ## Installation
90
95
 
91
- For more please go to specs (create/update/move/copy/destroy/...)
96
+ ``` bash
97
+ $ gem install vfs
98
+
99
+ # For S3 and SFTP support install also vos
100
+ $ gem install vos
101
+ ```
92
102
 
93
103
  ## Integration with [Vos][vos] (Virtual Operating System)
94
104
 
95
- ```ruby
96
- server['apps/cool_app'].bash 'rails production'
97
- ```
105
+ Vfs can be used toghether with the Virtual Operating System Tool, and while the Vfs covers all the I/O operations the Vos provides support for remote command execution.
106
+ You can use this combination to fully control remote machines, for example - I'm using it to manage my production servers (setup, administration, deployment, migration, ...).
98
107
 
99
108
  For more details please go to [Vos][vos] project page.
100
- Or checkout configuration I use to control my production servers [My Cluster][my_cluster] in conjunction with small
101
- configuration tool [Cluster Management][cluster_management].
109
+ You can also take look at the actual configuration I'm using to control my servers [My Cluster][my_cluster] (in conjunction with small configuration tool [Cluster Management][cluster_management]).
102
110
 
103
111
  # Why?
104
112
 
105
- To easy my work: with local FS, remote FS (cluster management, deployment automation), and some specific systems like Hadoop DFS.
113
+ To easy my work: with local FS, remote FS, and some specific systems like Hadoop DFS.
106
114
 
107
- Because the API of standard File/Dir/FileUtils classes are just terrible. And there's the reason for it - the goal of thouse tools
108
- is to provide 1-to-1 clone of underlying OS API, instead of provididing handy tool.
115
+ Because the API of standard File/Dir/FileUtils classes are just terrible. And there's the reason for it - the goal of thouse tools is to provide 1-to-1 clone of underlying OS API, instead of provididing handy tool.
109
116
 
110
117
  And if you want to use remote FS - things are getting even worse and more complicated (Net::SSH & Net::SFTP use a little
111
118
  different API than local FS, and you has to remember all thouse little quirks).
data/spec/path_spec.rb CHANGED
@@ -73,6 +73,8 @@ describe "Path" do
73
73
  ]
74
74
  (%w(
75
75
  /a/b/c /a/b
76
+ ./a/b/c ./a/b
77
+ ~/a/b/c ~/a/b
76
78
  ) + special).each_slice(2) do |path, parent|
77
79
  Path.new(path).parent.should == parent
78
80
  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.4.0
4
+ version: 0.4.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-09-08 00:00:00.000000000Z
12
+ date: 2011-09-09 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: