eac_ruby_utils 0.111.0 → 0.112.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 +4 -4
- data/lib/eac_ruby_utils/immutable/hash_accessor.rb +23 -12
- data/lib/eac_ruby_utils/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4e72428fde957fae996836371e62fcae0017805944e1dff3c714500b4d3659c
|
4
|
+
data.tar.gz: b419f3b1fb13d82c37c6fa8fed357e0a9a16169318972bd3f57271e73a09d46b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de10ee898b6b0e23d17949b454e1a79e631170e2356926d03732f3ebe4dd29dac7768e5651fcd65aba3ac16c333681bf96ccda7e1b81bff0b3057d045e7ed2f1
|
7
|
+
data.tar.gz: c845230c38a3ad30c9d502978d1fea5fd144a8d34ca4a044f56479f26847a089256e94c7a0ec301b126ef236cbaf59fbdd12ccff783e0976e8fca90ca47e829c
|
@@ -7,35 +7,46 @@ module EacRubyUtils
|
|
7
7
|
module Immutable
|
8
8
|
class HashAccessor < ::EacRubyUtils::Immutable::BaseAccessor
|
9
9
|
def apply(klass)
|
10
|
-
|
11
|
-
|
10
|
+
apply_plural(klass)
|
11
|
+
apply_singular(klass)
|
12
12
|
end
|
13
13
|
|
14
14
|
def immutable_value_get(object)
|
15
15
|
super || {}
|
16
16
|
end
|
17
17
|
|
18
|
-
def
|
19
|
-
|
20
|
-
|
21
|
-
|
18
|
+
def immutable_value_get_single(object, key)
|
19
|
+
immutable_value_get(object)[key]
|
20
|
+
end
|
21
|
+
|
22
|
+
def immutable_value_set(object, new_hash)
|
23
|
+
duplicate_object(object) { |_old_value| new_hash }
|
24
|
+
end
|
25
|
+
|
26
|
+
def immutable_value_set_single(object, key, value)
|
27
|
+
immutable_value_set(object, immutable_value_get(object).merge(key => value))
|
22
28
|
end
|
23
29
|
|
24
30
|
private
|
25
31
|
|
26
|
-
def
|
32
|
+
def apply_plural(klass)
|
27
33
|
accessor = self
|
28
|
-
klass.send(:define_method, ::ActiveSupport::Inflector.pluralize(name)) do
|
29
|
-
|
34
|
+
klass.send(:define_method, ::ActiveSupport::Inflector.pluralize(name)) do |*args|
|
35
|
+
case args.count
|
36
|
+
when 0 then next accessor.immutable_value_get(self)
|
37
|
+
when 1 then next accessor.immutable_value_set(self, args[0])
|
38
|
+
else
|
39
|
+
raise ::ArgumentError, "wrong number of arguments (given #{args.count}, expected 0..1)"
|
40
|
+
end
|
30
41
|
end
|
31
42
|
end
|
32
43
|
|
33
|
-
def
|
44
|
+
def apply_singular(klass)
|
34
45
|
accessor = self
|
35
46
|
klass.send(:define_method, name) do |*args|
|
36
47
|
case args.count
|
37
|
-
when 1 then next accessor.
|
38
|
-
when 2 then next accessor.
|
48
|
+
when 1 then next accessor.immutable_value_get_single(self, args[0])
|
49
|
+
when 2 then next accessor.immutable_value_set_single(self, *args[0..1])
|
39
50
|
else
|
40
51
|
raise ::ArgumentError, "wrong number of arguments (given #{args.count}, expected 1..2)"
|
41
52
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eac_ruby_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.112.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Esquilo Azul Company
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-01-
|
11
|
+
date: 2023-01-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|