astrails-http_require 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.
- data/LICENSE +20 -0
- data/README.markdown +20 -0
- data/VERSION.yml +4 -0
- data/lib/http_require.rb +41 -0
- metadata +58 -0
data/LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Vitaly Kushner
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.markdown
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
= http_require
|
2
|
+
|
3
|
+
The idea is very simple:
|
4
|
+
require "http://foo.com/bar.rb" # <= this will download bar.rb and eval its
|
5
|
+
content.
|
6
|
+
|
7
|
+
If a remote file (or one of its local dependencies) requires something that
|
8
|
+
can't be found locally, it will try to find it remotely from the same location
|
9
|
+
as the parent.
|
10
|
+
|
11
|
+
For example:
|
12
|
+
|
13
|
+
require 'http://example.com/test/foo.rb"
|
14
|
+
|
|
15
|
+
+====> require 'foo/bar' <== this will load 'http://example.com/test/foo/bar.rb"
|
16
|
+
if 'foo/bar' is not available locally
|
17
|
+
|
18
|
+
== Copyright
|
19
|
+
|
20
|
+
Copyright (c) 2009 Vitaly Kushner. See LICENSE for details.
|
data/VERSION.yml
ADDED
data/lib/http_require.rb
ADDED
@@ -0,0 +1,41 @@
|
|
1
|
+
require 'open-uri'
|
2
|
+
|
3
|
+
module Kernel
|
4
|
+
|
5
|
+
class HttpLoadError < LoadError; end
|
6
|
+
|
7
|
+
@@http_require_base = nil
|
8
|
+
def with_http_require_base(base)
|
9
|
+
base, @http_require_base = @http_require_base, base
|
10
|
+
yield
|
11
|
+
ensure
|
12
|
+
@http_require_base = base
|
13
|
+
end
|
14
|
+
|
15
|
+
def http_require(path)
|
16
|
+
uri = path.is_a?(URI) ? path : URI.parse(path)
|
17
|
+
|
18
|
+
content = uri.read
|
19
|
+
|
20
|
+
with_http_require_base(File.dirname(uri.to_s)) do
|
21
|
+
eval(content, binding, uri.to_s)
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
|
26
|
+
alias :require_without_http :require
|
27
|
+
def require(path)
|
28
|
+
uri = URI.parse(path) rescue nil
|
29
|
+
return http_require(uri) if uri.is_a?(URI) && (uri.class != URI::Generic)
|
30
|
+
|
31
|
+
require_without_http(path)
|
32
|
+
|
33
|
+
rescue LoadError => e
|
34
|
+
if @http_require_base
|
35
|
+
path += ".rb" unless path[-3..-1] == ".rb"
|
36
|
+
http_require "#{@http_require_base}/#{path}"
|
37
|
+
else
|
38
|
+
raise e
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: astrails-http_require
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Vitaly Kushner
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-05-12 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: vitaly@astrails.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.markdown
|
24
|
+
- LICENSE
|
25
|
+
files:
|
26
|
+
- README.markdown
|
27
|
+
- VERSION.yml
|
28
|
+
- lib/http_require.rb
|
29
|
+
- LICENSE
|
30
|
+
has_rdoc: true
|
31
|
+
homepage: http://github.com/astrails/http_require
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options:
|
34
|
+
- --inline-source
|
35
|
+
- --charset=UTF-8
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: "0"
|
43
|
+
version:
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
version:
|
50
|
+
requirements: []
|
51
|
+
|
52
|
+
rubyforge_project:
|
53
|
+
rubygems_version: 1.2.0
|
54
|
+
signing_key:
|
55
|
+
specification_version: 2
|
56
|
+
summary: allows you to require "http://foo/bar.rb"
|
57
|
+
test_files: []
|
58
|
+
|