jrclj 1.0.0
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/lib/jrclj.rb +48 -0
- data/spec/jrclj_spec.rb +24 -0
- metadata +57 -0
data/lib/jrclj.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'java'
|
2
|
+
|
3
|
+
#Dir["#{File.dirname(__FILE__)}/*.jar"].each { |jar| puts "requiring: #{jar}"; require jar }
|
4
|
+
import "clojure.lang.RT"
|
5
|
+
|
6
|
+
class JRClj
|
7
|
+
def initialize *pkgs
|
8
|
+
@mappings = {}
|
9
|
+
@ns_map = RT.var "clojure.core", "ns-map"
|
10
|
+
@symbol = RT.var "clojure.core", "symbol"
|
11
|
+
@require = RT.var "clojure.core", "require"
|
12
|
+
_import "clojure.core"
|
13
|
+
pkgs.each do |pkg|
|
14
|
+
_import pkg
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def _import pkg_name, sym=nil, sym_alais=nil
|
19
|
+
@require.invoke @symbol.invoke(pkg_name)
|
20
|
+
if sym
|
21
|
+
sym_alias ||= sym
|
22
|
+
@mappings[sym_alias] = RT.var pkg_name, sym
|
23
|
+
return
|
24
|
+
end
|
25
|
+
pkg = @symbol.invoke pkg_name
|
26
|
+
@ns_map.invoke(pkg).each do |sym,var|
|
27
|
+
@mappings[sym.to_s] = var
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
def _invoke m, *args
|
32
|
+
fun = @mappings[m.to_s] || @mappings[m.to_s.gsub "_", "-"]
|
33
|
+
unless fun
|
34
|
+
raise "Error, no current binding for symbol=#{m}"
|
35
|
+
end
|
36
|
+
fun.invoke(*args)
|
37
|
+
end
|
38
|
+
|
39
|
+
def _alias new, old
|
40
|
+
@mappings[new] = @mappings[old]
|
41
|
+
end
|
42
|
+
|
43
|
+
def method_missing symbol, *args
|
44
|
+
_invoke symbol, *args
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
data/spec/jrclj_spec.rb
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require 'java'
|
2
|
+
$:.push "#{File.dirname(__FILE__)}/../lib"
|
3
|
+
require 'jrclj'
|
4
|
+
|
5
|
+
describe JRClj do
|
6
|
+
it "should support core functions" do
|
7
|
+
core = JRClj.new
|
8
|
+
core.+(3, 2).should == 5
|
9
|
+
core./(3, 2).should == 1.5
|
10
|
+
core.inc(2).should == 3
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should support loading other libraries (contrib)" do
|
14
|
+
str_utils = JRClj.new 'clojure.contrib.str-utils'
|
15
|
+
str_utils.str_join(":", [1,2,3]).should == "1:2:3"
|
16
|
+
end
|
17
|
+
|
18
|
+
it "should support calling weirdly named symbols via aliasing" do
|
19
|
+
clj_xpath = JRClj.new 'com.github.kyleburton.clj-xpath'
|
20
|
+
clj_xpath._alias "x_txt", "$x:text"
|
21
|
+
clj_xpath._invoke("$x:text", "//foo", "<foo>bar</foo>").should == "bar"
|
22
|
+
clj_xpath.x_txt("//foo", "<foo>bar</foo>").should == "bar"
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
3
|
+
requirements:
|
4
|
+
- - '>='
|
5
|
+
- !ruby/object:Gem::Version
|
6
|
+
version: "0"
|
7
|
+
version:
|
8
|
+
email: kyle.burton@gmail.com
|
9
|
+
cert_chain: []
|
10
|
+
|
11
|
+
summary: Bridge Library for working with Clojure from JRuby
|
12
|
+
post_install_message:
|
13
|
+
extra_rdoc_files: []
|
14
|
+
|
15
|
+
homepage: http://github.com/kyleburton/jrclj
|
16
|
+
signing_key:
|
17
|
+
name: jrclj
|
18
|
+
rdoc_options: []
|
19
|
+
|
20
|
+
rubyforge_project:
|
21
|
+
autorequire:
|
22
|
+
licenses: []
|
23
|
+
|
24
|
+
executables: []
|
25
|
+
|
26
|
+
description: |
|
27
|
+
Helper library for working with Clojure from JRuby.
|
28
|
+
specification_version: 3
|
29
|
+
default_executable:
|
30
|
+
files:
|
31
|
+
- lib/jrclj.rb
|
32
|
+
- spec/jrclj_spec.rb
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - '>='
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: "0"
|
38
|
+
version:
|
39
|
+
extensions: []
|
40
|
+
|
41
|
+
rubygems_version: 1.3.5
|
42
|
+
requirements: []
|
43
|
+
|
44
|
+
authors:
|
45
|
+
- Kyle Burton
|
46
|
+
date: 2010-03-07 05:00:00 +00:00
|
47
|
+
platform: ruby
|
48
|
+
test_files: []
|
49
|
+
|
50
|
+
version: !ruby/object:Gem::Version
|
51
|
+
version: 1.0.0
|
52
|
+
require_paths:
|
53
|
+
- lib
|
54
|
+
dependencies: []
|
55
|
+
|
56
|
+
bindir: bin
|
57
|
+
has_rdoc: true
|