zweikopf 0.0.4 → 0.0.5
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/README.md +54 -4
- data/lib/zweikopf/array.rb +4 -4
- data/lib/zweikopf/version.rb +1 -1
- metadata +103 -99
data/README.md
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
# Zweihopf, a two-headed JVM friend of yours.
|
|
2
|
+
[](http://travis-ci.org/ifesdjeen/zweikopf)
|
|
2
3
|
|
|
3
4
|
Zweikopf helps you to interoperate between Clojure and JRuby on JVM.
|
|
4
5
|
|
|
@@ -16,16 +17,65 @@ Or install it yourself as:
|
|
|
16
17
|
|
|
17
18
|
$ gem install zweikopf
|
|
18
19
|
|
|
20
|
+
## Usage
|
|
21
|
+
|
|
22
|
+
Transfroming from Clojure entities to Ruby ones is as easy as:
|
|
23
|
+
|
|
24
|
+
```ruby
|
|
25
|
+
# Say you have a variable clojure_var that is a Clojure Hash: {:a 1 :b 2}
|
|
26
|
+
Zweikopf::Transformer.from_clj(clojure_var)
|
|
27
|
+
# => {:a => 1, :b => 2}
|
|
28
|
+
|
|
29
|
+
# Or an array: [1 2 3 4 5]
|
|
30
|
+
Zweikopf::Transformer.from_clj(clojure_var)
|
|
31
|
+
# => [1, 2, 3, 4, 5]
|
|
32
|
+
|
|
33
|
+
# Or something really wicked: {:a 1 :b {:c [{:d 2} {:e 3} {:f 4}]}}
|
|
34
|
+
Zweikopf::Transformer.from_clj(clojure_var)
|
|
35
|
+
# => {:a => 1, :b => {:c => [{:d => 2}, {:e => 3}, { :f => 4}]}}
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
And backwards:
|
|
39
|
+
|
|
40
|
+
```ruby
|
|
41
|
+
# Say you have a variable ruby_var that is a Ruby Hash: {:a => 1, :b => 2}
|
|
42
|
+
Zweikopf::Transformer.from_ruby(ruby_var)
|
|
43
|
+
# => {:a 1 :b 2}
|
|
44
|
+
|
|
45
|
+
# Or an array: [1, 2, 3, 4, 5]
|
|
46
|
+
Zweikopf::Transformer.from_ruby(ruby_var)
|
|
47
|
+
# => [1 2 3 4 5]
|
|
48
|
+
|
|
49
|
+
# Or something really wicked: {:a => 1, :b => {:c => [{:d => 2}, {:e => 3}, { :f => 4}]}}
|
|
50
|
+
Zweikopf::Transformer.from_ruby(ruby_var)
|
|
51
|
+
# => {:a 1 :b {:c [{:d 2} {:e 3} {:f 4}]}}
|
|
52
|
+
```
|
|
53
|
+
|
|
54
|
+
When performing Ruby to Clojure transformation, you may leave out some space for customization:
|
|
55
|
+
|
|
56
|
+
```ruby
|
|
57
|
+
class CustomTransformedEntry
|
|
58
|
+
def serializable_hash
|
|
59
|
+
{:c => 3, :d => 4}
|
|
60
|
+
end
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
Zweikopf::Transformer.from_ruby({:a => 1, :b => CustomTransformedEntry.new }) do |v|
|
|
64
|
+
if v.is_a?(CustomTransformedEntry)
|
|
65
|
+
v.serializable_hash
|
|
66
|
+
else
|
|
67
|
+
v
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
# => {:a 1 :b {:c 3 :d 4}}
|
|
71
|
+
```
|
|
72
|
+
|
|
19
73
|
# Performance
|
|
20
74
|
|
|
21
75
|
## Conversion from Ruby hash to Clojure PersistentHash Map
|
|
22
76
|
|
|
23
77
|
Most of time 52% according to the rough estimate is spent while converting from ruby Symbol to clojure Keyword.
|
|
24
78
|
|
|
25
|
-
## Usage
|
|
26
|
-
|
|
27
|
-
TODO: Write usage instructions here
|
|
28
|
-
|
|
29
79
|
## Contributing
|
|
30
80
|
|
|
31
81
|
1. Fork it
|
data/lib/zweikopf/array.rb
CHANGED
|
@@ -3,16 +3,16 @@ java_import "clojure.lang.PersistentVector"
|
|
|
3
3
|
module Zweikopf
|
|
4
4
|
module Array
|
|
5
5
|
|
|
6
|
-
def self.from_ruby(arr)
|
|
6
|
+
def self.from_ruby(arr, &block)
|
|
7
7
|
PersistentVector.create(arr.inject([]) do |acc, v|
|
|
8
|
-
acc<< Zweikopf::Transformer.from_ruby(v)
|
|
8
|
+
acc<< Zweikopf::Transformer.from_ruby(v, &block)
|
|
9
9
|
end)
|
|
10
10
|
end # to_persistent_vector
|
|
11
11
|
|
|
12
|
-
def self.from_clj(clj_arr)
|
|
12
|
+
def self.from_clj(clj_arr, &block)
|
|
13
13
|
[].tap do |ruby_arr|
|
|
14
14
|
clj_arr.each do |v|
|
|
15
|
-
ruby_arr<< Zweikopf::Transformer.from_clj(v);
|
|
15
|
+
ruby_arr<< Zweikopf::Transformer.from_clj(v, &block);
|
|
16
16
|
end
|
|
17
17
|
end
|
|
18
18
|
end # self.from_clj
|
data/lib/zweikopf/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,115 +1,119 @@
|
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: zweikopf
|
|
3
|
-
version: !ruby/object:Gem::Version
|
|
4
|
-
prerelease:
|
|
5
|
-
version: 0.0.
|
|
3
|
+
version: !ruby/object:Gem::Version
|
|
4
|
+
prerelease:
|
|
5
|
+
version: 0.0.5
|
|
6
6
|
platform: ruby
|
|
7
|
-
authors:
|
|
8
|
-
|
|
9
|
-
autorequire:
|
|
7
|
+
authors:
|
|
8
|
+
- Oleksandr Petrov
|
|
9
|
+
autorequire:
|
|
10
10
|
bindir: bin
|
|
11
11
|
cert_chain: []
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
12
|
+
date: 2012-09-24 00:00:00.000000000 Z
|
|
13
|
+
dependencies:
|
|
14
|
+
- !ruby/object:Gem::Dependency
|
|
15
|
+
name: rake
|
|
16
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
17
|
+
requirements:
|
|
18
|
+
- - ! '>='
|
|
19
|
+
- !ruby/object:Gem::Version
|
|
20
|
+
version: '0'
|
|
21
|
+
none: false
|
|
22
|
+
requirement: !ruby/object:Gem::Requirement
|
|
23
|
+
requirements:
|
|
24
|
+
- - ! '>='
|
|
25
|
+
- !ruby/object:Gem::Version
|
|
26
|
+
version: '0'
|
|
27
|
+
none: false
|
|
28
|
+
prerelease: false
|
|
29
|
+
type: :development
|
|
30
|
+
- !ruby/object:Gem::Dependency
|
|
31
|
+
name: rspec
|
|
32
|
+
version_requirements: !ruby/object:Gem::Requirement
|
|
33
|
+
requirements:
|
|
34
|
+
- - ! '>='
|
|
35
|
+
- !ruby/object:Gem::Version
|
|
36
|
+
version: '0'
|
|
37
|
+
none: false
|
|
38
|
+
requirement: !ruby/object:Gem::Requirement
|
|
39
|
+
requirements:
|
|
40
|
+
- - ! '>='
|
|
41
|
+
- !ruby/object:Gem::Version
|
|
42
|
+
version: '0'
|
|
43
|
+
none: false
|
|
44
|
+
prerelease: false
|
|
45
|
+
type: :development
|
|
37
46
|
description: Rubygem for jruby/clojure interop
|
|
38
|
-
email:
|
|
39
|
-
|
|
47
|
+
email:
|
|
48
|
+
- oleksandr.petrov@gmail.com
|
|
40
49
|
executables: []
|
|
41
|
-
|
|
42
50
|
extensions: []
|
|
43
|
-
|
|
44
51
|
extra_rdoc_files: []
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
homepage: ""
|
|
52
|
+
files:
|
|
53
|
+
- .gitignore
|
|
54
|
+
- .rspec
|
|
55
|
+
- .rvmrc
|
|
56
|
+
- .travis.yml
|
|
57
|
+
- Gemfile
|
|
58
|
+
- LICENSE
|
|
59
|
+
- README.md
|
|
60
|
+
- Rakefile
|
|
61
|
+
- deps/clojure-1.4.0.jar
|
|
62
|
+
- lib/zweikopf.rb
|
|
63
|
+
- lib/zweikopf/array.rb
|
|
64
|
+
- lib/zweikopf/hash.rb
|
|
65
|
+
- lib/zweikopf/keyword.rb
|
|
66
|
+
- lib/zweikopf/primitive.rb
|
|
67
|
+
- lib/zweikopf/transformer.rb
|
|
68
|
+
- lib/zweikopf/version.rb
|
|
69
|
+
- project.clj
|
|
70
|
+
- spec/fixtures/clj_array1.clj
|
|
71
|
+
- spec/fixtures/clj_deep_hash1.clj
|
|
72
|
+
- spec/fixtures/clj_hash1.clj
|
|
73
|
+
- spec/fixtures/complex_hash.clj
|
|
74
|
+
- spec/fixtures/empty_hash.clj
|
|
75
|
+
- spec/spec_helper.rb
|
|
76
|
+
- spec/support/loader.rb
|
|
77
|
+
- spec/zweikopf/performance_spec.rb
|
|
78
|
+
- spec/zweikopf/transformer_clojure_to_ruby_spec.rb
|
|
79
|
+
- spec/zweikopf/transformer_ruby_to_clojure_spec.rb
|
|
80
|
+
- src/zweikopf/core.clj
|
|
81
|
+
- test/zweikopf/core_test.clj
|
|
82
|
+
- zweikopf.gemspec
|
|
83
|
+
homepage: ''
|
|
78
84
|
licenses: []
|
|
79
|
-
|
|
80
|
-
post_install_message:
|
|
85
|
+
post_install_message:
|
|
81
86
|
rdoc_options: []
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
87
|
+
require_paths:
|
|
88
|
+
- lib
|
|
89
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
|
+
requirements:
|
|
91
|
+
- - ! '>='
|
|
92
|
+
- !ruby/object:Gem::Version
|
|
93
|
+
version: '0'
|
|
86
94
|
none: false
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
95
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
96
|
+
requirements:
|
|
97
|
+
- - ! '>='
|
|
98
|
+
- !ruby/object:Gem::Version
|
|
99
|
+
version: '0'
|
|
92
100
|
none: false
|
|
93
|
-
requirements:
|
|
94
|
-
- - ">="
|
|
95
|
-
- !ruby/object:Gem::Version
|
|
96
|
-
version: "0"
|
|
97
101
|
requirements: []
|
|
98
|
-
|
|
99
|
-
rubyforge_project:
|
|
102
|
+
rubyforge_project:
|
|
100
103
|
rubygems_version: 1.8.24
|
|
101
|
-
signing_key:
|
|
104
|
+
signing_key:
|
|
102
105
|
specification_version: 3
|
|
103
106
|
summary: Its good, try it out!
|
|
104
|
-
test_files:
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
107
|
+
test_files:
|
|
108
|
+
- spec/fixtures/clj_array1.clj
|
|
109
|
+
- spec/fixtures/clj_deep_hash1.clj
|
|
110
|
+
- spec/fixtures/clj_hash1.clj
|
|
111
|
+
- spec/fixtures/complex_hash.clj
|
|
112
|
+
- spec/fixtures/empty_hash.clj
|
|
113
|
+
- spec/spec_helper.rb
|
|
114
|
+
- spec/support/loader.rb
|
|
115
|
+
- spec/zweikopf/performance_spec.rb
|
|
116
|
+
- spec/zweikopf/transformer_clojure_to_ruby_spec.rb
|
|
117
|
+
- spec/zweikopf/transformer_ruby_to_clojure_spec.rb
|
|
118
|
+
- test/zweikopf/core_test.clj
|
|
119
|
+
...
|