with_ease 0.0.2 → 0.0.4
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
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5e01a06e7d3664b42c554856f9f14a424c739e15fa7463cb3afb59b975d71095
|
4
|
+
data.tar.gz: 9375604296c49a99b23e7b504ed0c98cff36a9c0269519294ab5bf815726ac21
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 52a5632e7e4de8255098a3b82dfe158b6bc518b7e3a64ecc69b39d186a7a15bca82b18ba6aea8b4d3afb80ee57e9470e49f4f4f8658a714e8152fcf8f0ba66a8
|
7
|
+
data.tar.gz: c9009ed9fd714345ffac18bf42a97a574ec5753939b4a2f48edc6068efe17d36e61f3b271b4d7140384b0ea4656251d5e1db9577500687618fdcad85d3a8ff9a
|
@@ -9,7 +9,7 @@ module WithEase
|
|
9
9
|
extend Forward
|
10
10
|
include HashApi
|
11
11
|
|
12
|
-
forward :deconstruct_keys, :fetch, :to_a, :to_h, to: :@data
|
12
|
+
forward :[], :[]=, :deconstruct_keys, :fetch, :to_a, :to_h, to: :@data
|
13
13
|
forward :deconstruct, to: :to_a
|
14
14
|
|
15
15
|
# def fetch(key, *defaults, &blk)
|
@@ -28,6 +28,12 @@ module WithEase
|
|
28
28
|
def initialize(**data, &blk)
|
29
29
|
@data = data.dup
|
30
30
|
@keys = Set.new(data.keys)
|
31
|
+
(class << self; self; end).module_eval do
|
32
|
+
data.each do |k,|
|
33
|
+
define_method k do @data.fetch(k) end
|
34
|
+
define_method "#{k}=" do |val| @data[k] = val end
|
35
|
+
end
|
36
|
+
end
|
31
37
|
end
|
32
38
|
|
33
39
|
end
|
@@ -6,5 +6,5 @@ require_relative 'open_struct'
|
|
6
6
|
|
7
7
|
def ClosedStruct(**k) = WithEase::ClosedStruct.new(**k)
|
8
8
|
def Iterator(init, &blk) = WithEase::Iterator.new(init, &blk)
|
9
|
-
def OpenStruct(**k) =
|
9
|
+
def OpenStruct(**k) = OpenStruct.new(**k)
|
10
10
|
# SPDX-License-Identifier: AGPL-3.0-or-later
|
@@ -16,15 +16,18 @@ module WithEase
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
def update(
|
19
|
+
def update(*positionals, **keys, &blk)
|
20
20
|
if blk
|
21
|
-
return _update_with_blk(
|
21
|
+
return _update_with_blk(*positionals, **keys, &blk)
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
case positionals
|
25
|
+
in []
|
26
|
+
_update(keys)
|
27
|
+
in [hash_like]
|
25
28
|
_update(hash_like.to_h.merge(**keys))
|
26
29
|
else
|
27
|
-
|
30
|
+
raise ArgumentError, "must not provide more than one postional argument"
|
28
31
|
end
|
29
32
|
end
|
30
33
|
|
@@ -47,10 +50,23 @@ module WithEase
|
|
47
50
|
self
|
48
51
|
end
|
49
52
|
|
50
|
-
def _update_with_blk(
|
51
|
-
|
52
|
-
|
53
|
-
|
53
|
+
def _update_with_blk(*positionals, **keys, &blk)
|
54
|
+
case positionals
|
55
|
+
in []
|
56
|
+
new_hash = to_h.update(**keys, &blk)
|
57
|
+
_update(new_hash)
|
58
|
+
in [key]
|
59
|
+
if keys.has_key?(:default)
|
60
|
+
value = fetch(key, keys.delete(:default))
|
61
|
+
raise ArgumentError, "only :default key is allowed with positional key" unless keys.empty?
|
62
|
+
_update(key => blk.(value))
|
63
|
+
else
|
64
|
+
value = fetch(key)
|
65
|
+
raise ArgumentError, "only :default key is allowed with positional key" unless keys.empty?
|
66
|
+
_update(key => blk.(value))
|
67
|
+
end
|
68
|
+
in [_, _, *]
|
69
|
+
end
|
54
70
|
end
|
55
71
|
end
|
56
72
|
end
|
data/lib/with_ease/version.rb
CHANGED