eac_ruby_utils 0.111.0 → 0.112.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a889ac2d4aac725fd91d963d4ca90a7179ae513c033edcd7c6f3bb4bfe73f0ce
4
- data.tar.gz: 46453cd0a6bc65f8f7b1533b6bcd7d70e52c75d9af0caffb2fcad84fcc90ccfb
3
+ metadata.gz: d4e72428fde957fae996836371e62fcae0017805944e1dff3c714500b4d3659c
4
+ data.tar.gz: b419f3b1fb13d82c37c6fa8fed357e0a9a16169318972bd3f57271e73a09d46b
5
5
  SHA512:
6
- metadata.gz: a47d0a6561ce05b2f973900271848ae78039697beda431d9981c491fec73a7c7efe0be2cf054d19a222ec4f7f4bb7a86eb8608406820ae82a6c942f49e0db2e4
7
- data.tar.gz: 9087ea886ee2d028a9701c45466d67d2cc450b6f1da6a301e65aca41bcf4d19a52a199342cb62806a953838d31be4c7a743a3ba206162e40b90a996fe4f44988
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
- apply_get(klass)
11
- apply_set(klass)
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 immutable_value_set(object, key, value)
19
- duplicate_object(object) do |old_value|
20
- (old_value || {}).merge(key => value)
21
- end
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 apply_get(klass)
32
+ def apply_plural(klass)
27
33
  accessor = self
28
- klass.send(:define_method, ::ActiveSupport::Inflector.pluralize(name)) do
29
- accessor.immutable_value_get(self)
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 apply_set(klass)
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.immutable_value_get(self, args[0])
38
- when 2 then next accessor.immutable_value_set(self, *args[0..1])
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module EacRubyUtils
4
- VERSION = '0.111.0'
4
+ VERSION = '0.112.0'
5
5
  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.111.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-20 00:00:00.000000000 Z
11
+ date: 2023-01-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport