invfs 0.3 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5ba520faaa919d8053ed90c0e4f1a83566a0bfb15dc3dbc2a556a335d7c16922
4
- data.tar.gz: ade81666d1041d7e2789929b03297592119767e7b9f9280775fcf7bd655127f4
3
+ metadata.gz: 284b0757e014569ee1da5d2d0d246074249421d3727bdf97012379cfef7e6fc5
4
+ data.tar.gz: cd596213d14297b1af6199d19821eb31c6f61b145f9923e0538c3dcd18d5ca21
5
5
  SHA512:
6
- metadata.gz: 69e2d22350e08b9ce911e75a071688f78916e30d5b821ae6b229e3c3a91c8cd082836d8a70fc02f92f776487732a6acb18625e70ba3697b4ded4c88fadde7222
7
- data.tar.gz: f21cfaa41d7f266a24b737ee5665647735d67bf0b5b28e5d5a3f2594bab9bdf9ef0ff4b84ffe789ba21702a718965019e2f6e0e92120cac6e4c2692fd7a95cbb
6
+ metadata.gz: 155e97de462c1430a4a5cb99ea22f91d7ac59a8418ee873719f5b9f80554ad915489bc2c41aab2b19b615c71bbdaaf43f90cd32ec9bc2f74e8baafb7cd6ee8c7
7
+ data.tar.gz: 3dc68b46585571da6eadeb448aa9f70eb113ffc17007c391ea2c6d3191aea4b4331f88dbb3d9f08b386e62320b29b3c3222f2b26ae996607c6d3399a007ea28f
data/README.md CHANGED
@@ -3,7 +3,7 @@
3
3
  ruby の ``require`` に仮想ファイルシステム (VFS; Virtual Filesystem) 対応機能を追加します。
4
4
 
5
5
  * package name: invfs <https://github.com/dearblue/ruby-invfs>
6
- * version: 0.3
6
+ * version: 0.3.1
7
7
  * production quality: CONCEPT, EXPERIMENTAL, UNSTABLE
8
8
  * license: BSD-2-clause License
9
9
  * author: dearblue <mailto:dearblue@users.noreply.github.com>
@@ -7,145 +7,9 @@ InVFS::TOPLEVEL_BINDING = binding.freeze
7
7
 
8
8
  require "pathname"
9
9
  require "tempfile"
10
+ require_relative "invfs/extensions"
10
11
 
11
12
  module InVFS
12
- module Extensions
13
- unless Numeric.method_defined?(:clamp)
14
- refine Numeric do
15
- def clamp(min, max)
16
- case
17
- when self < min
18
- min
19
- when self > max
20
- max
21
- else
22
- self
23
- end
24
- end
25
- end
26
- end
27
-
28
- unless String.method_defined?(:to_path)
29
- refine String do
30
- alias to_path to_s
31
- end
32
- end
33
-
34
- refine String do
35
- def to_i_with_unit
36
- case strip
37
- when /^(\d+(\.\d+)?)(?:([kmg])i?)?b?/i
38
- unit = 1 << (10 * " kmgtp".index(($3 || " ").downcase))
39
- ($1.to_f * unit).round
40
- else
41
- to_i
42
- end
43
- end
44
- end
45
-
46
- refine Integer do
47
- alias to_i_with_unit to_i
48
- end
49
-
50
- refine Numeric do
51
- def KiB
52
- self * (1 << 10)
53
- end
54
-
55
- def MiB
56
- self * (1 << 20)
57
- end
58
-
59
- def GiB
60
- self * (1 << 30)
61
- end
62
- end
63
-
64
- refine BasicObject do
65
- def __native_file_path?
66
- nil
67
- end
68
- end
69
-
70
- [::String, ::File, ::Dir, ::Pathname].each do |klass|
71
- refine klass do
72
- def __native_file_path?
73
- true
74
- end
75
- end
76
- end
77
-
78
- refine BasicObject do
79
- def it_a_file?
80
- false
81
- end
82
- end
83
-
84
- [::String, ::File, ::Dir, ::Pathname].each do |klass|
85
- refine klass do
86
- def it_a_file?
87
- File.file?(self)
88
- end
89
- end
90
- end
91
-
92
- [::String, ::File, ::Dir].each do |klass|
93
- refine klass do
94
- def file?(path)
95
- File.file?(File.join(self, path))
96
- end
97
- end
98
- end
99
-
100
- [::String, ::File, ::Pathname].each do |klass|
101
- refine klass do
102
- def readat(off, size = nil, buf = "".b)
103
- buf.replace File.binread(self, size, off)
104
- buf
105
- end
106
- end
107
- end
108
-
109
- refine Object do
110
- if Object.const_defined?(:DEBUGGER__)
111
- BREAKPOINT_SET = {}
112
-
113
- def __BREAKHERE__
114
- locate = caller_locations(1, 1)[0]
115
- __BREAKPOINT__(locate.path, locate.lineno + 1)
116
- end
117
-
118
- def __BREAKPOINT__(base, pos)
119
- case base
120
- when Module
121
- pos = String(pos.to_sym)
122
- when String
123
- base = "#{base}".freeze
124
- pos = pos.to_i
125
- else
126
- raise ArgumentError
127
- end
128
-
129
- key = [base, pos]
130
- unless BREAKPOINT_SET[key]
131
- BREAKPOINT_SET[key] = true
132
- DEBUGGER__.break_points.push [true, 0, base, pos]
133
- end
134
-
135
- nil
136
- end
137
- else
138
- def __BREAKHERE__
139
- nil
140
- end
141
-
142
- def __BREAKPOINT__(base, pos)
143
- nil
144
- end
145
- end
146
- end
147
- end
148
-
149
13
  using Extensions
150
14
 
151
15
  DEFAULT_MAX_LOADSIZE = 2.MiB
@@ -310,87 +174,22 @@ module InVFS
310
174
  end
311
175
  end
312
176
 
313
- class UnionFS
314
- attr_reader :dirs
315
-
316
- def initialize(*dirs)
317
- @dirs = dirs
318
- end
319
-
320
- def file?(lib)
321
- dirs.each do |dir|
322
- path = File.join(dir, lib)
323
- return true if File.file?(path)
324
- end
177
+ def InVFS.union(*dirs)
178
+ require_relative "invfs/unionfs"
325
179
 
326
- false
327
- end
328
-
329
- def size(lib)
330
- dirs.each do |dir|
331
- path = File.join(dir, lib)
332
- return File.size(path) if File.file?(path)
333
- end
334
-
335
- raise Errno::ENOENT, lib
336
- end
337
-
338
- def read(lib)
339
- dirs.each do |dir|
340
- path = File.join(dir, lib)
341
- return File.binread(path) if File.file?(path)
342
- end
343
-
344
- raise Errno::ENOENT, lib
345
- end
346
-
347
- def to_path
348
- %(#<#{self.class} #{dirs.map { |d| "<#{d}>" }.join(", ")}>)
349
- end
350
-
351
- def to_s
352
- to_path
353
- end
354
-
355
- def inspect
356
- to_s
357
- end
358
-
359
- def pretty_print(q)
360
- q.group(2, "#<#{self.class}", ">") do
361
- dirs.each_with_index do |d, i|
362
- q.text "," if i > 0
363
- q.breakable " "
364
- d.pretty_print q
365
- end
366
- end
367
- end
180
+ UnionFS.new(*dirs)
368
181
  end
369
182
 
370
- MultipleDirectory = UnionFS
183
+ def InVFS.stringmap(*map)
184
+ require_relative "invfs/stringmapfs"
371
185
 
372
- class StringMapFS
373
- attr_reader :map
374
-
375
- def initialize(*map)
376
- @map = Hash[*map]
377
- end
378
-
379
- def to_path
380
- sprintf %(#<%s 0x%08x>) % [self.class, object_id]
381
- end
382
-
383
- def file?(path)
384
- !!map.has_key?(path)
385
- end
186
+ StringMapFS.new(*map)
187
+ end
386
188
 
387
- def size(path)
388
- (map[path] or return nil).bytesize
389
- end
189
+ def InVFS.zip(*args)
190
+ require_relative "invfs/zip"
390
191
 
391
- def read(path)
392
- (map[path] or return nil).to_s
393
- end
192
+ Zip.new(*args)
394
193
  end
395
194
  end
396
195
 
@@ -0,0 +1,142 @@
1
+ #!ruby
2
+
3
+ require_relative "../invfs"
4
+
5
+ module InVFS
6
+ module Extensions
7
+ unless Numeric.method_defined?(:clamp)
8
+ refine Numeric do
9
+ def clamp(min, max)
10
+ case
11
+ when self < min
12
+ min
13
+ when self > max
14
+ max
15
+ else
16
+ self
17
+ end
18
+ end
19
+ end
20
+ end
21
+
22
+ unless String.method_defined?(:to_path)
23
+ refine String do
24
+ alias to_path to_s
25
+ end
26
+ end
27
+
28
+ refine String do
29
+ def to_i_with_unit
30
+ case strip
31
+ when /^(\d+(\.\d+)?)(?:([kmg])i?)?b?/i
32
+ unit = 1 << (10 * " kmgtp".index(($3 || " ").downcase))
33
+ ($1.to_f * unit).round
34
+ else
35
+ to_i
36
+ end
37
+ end
38
+ end
39
+
40
+ refine Integer do
41
+ alias to_i_with_unit to_i
42
+ end
43
+
44
+ refine Numeric do
45
+ def KiB
46
+ self * (1 << 10)
47
+ end
48
+
49
+ def MiB
50
+ self * (1 << 20)
51
+ end
52
+
53
+ def GiB
54
+ self * (1 << 30)
55
+ end
56
+ end
57
+
58
+ refine BasicObject do
59
+ def __native_file_path?
60
+ nil
61
+ end
62
+ end
63
+
64
+ [::String, ::File, ::Dir, ::Pathname].each do |klass|
65
+ refine klass do
66
+ def __native_file_path?
67
+ true
68
+ end
69
+ end
70
+ end
71
+
72
+ refine BasicObject do
73
+ def it_a_file?
74
+ false
75
+ end
76
+ end
77
+
78
+ [::String, ::File, ::Dir, ::Pathname].each do |klass|
79
+ refine klass do
80
+ def it_a_file?
81
+ File.file?(self)
82
+ end
83
+ end
84
+ end
85
+
86
+ [::String, ::File, ::Dir].each do |klass|
87
+ refine klass do
88
+ def file?(path)
89
+ File.file?(File.join(self, path))
90
+ end
91
+ end
92
+ end
93
+
94
+ [::String, ::File, ::Pathname].each do |klass|
95
+ refine klass do
96
+ def readat(off, size = nil, buf = "".b)
97
+ buf.replace File.binread(self, size, off)
98
+ buf
99
+ end
100
+ end
101
+ end
102
+
103
+ refine Object do
104
+ if Object.const_defined?(:DEBUGGER__)
105
+ BREAKPOINT_SET = {}
106
+
107
+ def __BREAKHERE__
108
+ locate = caller_locations(1, 1)[0]
109
+ __BREAKPOINT__(locate.path, locate.lineno + 1)
110
+ end
111
+
112
+ def __BREAKPOINT__(base, pos)
113
+ case base
114
+ when Module
115
+ pos = String(pos.to_sym)
116
+ when String
117
+ base = "#{base}".freeze
118
+ pos = pos.to_i
119
+ else
120
+ raise ArgumentError
121
+ end
122
+
123
+ key = [base, pos]
124
+ unless BREAKPOINT_SET[key]
125
+ BREAKPOINT_SET[key] = true
126
+ DEBUGGER__.break_points.push [true, 0, base, pos]
127
+ end
128
+
129
+ nil
130
+ end
131
+ else
132
+ def __BREAKHERE__
133
+ nil
134
+ end
135
+
136
+ def __BREAKPOINT__(base, pos)
137
+ nil
138
+ end
139
+ end
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,29 @@
1
+ #!ruby
2
+
3
+ require_relative "../invfs"
4
+
5
+ module InVFS
6
+ class StringMapFS
7
+ attr_reader :map
8
+
9
+ def initialize(*map)
10
+ @map = Hash[*map]
11
+ end
12
+
13
+ def to_path
14
+ sprintf %(#<%s 0x%08x>) % [self.class, object_id]
15
+ end
16
+
17
+ def file?(path)
18
+ !!map.has_key?(path)
19
+ end
20
+
21
+ def size(path)
22
+ (map[path] or return nil).bytesize
23
+ end
24
+
25
+ def read(path)
26
+ (map[path] or return nil).to_s
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,64 @@
1
+ #!ruby
2
+
3
+ require_relative "../invfs"
4
+
5
+ module InVFS
6
+ class UnionFS
7
+ attr_reader :dirs
8
+
9
+ def initialize(*dirs)
10
+ @dirs = dirs
11
+ end
12
+
13
+ def file?(lib)
14
+ dirs.each do |dir|
15
+ path = File.join(dir, lib)
16
+ return true if File.file?(path)
17
+ end
18
+
19
+ false
20
+ end
21
+
22
+ def size(lib)
23
+ dirs.each do |dir|
24
+ path = File.join(dir, lib)
25
+ return File.size(path) if File.file?(path)
26
+ end
27
+
28
+ raise Errno::ENOENT, lib
29
+ end
30
+
31
+ def read(lib)
32
+ dirs.each do |dir|
33
+ path = File.join(dir, lib)
34
+ return File.binread(path) if File.file?(path)
35
+ end
36
+
37
+ raise Errno::ENOENT, lib
38
+ end
39
+
40
+ def to_path
41
+ %(#<#{self.class} #{dirs.map { |d| "<#{d}>" }.join(", ")}>)
42
+ end
43
+
44
+ def to_s
45
+ to_path
46
+ end
47
+
48
+ def inspect
49
+ to_s
50
+ end
51
+
52
+ def pretty_print(q)
53
+ q.group(2, "#<#{self.class}", ">") do
54
+ dirs.each_with_index do |d, i|
55
+ q.text "," if i > 0
56
+ q.breakable " "
57
+ d.pretty_print q
58
+ end
59
+ end
60
+ end
61
+ end
62
+
63
+ MultipleDirectory = UnionFS
64
+ end
@@ -5,10 +5,6 @@ require_relative "../invfs"
5
5
 
6
6
  using InVFS::Extensions
7
7
 
8
- def InVFS.zip(*args)
9
- InVFS::Zip.new(*args)
10
- end
11
-
12
8
  module InVFS
13
9
  class Zip
14
10
  attr_reader :path, :zip, :zipfile
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: invfs
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - dearblue
@@ -32,6 +32,9 @@ extra_rdoc_files:
32
32
  - LICENSE
33
33
  - README.md
34
34
  - lib/invfs.rb
35
+ - lib/invfs/extensions.rb
36
+ - lib/invfs/stringmapfs.rb
37
+ - lib/invfs/unionfs.rb
35
38
  - lib/invfs/zip.rb
36
39
  files:
37
40
  - LICENSE
@@ -39,6 +42,9 @@ files:
39
42
  - Rakefile
40
43
  - gemstub.rb
41
44
  - lib/invfs.rb
45
+ - lib/invfs/extensions.rb
46
+ - lib/invfs/stringmapfs.rb
47
+ - lib/invfs/unionfs.rb
42
48
  - lib/invfs/zip.rb
43
49
  homepage: https://github.com/dearblue/ruby-invfs
44
50
  licenses: