vfs 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (2) hide show
  1. data/readme.md +92 -0
  2. metadata +2 -2
data/readme.md CHANGED
@@ -18,6 +18,98 @@ Once installed, You can proceed with the [basic example][basics], there's also [
18
18
 
19
19
  You can report bugs and discuss features on the [issues page][issues].
20
20
 
21
+ ## Sample
22
+
23
+ ``` ruby
24
+ # Preparing sandbox for our sample and cleaning it before starting
25
+ # (ignore the `$sandbox` variable, it's needed to reuse this code in S3 and SSH samples).
26
+ require 'vfs'
27
+ sandbox = $sandbox || '/tmp/vfs_sandbox'.to_dir.destroy
28
+
29
+ # Creating simple Hello World project.
30
+ project = sandbox['hello_world']
31
+
32
+ # Writing readme file (note that parent dirs where created automatically).
33
+ project['readme.txt'].write 'My App'
34
+
35
+ # We can assign files and dirs to variables, now the `readme` variable refers to our readme.txt file.
36
+ readme = project['readme.txt']
37
+
38
+ # Let's ensure that it's all ok with our readme file and check it's attributes.
39
+ p readme.name # => readme.txt
40
+ p [readme.basename, readme.extension] # => ['readme', 'txt']
41
+ p readme.path # => /.../readme.txt
42
+ p readme.exist? # => true
43
+ p readme.file? # => true
44
+ p readme.dir? # => false
45
+ p readme.size # => 6
46
+ p readme.created_at # => 2011-09-09 13:20:43 +0400
47
+ p readme.updated_at # => 2011-09-09 13:20:43 +0400
48
+
49
+ # Reading - You can read all at once or do it sequentially (input stream
50
+ # will be automatically splitted into chunks of reasonable size).
51
+ p readme.read # => "My shiny App"
52
+ readme.read{|chunk| p chunk} # => "My shiny App"
53
+
54
+ # The same for writing - write all at once or do it sequentially
55
+ # (if there's no file it will be created, if it exists it will be rewriten).
56
+ readme.write "My App v2"
57
+ readme.write{|stream| stream.write "My App v3"}
58
+ p readme.read # => "My shiny App v3"
59
+
60
+ # Appending content to existing file.
61
+ readme.append "How to install ..."
62
+ p readme.size # => 27
63
+
64
+ # Copying and Moving. It also works exactly the same
65
+ # way if You copy or move files and dirs to other storages.
66
+ readme.copy_to project['docs/readme.txt']
67
+ p project['docs/readme.txt'].exist? # => true
68
+ p readme.exist? # => true
69
+
70
+ readme.move_to project['docs/readme.txt']
71
+ p project['docs/readme.txt'].exist? # => true
72
+ p readme.exist? # => false
73
+
74
+ # Let's add empty Rakefile to our project.
75
+ project['Rakefile'].write
76
+
77
+ # Operations with directories - checking our project exists and not empty.
78
+ p project.exist? # => true
79
+ p project.empty? # => false
80
+
81
+ # Listing dir content. There are two versions of methods -
82
+ # without block the result will be Array of Entries, with block
83
+ # it will iterate over directory sequentially.
84
+ p project.entries # => [/.../docs, /.../Rakefile]
85
+ p project.files # => [/.../Rakefile]
86
+ p project.dirs # => [/.../docs]
87
+ project.entries do |entry| # => ["docs", false]
88
+ p [entry.name, entry.file?] # => ["Rakefile", true]
89
+ end
90
+ p project.include?('Rakefile') # => true
91
+
92
+ # You can also use glob (if storage support it).
93
+ if project.driver.local?
94
+ p project.entries('**/Rake*') # => [/.../Rakefile]
95
+ p project['**/Rake*'] # => [/.../Rakefile]
96
+ end
97
+
98
+ # The result of dir listing is just an array of Entries, so
99
+ # You can use it to do interesting things. For example this code will
100
+ # calculates the size of sources in our project.
101
+ if project.driver.local?
102
+ project['**/*.rb'].collect(&:size).reduce(0, :+)
103
+ end
104
+
105
+ # Copying and moving - let's create another project by cloning our hello_world.
106
+ project.copy_to sandbox['another_project']
107
+ p sandbox['another_project'].entries # => [/.../docs, .../Rakefile]
108
+
109
+ # Cleaning sandbox.
110
+ sandbox.destroy
111
+ ```
112
+
21
113
  ## Integration with [Vos][vos] (Virtual Operating System)
22
114
 
23
115
  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.
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.5
4
+ version: 0.4.6
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-11 00:00:00.000000000Z
12
+ date: 2011-09-13 00:00:00.000000000Z
13
13
  dependencies: []
14
14
  description:
15
15
  email: