fffs 0.0.1

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.
@@ -0,0 +1,20 @@
1
+ #--
2
+ # Copyleft meh. [http://meh.doesntexist.org | meh@paranoici.org]
3
+ #
4
+ # This file is part of fffs.
5
+ #
6
+ # fffs is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # fffs is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with fffs. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ require 'fffs/filesystem'
@@ -0,0 +1,90 @@
1
+ #--
2
+ # Copyleft meh. [http://meh.doesntexist.org | meh@paranoici.org]
3
+ #
4
+ # This file is part of fffs.
5
+ #
6
+ # fffs is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # fffs is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with fffs. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ module FFFS
21
+
22
+ class Directory < Hash
23
+ attr_accessor :filesystem, :parent
24
+
25
+ attr_reader :name
26
+
27
+ def initialize (name, files=[], parent=nil, filesystem=nil)
28
+ @filesystem = filesystem
29
+ @parent = parent
30
+
31
+ @name = name
32
+
33
+ files.each {|file|
34
+ self[file.name] = file
35
+ }
36
+ end
37
+
38
+ def name= (value)
39
+ @parent.delete(@name)
40
+ @name = value
41
+ @parent << self
42
+ end
43
+
44
+ def to_a
45
+ self.map {|(name, file)| file}
46
+ end
47
+
48
+ def method_missing (id, *args, &block)
49
+ self[id.to_s]
50
+ end
51
+
52
+ alias __set []=
53
+
54
+ def []= (name, value)
55
+ value.parent = self
56
+ value.filesystem = self.filesystem
57
+
58
+ __set(name, value)
59
+ end
60
+
61
+ def push (file)
62
+ self[file.name] = file
63
+ end
64
+
65
+ alias << push
66
+
67
+ def path
68
+ path = []
69
+ current = self
70
+
71
+ begin
72
+ path << current.name
73
+ current = current.parent
74
+ end while current != current.parent
75
+
76
+ "/#{path.reverse.join('/')}/".sub(%r{/*/}, '/')
77
+ end
78
+
79
+ def inspect
80
+ output = "#{self.path}\n"
81
+
82
+ self.each_value {|file|
83
+ output << "#{file.inspect}\n"
84
+ }
85
+
86
+ output[-1] = ''; output
87
+ end
88
+ end
89
+
90
+ end
@@ -0,0 +1,61 @@
1
+ #--
2
+ # Copyleft meh. [http://meh.doesntexist.org | meh@paranoici.org]
3
+ #
4
+ # This file is part of fffs.
5
+ #
6
+ # fffs is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # fffs is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with fffs. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ module FFFS
21
+
22
+ class File
23
+ attr_accessor :filesystem, :parent
24
+
25
+ attr_accessor :content
26
+ attr_reader :name
27
+
28
+ def initialize (name, content='', parent=nil, filesystem=nil)
29
+ @filesystem = filesystem
30
+ @parent = parent
31
+
32
+ @name = name
33
+
34
+ @content = content.clone
35
+ @content.force_encoding 'ASCII-8BIT'
36
+ end
37
+
38
+ def name= (value)
39
+ @parent.delete(@name)
40
+ @name = value
41
+ @parent << self
42
+ end
43
+
44
+ def path
45
+ path = []
46
+ current = self
47
+
48
+ begin
49
+ path << current.name
50
+ current = current.parent
51
+ end while current != current.parent
52
+
53
+ "/#{path.reverse.join('/')}"
54
+ end
55
+
56
+ def inspect
57
+ self.path
58
+ end
59
+ end
60
+
61
+ end
@@ -0,0 +1,64 @@
1
+ #--
2
+ # Copyleft meh. [http://meh.doesntexist.org | meh@paranoici.org]
3
+ #
4
+ # This file is part of fffs.
5
+ #
6
+ # fffs is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # fffs is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with fffs. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ require 'fffs/directory'
21
+ require 'fffs/file'
22
+ require 'fffs/link'
23
+
24
+ module FFFS
25
+
26
+ class FileSystem < Directory
27
+ def initialize (text)
28
+ @name = '/'
29
+
30
+ self.parent = self
31
+ self.filesystem = self
32
+
33
+ separator = Regexp.escape(text.match(/^(.+)$/)[1])
34
+ text = text.sub(/^.*$/, '').gsub(/\r/, '')
35
+ text[-1] = ''
36
+
37
+ data = text.split(/\n\n#{separator} (.+?) #{separator}\n\n/)
38
+ data.shift
39
+
40
+ data.each_slice(2) {|(name, content)|
41
+ path = ::File.dirname(name)
42
+
43
+ if path == '.'
44
+ parent = self
45
+
46
+ self << File.new(::File.basename(name), content)
47
+ else
48
+ into = nil
49
+
50
+ path.split('/').each {|dir|
51
+ into = self[dir] || (self << Directory.new(dir))
52
+ }
53
+
54
+ into << File.new(::File.basename(name), content)
55
+ end
56
+ }
57
+ end
58
+
59
+ def path (path=nil)
60
+ '/'
61
+ end
62
+ end
63
+
64
+ end
@@ -0,0 +1,31 @@
1
+ #--
2
+ # Copyleft meh. [http://meh.doesntexist.org | meh@paranoici.org]
3
+ #
4
+ # This file is part of fffs.
5
+ #
6
+ # fffs is free software: you can redistribute it and/or modify
7
+ # it under the terms of the GNU Affero General Public License as published
8
+ # by the Free Software Foundation, either version 3 of the License, or
9
+ # (at your option) any later version.
10
+ #
11
+ # fffs is distributed in the hope that it will be useful,
12
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
13
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
+ # GNU Affero General Public License for more details.
15
+ #
16
+ # You should have received a copy of the GNU Affero General Public License
17
+ # along with fffs. If not, see <http://www.gnu.org/licenses/>.
18
+ #++
19
+
20
+ module FFFS
21
+
22
+ class Link
23
+ attr_accessor :parent, :to
24
+
25
+ def initialize (file, parent=nil)
26
+ @parent = parent
27
+ @to = file
28
+ end
29
+ end
30
+
31
+ end
metadata ADDED
@@ -0,0 +1,68 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: fffs
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - meh.
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-12-03 00:00:00 +01:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: A virtual filesystem for embedded data.
22
+ email: meh@paranoici.org
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/fffs.rb
31
+ - lib/fffs/file.rb
32
+ - lib/fffs/link.rb
33
+ - lib/fffs/directory.rb
34
+ - lib/fffs/filesystem.rb
35
+ has_rdoc: true
36
+ homepage: http://github.com/meh/fffs
37
+ licenses: []
38
+
39
+ post_install_message:
40
+ rdoc_options: []
41
+
42
+ require_paths:
43
+ - lib
44
+ required_ruby_version: !ruby/object:Gem::Requirement
45
+ none: false
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ segments:
50
+ - 0
51
+ version: "0"
52
+ required_rubygems_version: !ruby/object:Gem::Requirement
53
+ none: false
54
+ requirements:
55
+ - - ">="
56
+ - !ruby/object:Gem::Version
57
+ segments:
58
+ - 0
59
+ version: "0"
60
+ requirements: []
61
+
62
+ rubyforge_project:
63
+ rubygems_version: 1.3.7
64
+ signing_key:
65
+ specification_version: 3
66
+ summary: A virtual filesystem.
67
+ test_files: []
68
+