fffs 0.0.1 → 0.0.2

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.
@@ -35,6 +35,14 @@ class Directory < Hash
35
35
  }
36
36
  end
37
37
 
38
+ def filesystem= (value)
39
+ self.each_value {|file|
40
+ file.filesystem = value
41
+ }
42
+
43
+ @filesystem = value
44
+ end
45
+
38
46
  def name= (value)
39
47
  @parent.delete(@name)
40
48
  @name = value
@@ -64,6 +72,12 @@ class Directory < Hash
64
72
 
65
73
  alias << push
66
74
 
75
+ def merge (dir)
76
+ dir.each_value {|file|
77
+ self << file
78
+ }
79
+ end
80
+
67
81
  def path
68
82
  path = []
69
83
  current = self
@@ -24,12 +24,18 @@ require 'fffs/link'
24
24
  module FFFS
25
25
 
26
26
  class FileSystem < Directory
27
- def initialize (text)
27
+ def self.parse (text)
28
+ self.new.parse(text)
29
+ end
30
+
31
+ def initialize
28
32
  @name = '/'
29
33
 
30
34
  self.parent = self
31
35
  self.filesystem = self
36
+ end
32
37
 
38
+ def parse (text)
33
39
  separator = Regexp.escape(text.match(/^(.+)$/)[1])
34
40
  text = text.sub(/^.*$/, '').gsub(/\r/, '')
35
41
  text[-1] = ''
@@ -38,12 +44,21 @@ class FileSystem < Directory
38
44
  data.shift
39
45
 
40
46
  data.each_slice(2) {|(name, content)|
47
+ if name.include?(' -> ')
48
+ t, name, link = name.match(/^(.*?) -> (.*?)$/)
49
+ end
50
+
41
51
  path = ::File.dirname(name)
52
+ name = ::File.basename(name)
42
53
 
43
54
  if path == '.'
44
55
  parent = self
45
56
 
46
- self << File.new(::File.basename(name), content)
57
+ if link
58
+ self << Link.new(name, link)
59
+ else
60
+ self << File.new(name, content)
61
+ end
47
62
  else
48
63
  into = nil
49
64
 
@@ -51,9 +66,15 @@ class FileSystem < Directory
51
66
  into = self[dir] || (self << Directory.new(dir))
52
67
  }
53
68
 
54
- into << File.new(::File.basename(name), content)
69
+ if link
70
+ into << Link.new(name, link)
71
+ else
72
+ into << File.new(name, content)
73
+ end
55
74
  end
56
75
  }
76
+
77
+ self
57
78
  end
58
79
 
59
80
  def path (path=nil)
@@ -20,12 +20,28 @@
20
20
  module FFFS
21
21
 
22
22
  class Link
23
- attr_accessor :parent, :to
23
+ attr_accessor :filesystem, :parent
24
+
25
+ attr_accessor :to
24
26
 
25
- def initialize (file, parent=nil)
27
+ def initialize (file, parent=nil, filesystem=nil)
26
28
  @parent = parent
27
29
  @to = file
28
30
  end
31
+
32
+ def content
33
+ handle = self.filesystem
34
+
35
+ @to.split('/').reject {|s| s.empty?}.each {|path|
36
+ handle = handle[path]
37
+
38
+ break if !handle
39
+ }
40
+
41
+ if handle
42
+ handle.content rescue ''
43
+ end
44
+ end
29
45
  end
30
46
 
31
47
  end
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 0
8
- - 1
9
- version: 0.0.1
8
+ - 2
9
+ version: 0.0.2
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: 2010-12-03 00:00:00 +01:00
17
+ date: 2010-12-04 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies: []
20
20