rujure 0.1.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.
- checksums.yaml +7 -0
- data/.gitignore +22 -0
- data/Gemfile +8 -0
- data/LICENSE.txt +22 -0
- data/README.md +65 -0
- data/Rakefile +11 -0
- data/lib/rujure.rb +72 -0
- data/lib/rujure/core.rb +7 -0
- data/lib/rujure/data.rb +7 -0
- data/lib/rujure/edn.rb +7 -0
- data/lib/rujure/helpers.rb +51 -0
- data/lib/rujure/inspector.rb +7 -0
- data/lib/rujure/instant.rb +7 -0
- data/lib/rujure/java.rb +9 -0
- data/lib/rujure/java/browse.rb +9 -0
- data/lib/rujure/java/io.rb +9 -0
- data/lib/rujure/java/javadoc.rb +9 -0
- data/lib/rujure/java/shell.rb +9 -0
- data/lib/rujure/main.rb +7 -0
- data/lib/rujure/objects/agent.rb +115 -0
- data/lib/rujure/objects/atom.rb +66 -0
- data/lib/rujure/pprint.rb +7 -0
- data/lib/rujure/proc_ifn.rb +20 -0
- data/lib/rujure/reflect.rb +7 -0
- data/lib/rujure/repl.rb +7 -0
- data/lib/rujure/set.rb +7 -0
- data/lib/rujure/stacktrace.rb +7 -0
- data/lib/rujure/string.rb +7 -0
- data/lib/rujure/template.rb +7 -0
- data/lib/rujure/test.rb +7 -0
- data/lib/rujure/version.rb +3 -0
- data/lib/rujure/walk.rb +7 -0
- data/lib/rujure/xml.rb +7 -0
- data/lib/rujure/zip.rb +7 -0
- data/rujure.gemspec +24 -0
- data/test/rujure/test_helpers.rb +109 -0
- data/test/rujure/test_rujure.rb +19 -0
- data/test/test_helper.rb +4 -0
- metadata +126 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: e505da01ee5ef07c3e36de7e147eca7e089518f9
|
4
|
+
data.tar.gz: a80a89049e26924ea3413729628bdf83d763d68e
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 73b447e96db70b15dcd8760a41b5d8e043299b3980ffdfded4e96ccc8bc169e03b6362eddec512314988d3303b5b6dd1a99efbedf2b47eb158c0df926d969877
|
7
|
+
data.tar.gz: a22018fd46672a87468ec3505399ecf7d9436200cdc6c588a3f7636b5538c102b19c9a15576c329867057e8635dc664812eefd2a5528213733f0bd409b9242f4
|
data/.gitignore
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
*.gem
|
2
|
+
*.rbc
|
3
|
+
.bundle
|
4
|
+
.config
|
5
|
+
.yardoc
|
6
|
+
Gemfile.lock
|
7
|
+
InstalledFiles
|
8
|
+
_yardoc
|
9
|
+
coverage
|
10
|
+
doc/
|
11
|
+
lib/bundler/man
|
12
|
+
pkg
|
13
|
+
rdoc
|
14
|
+
spec/reports
|
15
|
+
test/tmp
|
16
|
+
test/version_tmp
|
17
|
+
tmp
|
18
|
+
*.bundle
|
19
|
+
*.so
|
20
|
+
*.o
|
21
|
+
*.a
|
22
|
+
mkmf.log
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Stefan Huber
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Rujure
|
2
|
+
|
3
|
+
Rujure helps you to interoperate between Clojure and JRuby on JVM.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'rujure'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install rujure
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
### Calling single Clojure function
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
sort = Rujure.function 'clojure.core', 'sort'
|
25
|
+
sort.invoke([3, 2, 1]) # => [1, 2, 3]
|
26
|
+
```
|
27
|
+
|
28
|
+
### Including Clojure namespaces
|
29
|
+
|
30
|
+
```ruby
|
31
|
+
module IncludeAll
|
32
|
+
extend Rujure::Helpers
|
33
|
+
include_clojure_namespace 'clojure.core'
|
34
|
+
end
|
35
|
+
```
|
36
|
+
|
37
|
+
```ruby
|
38
|
+
module IncludeSome
|
39
|
+
extend Rujure::Helpers
|
40
|
+
include_clojure_namespace 'clojure.core', functions: %w(some string? swap! select-keys)
|
41
|
+
end
|
42
|
+
```
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
module IncludeWithoutAutoConversion
|
46
|
+
extend Rujure::Helpers
|
47
|
+
include_clojure_namespace 'clojure.core', auto_conversion: false
|
48
|
+
end
|
49
|
+
```
|
50
|
+
|
51
|
+
```ruby
|
52
|
+
module IncludeMultiple
|
53
|
+
extend Rujure::Helpers
|
54
|
+
include_clojure_namespace 'clojure.core', functions: %w(some)
|
55
|
+
include_clojure_namespace 'clojure.core', functions: %w(symbol), auto_conversion: false
|
56
|
+
end
|
57
|
+
```
|
58
|
+
|
59
|
+
## Contributing
|
60
|
+
|
61
|
+
1. Fork it ( https://github.com/msnexploder/rujure/fork )
|
62
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
63
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
64
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
65
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
data/lib/rujure.rb
ADDED
@@ -0,0 +1,72 @@
|
|
1
|
+
require 'rujure/version'
|
2
|
+
|
3
|
+
# check if clojure is available
|
4
|
+
begin
|
5
|
+
require 'java'
|
6
|
+
::Java::ClojureLang::Symbol
|
7
|
+
rescue NameError
|
8
|
+
begin
|
9
|
+
require 'clojure_jar'
|
10
|
+
rescue LoadError => e
|
11
|
+
raise unless e.message =~ /clojure_jar/
|
12
|
+
message = 'No Clojure jar found in your Java Classpath. You can fix this by adding the `clojure_jar` gem to your Application Gemfile.'
|
13
|
+
exception = e.exception(message)
|
14
|
+
exception.set_backtrace(e.backtrace)
|
15
|
+
raise exception
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
module Rujure
|
20
|
+
REQUIRE = ::Java::ClojureJavaApi::Clojure.var('clojure.core', 'require')
|
21
|
+
SYMBOL = ::Java::ClojureJavaApi::Clojure.var('clojure.core', 'symbol')
|
22
|
+
|
23
|
+
def self.function(namespace='clojure.core', name)
|
24
|
+
require(namespace)
|
25
|
+
::Java::ClojureJavaApi::Clojure.var(namespace.to_s, name.to_s)
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.read(name)
|
29
|
+
::Java::ClojureJavaApi::Clojure.read(name.to_s)
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.require(namespace)
|
33
|
+
namespace = namespace.to_s
|
34
|
+
unless loaded_namespaces.include?(namespace)
|
35
|
+
REQUIRE.invoke(SYMBOL.invoke(namespace))
|
36
|
+
loaded_namespaces << namespace
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
private
|
41
|
+
|
42
|
+
def self.loaded_namespaces
|
43
|
+
@loaded_namespaces ||= Set.new(['clojure.core']) # core is always loaded
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
require 'rujure/proc_ifn'
|
48
|
+
|
49
|
+
require 'rujure/helpers'
|
50
|
+
|
51
|
+
# Don't force loading everything Clojure provides
|
52
|
+
Rujure.autoload :Core, 'rujure/core'
|
53
|
+
Rujure.autoload :Data, 'rujure/data'
|
54
|
+
Rujure.autoload :Edn, 'rujure/edn'
|
55
|
+
Rujure.autoload :Inspector, 'rujure/inspector'
|
56
|
+
Rujure.autoload :Instant, 'rujure/instant'
|
57
|
+
Rujure.autoload :Java, 'rujure/java'
|
58
|
+
Rujure.autoload :Main, 'rujure/main'
|
59
|
+
Rujure.autoload :PPrint, 'rujure/pprint'
|
60
|
+
Rujure.autoload :Reflect, 'rujure/reflect'
|
61
|
+
Rujure.autoload :Repl, 'rujure/repl'
|
62
|
+
Rujure.autoload :Set, 'rujure/set'
|
63
|
+
Rujure.autoload :Stracktrace, 'rujure/stacktrace'
|
64
|
+
Rujure.autoload :String, 'rujure/string'
|
65
|
+
Rujure.autoload :Template, 'rujure/template'
|
66
|
+
Rujure.autoload :Test, 'rujure/test'
|
67
|
+
Rujure.autoload :Walk, 'rujure/walk'
|
68
|
+
Rujure.autoload :XML, 'rujure/xml'
|
69
|
+
Rujure.autoload :Zip, 'rujure/zip'
|
70
|
+
|
71
|
+
require 'rujure/objects/agent'
|
72
|
+
require 'rujure/objects/atom'
|
data/lib/rujure/core.rb
ADDED
data/lib/rujure/data.rb
ADDED
data/lib/rujure/edn.rb
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
module Rujure
|
2
|
+
module Helpers
|
3
|
+
def include_clojure_namespace(namespace, options={})
|
4
|
+
functions = options.fetch(:functions, nil)
|
5
|
+
auto_conversion = options.fetch(:auto_conversion, true)
|
6
|
+
|
7
|
+
Rujure.require(namespace)
|
8
|
+
NSPUBLICS.invoke(SYMBOL.invoke(namespace.to_s)).each do |function_name, function|
|
9
|
+
function_name = function_name.to_s
|
10
|
+
next if functions && !functions.include?(function_name)
|
11
|
+
method_name = function_name.gsub('-', '_')
|
12
|
+
|
13
|
+
if auto_conversion
|
14
|
+
define_method method_name do |*args|
|
15
|
+
arguments = Rujure::Helpers.handle_arguments(args)
|
16
|
+
value = function.invoke(*arguments)
|
17
|
+
Rujure::Helpers.handle_return_value(value)
|
18
|
+
end
|
19
|
+
else
|
20
|
+
define_method method_name do |*args|
|
21
|
+
function.invoke(*args)
|
22
|
+
end
|
23
|
+
end
|
24
|
+
module_function method_name
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
def self.handle_arguments(arguments)
|
29
|
+
arguments.map do |argument|
|
30
|
+
case argument
|
31
|
+
when ::Symbol then SYMBOL.invoke(argument.to_s)
|
32
|
+
when ::Proc then Rujure::ProcIFn.new(argument)
|
33
|
+
else argument
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.handle_return_value(value)
|
39
|
+
case value
|
40
|
+
when ::Java::ClojureLang::Symbol then value.to_s.to_sym
|
41
|
+
when Rujure::ProcIFn then value.proc
|
42
|
+
else value
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
private
|
47
|
+
|
48
|
+
NSPUBLICS = Rujure.function 'ns-publics'
|
49
|
+
SYMBOL = Rujure.function 'symbol'
|
50
|
+
end
|
51
|
+
end
|
data/lib/rujure/java.rb
ADDED
data/lib/rujure/main.rb
ADDED
@@ -0,0 +1,115 @@
|
|
1
|
+
module Rujure
|
2
|
+
module Objects
|
3
|
+
class Agent
|
4
|
+
AGENT = Rujure.function :agent
|
5
|
+
KEYWORD = Rujure.function :keyword
|
6
|
+
|
7
|
+
attr_reader :agent
|
8
|
+
|
9
|
+
shutdown_agents_function = Rujure.function('shutdown-agents')
|
10
|
+
define_singleton_method 'shutdown!' do
|
11
|
+
shutdown_agents_function.invoke()
|
12
|
+
end
|
13
|
+
|
14
|
+
def initialize(state, options=nil)
|
15
|
+
if options.nil?
|
16
|
+
@agent = AGENT.invoke(state)
|
17
|
+
else
|
18
|
+
@agent = AGENT.invoke(state, *transform_options(options))
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
deref_function = Rujure.function('deref')
|
23
|
+
define_method 'state' do
|
24
|
+
deref_function.invoke(agent)
|
25
|
+
end
|
26
|
+
|
27
|
+
agent_error_function = Rujure.function('agent-error')
|
28
|
+
define_method 'error' do
|
29
|
+
agent_error_function.invoke(agent)
|
30
|
+
end
|
31
|
+
|
32
|
+
%w(send send-off).each do |function_name|
|
33
|
+
method_name = function_name.sub('send', 'post').gsub('-', '_')
|
34
|
+
function = Rujure.function(function_name)
|
35
|
+
define_method method_name do |*args, &block|
|
36
|
+
function.invoke(agent, ProcIFn.new(block), *args)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
await_function = Rujure.function('await')
|
41
|
+
define_method 'await' do
|
42
|
+
await_function.invoke(agent)
|
43
|
+
end
|
44
|
+
|
45
|
+
await_for_function = Rujure.function('await-for')
|
46
|
+
define_method 'await_for' do |timeout|
|
47
|
+
await_for_function.invoke((timeout * 1000.0), agent)
|
48
|
+
end
|
49
|
+
|
50
|
+
get_validator_function = Rujure.function('get-validator')
|
51
|
+
define_method 'validator' do
|
52
|
+
validator = get_validator_function.invoke(agent)
|
53
|
+
validator.is_a?(ProcIFn) ? validator.proc : validator
|
54
|
+
end
|
55
|
+
|
56
|
+
set_validator_function = Rujure.function('set-validator!')
|
57
|
+
define_method 'validator=' do |&block|
|
58
|
+
set_validator_function.invoke(agent, ProcIFn.new(block))
|
59
|
+
end
|
60
|
+
|
61
|
+
error_handler_function = Rujure.function('error-handler')
|
62
|
+
define_method 'error_handler' do
|
63
|
+
handler = error_handler_function.invoke(agent)
|
64
|
+
handler.is_a?(ProcIFn) ? handler.proc : handler
|
65
|
+
end
|
66
|
+
|
67
|
+
set_error_handler_function = Rujure.function('set-error-handler!')
|
68
|
+
define_method 'error_handler=' do |&block|
|
69
|
+
set_error_handler_function.invoke(agent, ProcIFn.new(block))
|
70
|
+
end
|
71
|
+
|
72
|
+
error_mode_function = Rujure.function('error-mode')
|
73
|
+
define_method 'error_mode' do
|
74
|
+
mode = error_mode_function.invoke(agent)
|
75
|
+
mode ? mode.to_s.to_sym : mode
|
76
|
+
end
|
77
|
+
|
78
|
+
set_error_mode_function = Rujure.function('set-error-mode!')
|
79
|
+
define_method 'error_mode=' do |mode|
|
80
|
+
set_error_mode_function.invoke(agent, KEYWORD.invoke(mode.to_s))
|
81
|
+
end
|
82
|
+
|
83
|
+
add_watch_function = Rujure.function('add-watch')
|
84
|
+
define_method 'add_observer' do |key, &block|
|
85
|
+
add_watch_function.invoke(agent, key, ProcIFn.new(block))
|
86
|
+
end
|
87
|
+
|
88
|
+
remove_watch_function = Rujure.function('remove-watch')
|
89
|
+
define_method 'remove_observer' do |key|
|
90
|
+
remove_watch_function.invoke(agent, key)
|
91
|
+
end
|
92
|
+
|
93
|
+
restart_agent_function = Rujure.function('restart-agent')
|
94
|
+
define_method 'restart' do |state, options=nil|
|
95
|
+
if options.nil?
|
96
|
+
restart_agent_function.invoke(state)
|
97
|
+
else
|
98
|
+
restart_agent_function.invoke(state, *transform_options(options))
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
at_exit {
|
103
|
+
Rujure::Objects::Agent.shutdown!
|
104
|
+
}
|
105
|
+
|
106
|
+
private
|
107
|
+
|
108
|
+
def transform_options(options)
|
109
|
+
keys = options.keys.map { |k| KEYWORD.invoke(k.to_s) }
|
110
|
+
values = options.values.map { |v| v.is_a?(::Proc) ? Rujure::ProcIFn.new(v) : v }
|
111
|
+
keys.zip(values).flatten
|
112
|
+
end
|
113
|
+
end
|
114
|
+
end
|
115
|
+
end
|
@@ -0,0 +1,66 @@
|
|
1
|
+
module Rujure
|
2
|
+
module Objects
|
3
|
+
class Atom
|
4
|
+
ATOM = Rujure.function :atom
|
5
|
+
KEYWORD = Rujure.function :keyword
|
6
|
+
|
7
|
+
attr_reader :atom
|
8
|
+
|
9
|
+
def initialize(value, options=nil)
|
10
|
+
if options.nil?
|
11
|
+
@atom = ATOM.invoke(value)
|
12
|
+
else
|
13
|
+
@atom = ATOM.invoke(value, *transform_options(options))
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
deref_function = Rujure.function('deref')
|
18
|
+
define_method 'value' do |timeout=nil, timeout_val=nil|
|
19
|
+
if timeout.nil?
|
20
|
+
deref_function.invoke(atom)
|
21
|
+
else
|
22
|
+
deref_function.invoke(atom, (timeout * 1000.0), timeout_val)
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
swap_function = Rujure.function('swap!')
|
27
|
+
define_method 'swap!' do |*args, &block|
|
28
|
+
swap_function.invoke(atom, ProcIFn.new(block), *args)
|
29
|
+
end
|
30
|
+
|
31
|
+
compare_and_set_function = Rujure.function('compare-and-set!')
|
32
|
+
define_method 'compare_and_set!' do |oldval, newval|
|
33
|
+
compare_and_set_function.invoke(atom, oldval, newval)
|
34
|
+
end
|
35
|
+
|
36
|
+
get_validator_function = Rujure.function('get-validator')
|
37
|
+
define_method 'validator' do
|
38
|
+
validator = get_validator_function.invoke(atom)
|
39
|
+
validator.is_a?(ProcIFn) ? validator.proc : validator
|
40
|
+
end
|
41
|
+
|
42
|
+
set_validator_function = Rujure.function('set-validator!')
|
43
|
+
define_method 'validator=' do |&block|
|
44
|
+
set_validator_function.invoke(atom, ProcIFn.new(block))
|
45
|
+
end
|
46
|
+
|
47
|
+
add_watch_function = Rujure.function('add-watch')
|
48
|
+
define_method 'add_observer' do |key, &block|
|
49
|
+
add_watch_function.invoke(atom, key, ProcIFn.new(block))
|
50
|
+
end
|
51
|
+
|
52
|
+
remove_watch_function = Rujure.function('remove-watch')
|
53
|
+
define_method 'remove_observer' do |key|
|
54
|
+
remove_watch_function.invoke(atom, key)
|
55
|
+
end
|
56
|
+
|
57
|
+
private
|
58
|
+
|
59
|
+
def transform_options(options)
|
60
|
+
keys = options.keys.map { |k| KEYWORD.invoke(k.to_s) }
|
61
|
+
values = options.values.map { |v| v.is_a?(::Proc) ? Rujure::ProcIFn.new(v) : v }
|
62
|
+
keys.zip(values).flatten
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
66
|
+
end
|
@@ -0,0 +1,20 @@
|
|
1
|
+
module Rujure
|
2
|
+
class ProcIFn
|
3
|
+
include Java::ClojureLang::IFn
|
4
|
+
include Java::JavaUtil::Comparator
|
5
|
+
|
6
|
+
attr_reader :proc
|
7
|
+
|
8
|
+
def initialize(proc)
|
9
|
+
@proc = proc
|
10
|
+
end
|
11
|
+
|
12
|
+
def invoke(*args)
|
13
|
+
proc.call *args
|
14
|
+
end
|
15
|
+
|
16
|
+
def compare(o1, o2)
|
17
|
+
proc.call o1, o2
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
data/lib/rujure/repl.rb
ADDED
data/lib/rujure/set.rb
ADDED
data/lib/rujure/test.rb
ADDED
data/lib/rujure/walk.rb
ADDED
data/lib/rujure/xml.rb
ADDED
data/lib/rujure/zip.rb
ADDED
data/rujure.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'rujure/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "rujure"
|
8
|
+
spec.version = Rujure::VERSION
|
9
|
+
spec.authors = ["Stefan Huber"]
|
10
|
+
spec.email = ["MSNexploder@gmail.com"]
|
11
|
+
spec.summary = "JRuby - Clojure interop"
|
12
|
+
spec.description = "Call your Clojure using JRuby"
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_development_dependency "bundler", "~> 1.6.1"
|
22
|
+
spec.add_development_dependency "rake", "~> 10.3.1"
|
23
|
+
spec.add_development_dependency "minitest", "~> 5.3.3"
|
24
|
+
end
|
@@ -0,0 +1,109 @@
|
|
1
|
+
require File.expand_path('../test_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe Rujure::Helpers do
|
4
|
+
module IncludeAll
|
5
|
+
extend Rujure::Helpers
|
6
|
+
include_clojure_namespace 'clojure.core'
|
7
|
+
end
|
8
|
+
|
9
|
+
module IncludeSome
|
10
|
+
extend Rujure::Helpers
|
11
|
+
include_clojure_namespace 'clojure.core', functions: %w(some string? swap! select-keys)
|
12
|
+
end
|
13
|
+
|
14
|
+
module IncludeWithAutoConversion
|
15
|
+
extend Rujure::Helpers
|
16
|
+
include_clojure_namespace 'clojure.core', auto_conversion: true
|
17
|
+
end
|
18
|
+
|
19
|
+
module IncludeWithoutAutoConversion
|
20
|
+
extend Rujure::Helpers
|
21
|
+
include_clojure_namespace 'clojure.core', auto_conversion: false
|
22
|
+
end
|
23
|
+
|
24
|
+
module IncludeMultiple
|
25
|
+
extend Rujure::Helpers
|
26
|
+
include_clojure_namespace 'clojure.core', functions: %w(some)
|
27
|
+
include_clojure_namespace 'clojure.core', functions: %w(symbol), auto_conversion: false
|
28
|
+
end
|
29
|
+
|
30
|
+
it "includes all functions from a clojure namespace" do
|
31
|
+
assert_respond_to IncludeAll, :some
|
32
|
+
assert_respond_to IncludeAll, :list
|
33
|
+
end
|
34
|
+
|
35
|
+
it "includes predicate functions" do
|
36
|
+
assert_respond_to IncludeAll, :string?
|
37
|
+
assert_respond_to IncludeAll, :satisfies?
|
38
|
+
end
|
39
|
+
|
40
|
+
it "includes bang functions" do
|
41
|
+
assert_respond_to IncludeAll, :swap!
|
42
|
+
assert_respond_to IncludeAll, :alter_meta!
|
43
|
+
end
|
44
|
+
|
45
|
+
it "translates hypens into unterscores" do
|
46
|
+
assert_respond_to IncludeAll, :select_keys
|
47
|
+
assert_respond_to IncludeAll, :remove_watch
|
48
|
+
end
|
49
|
+
|
50
|
+
it "includes a subset functions from a clojure namespace" do
|
51
|
+
assert_respond_to IncludeSome, :some
|
52
|
+
refute_respond_to IncludeSome, :list
|
53
|
+
end
|
54
|
+
|
55
|
+
it "includes a subset of predicate functions" do
|
56
|
+
assert_respond_to IncludeSome, :string?
|
57
|
+
refute_respond_to IncludeSome, :satisfies?
|
58
|
+
end
|
59
|
+
|
60
|
+
it "includes a subset of bang functions" do
|
61
|
+
assert_respond_to IncludeSome, :swap!
|
62
|
+
refute_respond_to IncludeSome, :alter_meta!
|
63
|
+
end
|
64
|
+
|
65
|
+
it "translates hypens into unterscores for a subset of functions" do
|
66
|
+
assert_respond_to IncludeSome, :select_keys
|
67
|
+
refute_respond_to IncludeSome, :remove_watch
|
68
|
+
end
|
69
|
+
|
70
|
+
it "automatically converts procs" do
|
71
|
+
proc = Proc.new { |x| x > 2 }
|
72
|
+
assert IncludeWithAutoConversion.some(proc, [1, 2, 3])
|
73
|
+
end
|
74
|
+
|
75
|
+
it "automatically converts symbols" do
|
76
|
+
assert_equal :foo, IncludeWithAutoConversion.symbol(:foo)
|
77
|
+
end
|
78
|
+
|
79
|
+
it "auto conversions defaults to true" do
|
80
|
+
assert_equal :foo, IncludeAll.symbol(:foo)
|
81
|
+
end
|
82
|
+
|
83
|
+
it "does not convert procs if auto conversions is false" do
|
84
|
+
proc = Proc.new { |x| x > 2 }
|
85
|
+
assert_raises(Java::JavaLang::ClassCastException) {
|
86
|
+
IncludeWithoutAutoConversion.some(proc, [1, 2, 3])
|
87
|
+
}
|
88
|
+
end
|
89
|
+
|
90
|
+
it "does not convert symbols if auto conversions is false" do
|
91
|
+
assert_raises(Java::JavaLang::ClassCastException) {
|
92
|
+
IncludeWithoutAutoConversion.symbol(:foo)
|
93
|
+
}
|
94
|
+
end
|
95
|
+
|
96
|
+
it "includes all methods from multiple calls" do
|
97
|
+
assert_respond_to IncludeMultiple, :some
|
98
|
+
assert_respond_to IncludeMultiple, :symbol
|
99
|
+
refute_respond_to IncludeMultiple, :remove_watch
|
100
|
+
end
|
101
|
+
|
102
|
+
it "multiple includes honor conversion settings" do
|
103
|
+
proc = Proc.new { |x| x > 2 }
|
104
|
+
assert IncludeMultiple.some(proc, [1, 2, 3])
|
105
|
+
assert_raises(Java::JavaLang::ClassCastException) {
|
106
|
+
IncludeMultiple.symbol(:foo)
|
107
|
+
}
|
108
|
+
end
|
109
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require File.expand_path('../test_helper', File.dirname(__FILE__))
|
2
|
+
|
3
|
+
describe Rujure do
|
4
|
+
it "returns a clojure function" do
|
5
|
+
sort = Rujure.function 'clojure.core', 'sort'
|
6
|
+
refute_nil sort
|
7
|
+
assert_equal [1, 2, 3], sort.invoke([3, 2, 1])
|
8
|
+
end
|
9
|
+
|
10
|
+
it "returns a clojure function from default namespace" do
|
11
|
+
sort = Rujure.function 'sort'
|
12
|
+
refute_nil sort
|
13
|
+
assert_equal [1, 2, 3], sort.invoke([3, 2, 1])
|
14
|
+
end
|
15
|
+
|
16
|
+
it "returns a non-core clojure function" do
|
17
|
+
refute_nil Rujure.function('clojure.set', 'join')
|
18
|
+
end
|
19
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,126 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: rujure
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Stefan Huber
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-04-23 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: bundler
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: 1.6.1
|
20
|
+
type: :development
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: 1.6.1
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: rake
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: 10.3.1
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: 10.3.1
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: 5.3.3
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: 5.3.3
|
55
|
+
description: Call your Clojure using JRuby
|
56
|
+
email:
|
57
|
+
- MSNexploder@gmail.com
|
58
|
+
executables: []
|
59
|
+
extensions: []
|
60
|
+
extra_rdoc_files: []
|
61
|
+
files:
|
62
|
+
- ".gitignore"
|
63
|
+
- Gemfile
|
64
|
+
- LICENSE.txt
|
65
|
+
- README.md
|
66
|
+
- Rakefile
|
67
|
+
- lib/rujure.rb
|
68
|
+
- lib/rujure/core.rb
|
69
|
+
- lib/rujure/data.rb
|
70
|
+
- lib/rujure/edn.rb
|
71
|
+
- lib/rujure/helpers.rb
|
72
|
+
- lib/rujure/inspector.rb
|
73
|
+
- lib/rujure/instant.rb
|
74
|
+
- lib/rujure/java.rb
|
75
|
+
- lib/rujure/java/browse.rb
|
76
|
+
- lib/rujure/java/io.rb
|
77
|
+
- lib/rujure/java/javadoc.rb
|
78
|
+
- lib/rujure/java/shell.rb
|
79
|
+
- lib/rujure/main.rb
|
80
|
+
- lib/rujure/objects/agent.rb
|
81
|
+
- lib/rujure/objects/atom.rb
|
82
|
+
- lib/rujure/pprint.rb
|
83
|
+
- lib/rujure/proc_ifn.rb
|
84
|
+
- lib/rujure/reflect.rb
|
85
|
+
- lib/rujure/repl.rb
|
86
|
+
- lib/rujure/set.rb
|
87
|
+
- lib/rujure/stacktrace.rb
|
88
|
+
- lib/rujure/string.rb
|
89
|
+
- lib/rujure/template.rb
|
90
|
+
- lib/rujure/test.rb
|
91
|
+
- lib/rujure/version.rb
|
92
|
+
- lib/rujure/walk.rb
|
93
|
+
- lib/rujure/xml.rb
|
94
|
+
- lib/rujure/zip.rb
|
95
|
+
- rujure.gemspec
|
96
|
+
- test/rujure/test_helpers.rb
|
97
|
+
- test/rujure/test_rujure.rb
|
98
|
+
- test/test_helper.rb
|
99
|
+
homepage: ''
|
100
|
+
licenses:
|
101
|
+
- MIT
|
102
|
+
metadata: {}
|
103
|
+
post_install_message:
|
104
|
+
rdoc_options: []
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
requirements:
|
109
|
+
- - ">="
|
110
|
+
- !ruby/object:Gem::Version
|
111
|
+
version: '0'
|
112
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
113
|
+
requirements:
|
114
|
+
- - ">="
|
115
|
+
- !ruby/object:Gem::Version
|
116
|
+
version: '0'
|
117
|
+
requirements: []
|
118
|
+
rubyforge_project:
|
119
|
+
rubygems_version: 2.2.2
|
120
|
+
signing_key:
|
121
|
+
specification_version: 4
|
122
|
+
summary: JRuby - Clojure interop
|
123
|
+
test_files:
|
124
|
+
- test/rujure/test_helpers.rb
|
125
|
+
- test/rujure/test_rujure.rb
|
126
|
+
- test/test_helper.rb
|