ruby_archive 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,144 @@
1
+ require 'rbconfig'
2
+
3
+ module Kernel
4
+ class << self
5
+ unless Kernel.respond_to?('ruby_archive_original_open')
6
+ # Alias for the original +Kernel::open+
7
+ alias ruby_archive_original_open open
8
+ protected(:ruby_archive_original_open)
9
+ end
10
+
11
+ def open path,mode='r',perm=0666,&block
12
+ if path[0] == '|'[0]
13
+ return ruby_archive_original_open(path,mode,&block)
14
+ else
15
+ return File::open(path,mode,perm,&block)
16
+ end
17
+ end
18
+ end
19
+
20
+ unless Kernel.respond_to?('ruby_archive_original_kernel_open',true)
21
+ # Alias for the original +Kernel#open+
22
+ alias ruby_archive_original_kernel_open open
23
+ end
24
+
25
+ def open name,*rest,&block
26
+ Kernel::open(name,*rest,&block)
27
+ end
28
+ private(:ruby_archive_original_kernel_open, :open)
29
+
30
+ unless Kernel.respond_to?('ruby_archive_original_kernel_load',true)
31
+ # Alias for the original +Kernel#load+
32
+ alias ruby_archive_original_kernel_load load
33
+ private(:ruby_archive_original_kernel_load)
34
+ end
35
+
36
+ def load filename,wrap=false
37
+ # define errors to rescue original require from (exception for rubinius)
38
+ rescue1 = rescue2 = LoadError
39
+ rescue2 = Rubinius::CompileError if defined?(Rubinius::CompileError)
40
+
41
+ # use original load if it works
42
+ begin
43
+ return ruby_archive_original_kernel_load(filename,wrap)
44
+ rescue rescue1, rescue2
45
+ # otherwise, try our re-implementation of require
46
+ $LOAD_PATH.each do |path|
47
+ full_path = File.expand_path(filename,path)
48
+
49
+ to_eval = nil
50
+ begin
51
+ to_eval = File.read(full_path)
52
+ rescue Exception
53
+ next
54
+ end
55
+
56
+ if wrap
57
+ Module.new.instance_eval(to_eval,full_path)
58
+ else
59
+ eval(to_eval,TOPLEVEL_BINDING,full_path)
60
+ end
61
+ return true
62
+
63
+ end
64
+ raise LoadError, "no such file to load -- #{filename}"
65
+ end
66
+ end
67
+ private(:load)
68
+
69
+ # loads an extension given the _full path_
70
+ def load_extension full_path
71
+ orig_loaded_features = $LOADED_FEATURES.dup
72
+ unless File.in_archive?(full_path)
73
+ ruby_archive_original_kernel_require(full_path)
74
+ else
75
+ raise LoadError, "Can't load native extensions from archives (yet)"
76
+ end
77
+ $LOADED_FEATURES.replace(orig_loaded_features)
78
+ return true
79
+ end
80
+
81
+ unless Kernel.respond_to?('ruby_archive_original_kernel_require',true)
82
+ # Alias for the original +Kernel#require+
83
+ alias ruby_archive_original_kernel_require require
84
+ end
85
+
86
+ def require file
87
+ # define errors to rescue original require from (exception for rubinius)
88
+ rescue1 = rescue2 = LoadError
89
+ rescue2 = Rubinius::CompileError if defined?(Rubinius::CompileError)
90
+
91
+ # use original require if it works
92
+ begin
93
+ return ruby_archive_original_kernel_require(file)
94
+ rescue rescue1, rescue2
95
+ # otherwise, try our re-implementation of require
96
+ return false if $LOADED_FEATURES.include?(file)
97
+ rbext = '.rb'
98
+ dlext = ".#{Config::CONFIG['DLEXT']}"
99
+ ext = File.extname(file)
100
+ if ext == rbext || ext == dlext
101
+ f = require_path_find(file)
102
+ unless f == false
103
+ return false if $LOADED_FEATURES.include?(f)
104
+ load(f,false) if ext == rbext
105
+ load_extension(f) if ext == dlext
106
+ $LOADED_FEATURES << f
107
+ return true
108
+ end
109
+ end
110
+
111
+ # search for "file.rb"
112
+ return false if $LOADED_FEATURES.include?("#{file}#{rbext}")
113
+ f = require_path_find("#{file}#{rbext}")
114
+ unless f == false
115
+ return false if $LOADED_FEATURES.include?(f)
116
+ load(f,false)
117
+ $LOADED_FEATURES << f
118
+ return true
119
+ end
120
+
121
+ # search for "file.so"
122
+ return false if $LOADED_FEATURES.include?("#{file}#{dlext}")
123
+ f = require_path_find("#{file}#{dlext}")
124
+ unless f == false
125
+ return false if $LOADED_FEATURES.include?(f)
126
+ load_extension(f)
127
+ $LOADED_FEATURES << f
128
+ return true
129
+ end
130
+
131
+ raise LoadError, "no such file to load -- #{file}"
132
+ end
133
+ end
134
+ private(:require)
135
+
136
+ def require_path_find file
137
+ $LOAD_PATH.each do |path|
138
+ test = File.expand_path(file,path)
139
+ return test if File.exist?(test)
140
+ end
141
+ return false
142
+ end
143
+ private(:require_path_find)
144
+ end
Binary file
@@ -0,0 +1,4 @@
1
+ # Test case for the extremely lazy
2
+ def did_it_work?
3
+ "yes"
4
+ end
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'ruby_archive'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,8 @@
1
+ require 'helper'
2
+
3
+ class TestRubyArchive < Test::Unit::TestCase
4
+ should "load the file from within the archive" do
5
+ require 'archive.zip!/does_it_work'
6
+ flunk "It didn't work" if did_it_work? != 'yes'
7
+ end
8
+ end
metadata ADDED
@@ -0,0 +1,104 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: ruby_archive
3
+ version: !ruby/object:Gem::Version
4
+ hash: 31
5
+ prerelease: false
6
+ segments:
7
+ - 0
8
+ - 1
9
+ - 2
10
+ version: 0.1.2
11
+ platform: ruby
12
+ authors:
13
+ - Jonathan Nielsen
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2010-09-03 00:00:00 -06:00
19
+ default_executable: rba_launch
20
+ dependencies:
21
+ - !ruby/object:Gem::Dependency
22
+ name: thoughtbot-shoulda
23
+ prerelease: false
24
+ requirement: &id001 !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ">="
28
+ - !ruby/object:Gem::Version
29
+ hash: 3
30
+ segments:
31
+ - 0
32
+ version: "0"
33
+ type: :development
34
+ version_requirements: *id001
35
+ description: Allows loading applications, libraries, and data from easily distributable archive files
36
+ email: jonathan@jmnet.us
37
+ executables:
38
+ - rba_launch
39
+ extensions: []
40
+
41
+ extra_rdoc_files:
42
+ - README.rdoc
43
+ - README.rubyzip
44
+ files:
45
+ - .document
46
+ - .gitignore
47
+ - README.rdoc
48
+ - README.rubyzip
49
+ - Rakefile
50
+ - bin/rba_launch
51
+ - lib/ruby_archive.rb
52
+ - lib/ruby_archive/handler.rb
53
+ - lib/ruby_archive/handlers/rubyzip/zip/ioextras.rb
54
+ - lib/ruby_archive/handlers/rubyzip/zip/stdrubyext.rb
55
+ - lib/ruby_archive/handlers/rubyzip/zip/tempfile_bugfixed.rb
56
+ - lib/ruby_archive/handlers/rubyzip/zip/zip.rb
57
+ - lib/ruby_archive/handlers/rubyzip/zip/zipfilesystem.rb
58
+ - lib/ruby_archive/handlers/zip_handler.rb
59
+ - lib/ruby_archive/patch.rb
60
+ - lib/ruby_archive/patch/dir.rb
61
+ - lib/ruby_archive/patch/file.rb
62
+ - lib/ruby_archive/patch/kernel.rb
63
+ - test/archive.zip
64
+ - test/does_it_work.rb
65
+ - test/helper.rb
66
+ - test/test_ruby_archive.rb
67
+ has_rdoc: true
68
+ homepage: http://github.com/byuni/ruby_archive
69
+ licenses: []
70
+
71
+ post_install_message:
72
+ rdoc_options:
73
+ - --charset=UTF-8
74
+ require_paths:
75
+ - lib
76
+ required_ruby_version: !ruby/object:Gem::Requirement
77
+ none: false
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ hash: 3
82
+ segments:
83
+ - 0
84
+ version: "0"
85
+ required_rubygems_version: !ruby/object:Gem::Requirement
86
+ none: false
87
+ requirements:
88
+ - - ">="
89
+ - !ruby/object:Gem::Version
90
+ hash: 3
91
+ segments:
92
+ - 0
93
+ version: "0"
94
+ requirements: []
95
+
96
+ rubyforge_project:
97
+ rubygems_version: 1.3.7
98
+ signing_key:
99
+ specification_version: 3
100
+ summary: Seamless access to ruby source and other files inside zip archives
101
+ test_files:
102
+ - test/helper.rb
103
+ - test/test_ruby_archive.rb
104
+ - test/does_it_work.rb