fastlib 0.0.5 → 0.0.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/lib/fastlib.rb +71 -64
  2. metadata +3 -3
data/lib/fastlib.rb CHANGED
@@ -31,75 +31,13 @@ require "find"
31
31
  # >> rubyzip is free software; you can redistribute it and/or
32
32
  # >> modify it under the terms of the ruby license.
33
33
 
34
- module Kernel #:nodoc:all
35
- alias :fastlib_original_require :require
36
-
37
- #
38
- # This method hooks the original Kernel.require to support
39
- # loading files within FASTLIB archives
40
- #
41
- def require(name)
42
- fastlib_require(name) || fastlib_original_require(name)
43
- end
44
-
45
- #
46
- # This method handles the loading of FASTLIB archives
47
- #
48
- def fastlib_require(name)
49
- name = name + ".rb" if not name =~ /\.rb$/
50
- return false if fastlib_already_loaded?(name)
51
- return false if fastlib_already_tried?(name)
52
-
53
- # TODO: Implement relative path $: checks and adjust the
54
- # search path within archives to match.
55
-
56
- $:.grep( /^(.*)\.fastlib$/ ).each do |lib|
57
- data = FastLib.load(lib, name)
58
- next if not data
59
- $" << name
60
-
61
- # TODO: Implement a better stack trace that represents
62
- # the original filename and line number.
63
- Object.class_eval(data)
64
- return true
65
- end
66
-
67
- $fastlib_miss << name
68
-
69
- false
70
- end
71
-
72
- #
73
- # This method determines whether the specific file name
74
- # has already been loaded ($LOADED_FEATURES aka $")
75
- #
76
- def fastlib_already_loaded?(name)
77
- re = Regexp.new("^" + Regexp.escape(name) + "$")
78
- $".detect { |e| e =~ re } != nil
79
- end
80
-
81
- #
82
- # This method determines whether the specific file name
83
- # has already been attempted with the included FASTLIB
84
- # archives.
85
- #
86
- # TODO: Ensure that this only applies to known FASTLIB
87
- # archives and that newly included archives will
88
- # be searched appropriately.
89
- #
90
- def fastlib_already_tried?(name)
91
- $fastlib_miss ||= []
92
- $fastlib_miss.include?(name)
93
- end
94
- end
95
-
96
34
 
97
35
  #
98
36
  # The FastLib class implements the meat of the FASTLIB archive format
99
37
  #
100
38
  class FastLib
101
39
 
102
- VERSION = "0.0.5"
40
+ VERSION = "0.0.6"
103
41
 
104
42
  FLAG_COMPRESS = 0x01
105
43
  FLAG_ENCRYPT = 0x02
@@ -142,7 +80,7 @@ class FastLib
142
80
  @@cache[lib][:fastlib_header][1] +
143
81
  @@cache[lib][name][0]
144
82
  )
145
- data = fastlib_filter_decode( @@cache[lib][:fastlib_flags], fd.read(@@cache[lib][name][1] ))
83
+ data = fastlib_filter_decode( lib, fd.read(@@cache[lib][name][1] ))
146
84
  end
147
85
 
148
86
  # Return the contents in raw or processed form
@@ -403,4 +341,73 @@ end
403
341
  =end
404
342
 
405
343
 
344
+ module Kernel #:nodoc:all
345
+ alias :fastlib_original_require :require
346
+
347
+ #
348
+ # This method hooks the original Kernel.require to support
349
+ # loading files within FASTLIB archives
350
+ #
351
+ def require(name)
352
+ fastlib_require(name) || fastlib_original_require(name)
353
+ end
354
+
355
+ #
356
+ # This method handles the loading of FASTLIB archives
357
+ #
358
+ def fastlib_require(name)
359
+ name = name + ".rb" if not name =~ /\.rb$/
360
+ return false if fastlib_already_loaded?(name)
361
+ return false if fastlib_already_tried?(name)
362
+
363
+ # TODO: Implement relative path $: checks and adjust the
364
+ # search path within archives to match.
365
+
366
+ $:.map{ |path| ::Dir["#{path}/*.fastlib"] }.flatten.uniq.each do |lib|
367
+ data = FastLib.load(lib, name)
368
+ next if not data
369
+ $" << name
370
+
371
+ begin
372
+ Object.class_eval(data)
373
+ rescue ::Exception => e
374
+ opath,oerror = e.backtrace.shift.split(':', 2)
375
+ e.backtrace.unshift("#{lib}::#{name}:#{oerror}")
376
+ raise e
377
+ end
378
+
379
+ return true
380
+ end
381
+
382
+ $fastlib_miss << name
383
+
384
+ false
385
+ end
386
+
387
+ #
388
+ # This method determines whether the specific file name
389
+ # has already been loaded ($LOADED_FEATURES aka $")
390
+ #
391
+ def fastlib_already_loaded?(name)
392
+ re = Regexp.new("^" + Regexp.escape(name) + "$")
393
+ $".detect { |e| e =~ re } != nil
394
+ end
395
+
396
+ #
397
+ # This method determines whether the specific file name
398
+ # has already been attempted with the included FASTLIB
399
+ # archives.
400
+ #
401
+ # TODO: Ensure that this only applies to known FASTLIB
402
+ # archives and that newly included archives will
403
+ # be searched appropriately.
404
+ #
405
+ def fastlib_already_tried?(name)
406
+ $fastlib_miss ||= []
407
+ $fastlib_miss.include?(name)
408
+ end
409
+ end
410
+
411
+
412
+
406
413
 
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fastlib
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 0
9
- - 5
10
- version: 0.0.5
9
+ - 6
10
+ version: 0.0.6
11
11
  platform: ruby
12
12
  authors:
13
13
  - HD Moore