rjb-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.
@@ -0,0 +1,22 @@
1
+ h1. Rjb.require
2
+
3
+ Adds the ability to import and map Java packages to nested Ruby modules/classes to RJB.
4
+
5
+ h2. Usage
6
+
7
+ <pre>
8
+ require 'rjb/require'
9
+
10
+ # java.net.URL is already in your classpath
11
+ Rjb.require 'java.net.URL'
12
+ Java::Net::URL.new('http://github.com')
13
+
14
+ # load some custom library
15
+ Rjb.load_from 'path/to/htmlunit' # loads all jar files to Rjb
16
+ Rjb.require 'com.gargoylesoftware.htmlunit.WebClient'
17
+ </pre>
18
+
19
+ h2. Authors
20
+
21
+ * Original Work: Richard L. Apodaca (see "Mapping Java Packages Onto Ruby Modules":http://depth-first.com/articles/2006/10/24/metaprogramming-with-ruby-mapping-java-packages-onto-ruby-modules)
22
+ * Modifications: Sven Fuchs (Ruby gem, RJB module level method, add RJB.load_from for convenience)
@@ -0,0 +1,29 @@
1
+ module Rjb
2
+ def self.load_from(path)
3
+ paths = Dir["#{Steam.config[:html_unit][:java_path]}/*.jar"]
4
+ load(paths.join(':')) unless paths.empty?
5
+ end
6
+
7
+ def self.require(qualified_class_name)
8
+ java_class = Rjb::import(qualified_class_name)
9
+ package_names = qualified_class_name.to_s.split('.')
10
+ class_name = package_names.delete(package_names.last)
11
+ target_module = Object
12
+
13
+ package_names.each do |package_name|
14
+ module_name = package_name.capitalize
15
+
16
+ if !target_module.const_defined?(module_name)
17
+ target_module = target_module.const_set(module_name, Module.new)
18
+ else
19
+ target_module = target_module.const_get(module_name)
20
+ end
21
+ end
22
+
23
+ if target_module.const_defined?(class_name)
24
+ false
25
+ else
26
+ target_module.const_set(class_name, java_class)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1 @@
1
+ require 'rjb/require'
@@ -0,0 +1,3 @@
1
+ module RjbRequire
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,67 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rjb-require
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
+ - Sven Fuchs
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-04-30 00:00:00 +02:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: Adds the ability to import and map Java packages to nested Ruby modules/classes to RJB. Based on http://bit.ly/aBLnei
22
+ email: svenfuchs@artweb-design.de
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - lib/rjb/require.rb
31
+ - lib/rjb_require/version.rb
32
+ - lib/rjb_require.rb
33
+ - README.textile
34
+ has_rdoc: true
35
+ homepage: http://github.com/svenfuchs/rjb-require
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 1
56
+ - 3
57
+ - 6
58
+ version: 1.3.6
59
+ requirements: []
60
+
61
+ rubyforge_project: "[none]"
62
+ rubygems_version: 1.3.6
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Adds the ability to import and map Java packages to nested Ruby modules/classes to RJB
66
+ test_files: []
67
+