fffs 0.0.9 → 0.0.10

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.
@@ -17,4 +17,8 @@
17
17
  # along with fffs. If not, see <http://www.gnu.org/licenses/>.
18
18
  #++
19
19
 
20
+ module FFFS
21
+ Version = '0.0.10'
22
+ end
23
+
20
24
  require 'fffs/filesystem'
@@ -26,19 +26,24 @@ class Directory < Hash
26
26
 
27
27
  attr_accessor :filesystem, :parent
28
28
 
29
- attr_reader :name
29
+ attr_reader :name, :mode
30
30
 
31
31
  def initialize (name, files=[], parent=nil, filesystem=nil)
32
32
  @filesystem = filesystem
33
33
  @parent = parent
34
34
 
35
35
  @name = name
36
+ @mode = 0755
36
37
 
37
38
  files.each {|file|
38
39
  self[file.name] = file
39
40
  }
40
41
  end
41
42
 
43
+ def chmod (mode)
44
+ @mode = mode
45
+ end
46
+
42
47
  def filesystem= (value)
43
48
  self.each_value {|file|
44
49
  file.filesystem = value
@@ -92,13 +97,14 @@ class Directory < Hash
92
97
  "#{__path}/".sub(%r{/*/}, '/')
93
98
  end
94
99
 
95
- def save (path)
100
+ def save (path, mode=nil)
96
101
  require 'fileutils'
97
102
 
98
103
  FileUtils.mkpath(path)
104
+ ::File.chmod(mode || @mode, path)
99
105
 
100
- each_value {|f|
101
- f.save("#{path}/#{f.name}")
106
+ map {|(_, f)|
107
+ f.save("#{path}/#{f.name}", mode)
102
108
  }
103
109
  end
104
110
 
@@ -27,13 +27,14 @@ class File
27
27
  attr_accessor :filesystem, :parent
28
28
 
29
29
  attr_accessor :content
30
- attr_reader :name
30
+ attr_reader :name, :mode
31
31
 
32
32
  def initialize (name, content='', parent=nil, filesystem=nil)
33
33
  @filesystem = filesystem
34
34
  @parent = parent
35
35
 
36
36
  @name = name
37
+ @mode = 0644
37
38
 
38
39
  @content = content.clone
39
40
  @content.force_encoding 'ASCII-8BIT'
@@ -45,15 +46,33 @@ class File
45
46
  @parent << self
46
47
  end
47
48
 
48
- def save (file)
49
+ def chmod (mode)
50
+ @mode = mode
51
+ end
52
+
53
+ def save (file, mode=nil)
54
+ result = true
55
+
49
56
  if file.is_a?(String)
50
57
  ::File.open(file, 'wb') {|f|
51
- f.write content
58
+ result = f.write content
59
+
60
+ begin
61
+ f.chmod(mode || @mode)
62
+ rescue Exception => e
63
+ end
52
64
  }
53
65
  else
54
- file.write content
66
+ result = file.write content
55
67
  file.flush
68
+
69
+ begin
70
+ file.chmod(mode || @mode)
71
+ rescue Exception => e
72
+ end
56
73
  end
74
+
75
+ result
57
76
  end
58
77
 
59
78
  def execute (*args)
@@ -23,37 +23,39 @@ class Link
23
23
  attr_accessor :filesystem, :parent
24
24
 
25
25
  attr_accessor :to
26
+ attr_reader :name
26
27
 
27
- def initialize (file, parent=nil, filesystem=nil)
28
+ def initialize (name, file, parent=nil, filesystem=nil)
28
29
  @parent = parent
30
+ @name = name
29
31
  @to = file
30
32
  end
31
33
 
32
- def handle
33
- return @handle if @handle
34
+ def name= (value)
35
+ @parent.delete(@name)
36
+ @name = value
37
+ @parent << self
38
+ end
34
39
 
35
- @handle = self.filesystem
40
+ def handle
41
+ handle = self.filesystem
36
42
 
37
43
  @to.split('/').reject {|s| s.empty?}.each {|path|
38
- @handle = @handle[path]
44
+ handle = handle[path]
39
45
 
40
- break if !@handle
46
+ break if !handle
41
47
  }
42
48
 
43
- return @handle
49
+ return handle
44
50
  end
45
51
 
46
- def content
47
- if handle
48
- handle.content
52
+ [:content, :chmod, :execute, :mode].each {|meth|
53
+ define_method meth do |*args|
54
+ if tmp = handle
55
+ tmp.send meth, *args
56
+ end
49
57
  end
50
- end
51
-
52
- def execute (*args)
53
- if handle
54
- handle.execute(*args)
55
- end
56
- end
58
+ }
57
59
 
58
60
  def save (path)
59
61
  require 'fileutils'
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 9
9
- version: 0.0.9
8
+ - 10
9
+ version: 0.0.10
10
10
  platform: ruby
11
11
  authors:
12
12
  - meh.
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-05-05 00:00:00 +02:00
17
+ date: 2011-05-08 00:00:00 +02:00
18
18
  default_executable:
19
19
  dependencies: []
20
20