sin_deep_merge 0.0.0-java
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
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: cb2a5d755e5e2a44c834aa2a976bf90c189f5201c8c0aeff5b9e25c4412500a8
|
4
|
+
data.tar.gz: 2daa683b076bdb1a67b805295f109300692c95684e6ce7da11074cb5419b92cb
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 066aef355c6f16aa9cd62c2f0866f23357b5d9c3b839cd2620a3f7d67da6bad2babaa0046197d9974ffef67b1ec4f23ae2624e4797383108c97440a086dad526
|
7
|
+
data.tar.gz: 42ea77e45b314a5b2d3b97c0ee51a43335d00bc6da39f005ccf52754f410dbaaf1dfd94caf10b78a6a06c2c3f4f08f612b2c4ac5db0379af7ab0f9874c0a25cb
|
@@ -0,0 +1,56 @@
|
|
1
|
+
package sin_deep_merge;
|
2
|
+
|
3
|
+
import org.jruby.Ruby;
|
4
|
+
import org.jruby.RubyHash;
|
5
|
+
import org.jruby.anno.JRubyMethod;
|
6
|
+
import org.jruby.runtime.Block;
|
7
|
+
import org.jruby.runtime.ThreadContext;
|
8
|
+
import org.jruby.runtime.builtin.IRubyObject;
|
9
|
+
import org.jruby.runtime.load.Library;
|
10
|
+
|
11
|
+
public class SinDeepMergeLibrary implements Library {
|
12
|
+
@Override
|
13
|
+
public void load(Ruby runtime, boolean wrap) {
|
14
|
+
runtime.getHash().defineAnnotatedMethods(SinDeepMergeLibrary.class);
|
15
|
+
}
|
16
|
+
|
17
|
+
@JRubyMethod(name = "deep_merge", required = 1)
|
18
|
+
public static IRubyObject deepMerge(ThreadContext context, IRubyObject self, IRubyObject other, Block block) {
|
19
|
+
RubyHash selfHash = self.convertToHash();
|
20
|
+
RubyHash dupedHash = (RubyHash) selfHash.dup();
|
21
|
+
RubyHash otherHash = other.convertToHash();
|
22
|
+
deepMergeHashes(context, dupedHash, otherHash, block);
|
23
|
+
return dupedHash;
|
24
|
+
}
|
25
|
+
|
26
|
+
@JRubyMethod(name = "deep_merge!", required = 1)
|
27
|
+
public static IRubyObject deepMergeBang(ThreadContext context, IRubyObject self, IRubyObject other, Block block) {
|
28
|
+
RubyHash selfHash = self.convertToHash();
|
29
|
+
RubyHash otherHash = other.convertToHash();
|
30
|
+
deepMergeHashes(context, selfHash, otherHash, block);
|
31
|
+
return selfHash;
|
32
|
+
}
|
33
|
+
|
34
|
+
private static void deepMergeHashes(ThreadContext context, RubyHash self, RubyHash other, Block block) {
|
35
|
+
for (Object k : other.keySet()) {
|
36
|
+
IRubyObject key = (IRubyObject) k;
|
37
|
+
IRubyObject currentVal = self.op_aref(context, key);
|
38
|
+
IRubyObject otherVal = other.op_aref(context, key);
|
39
|
+
|
40
|
+
if (currentVal.isNil()) {
|
41
|
+
self.op_aset(context, key, otherVal);
|
42
|
+
} else if (currentVal instanceof RubyHash && otherVal instanceof RubyHash) {
|
43
|
+
RubyHash currentHash = (RubyHash) currentVal;
|
44
|
+
currentHash = (RubyHash) currentHash.dup();
|
45
|
+
RubyHash otherHash = (RubyHash) otherVal;
|
46
|
+
deepMergeHashes(context, currentHash, otherHash, block);
|
47
|
+
self.op_aset(context, key, currentHash);
|
48
|
+
} else if (block.isGiven()) {
|
49
|
+
IRubyObject result = block.call(context, new IRubyObject[] { key, currentVal, otherVal });
|
50
|
+
self.op_aset(context, key, result);
|
51
|
+
} else {
|
52
|
+
self.op_aset(context, key, otherVal);
|
53
|
+
}
|
54
|
+
}
|
55
|
+
}
|
56
|
+
}
|
Binary file
|
metadata
ADDED
@@ -0,0 +1,54 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: sin_deep_merge
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.0
|
5
|
+
platform: java
|
6
|
+
authors:
|
7
|
+
- Masahiro
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2025-03-10 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Ruby extension library for up to 2x faster deep merging of Hash objects
|
14
|
+
than ActiveSupport.
|
15
|
+
email:
|
16
|
+
- watanabe@cadenza-tech.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- ext/java/sin_deep_merge/SinDeepMergeLibrary.java
|
22
|
+
- lib/sin_deep_merge/sin_deep_merge.jar
|
23
|
+
homepage: https://github.com/cadenza-tech/sin_deep_merge/tree/v0.0.0
|
24
|
+
licenses:
|
25
|
+
- MIT
|
26
|
+
metadata:
|
27
|
+
homepage_uri: https://github.com/cadenza-tech/sin_deep_merge/tree/v0.0.0
|
28
|
+
source_code_uri: https://github.com/cadenza-tech/sin_deep_merge/tree/v0.0.0
|
29
|
+
changelog_uri: https://github.com/cadenza-tech/sin_deep_merge/blob/v0.0.0/CHANGELOG.md
|
30
|
+
bug_tracker_uri: https://github.com/cadenza-tech/sin_deep_merge/issues
|
31
|
+
documentation_uri: https://rubydoc.info/gems/sin_deep_merge/0.0.0
|
32
|
+
funding_uri: https://patreon.com/CadenzaTech
|
33
|
+
rubygems_mfa_required: 'true'
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: 2.3.0
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
requirements: []
|
49
|
+
rubygems_version: 3.2.33
|
50
|
+
signing_key:
|
51
|
+
specification_version: 4
|
52
|
+
summary: Ruby extension library for up to 2x faster deep merging of Hash objects than
|
53
|
+
ActiveSupport.
|
54
|
+
test_files: []
|