l43_open_object 0.1.1 → 0.2.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/l43/open_object.rb +10 -4
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9976c1247191d0a07f77df9ba0b986cd57412458c1167a7a8751f82c03fce094
|
4
|
+
data.tar.gz: d65d9275e3cdd6b756d913918310487764bb60cb8a43617183fbf7f020b3857c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: b280373d581088fc015c9d460dd806a5bfb0c3049cf274582453bccb53951523b95320bdef551e273ff00e5a04f50f0e47a964585438a7a29cd17c52cc94f9b1
|
7
|
+
data.tar.gz: 5aee83609062b79c9fa3947c1126c22a45351ba816dba24af83ba6779a9e77487d670feec520d01ec91a3a5a9ba2d29ecc8222369c83298368ed34af34d797a2
|
data/lib/l43/open_object.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module L43
|
4
4
|
module OpenObject
|
5
|
-
VERSION = "0.
|
5
|
+
VERSION = "0.2.0"
|
6
6
|
|
7
7
|
def attributes(*atts, **defaults)
|
8
8
|
attr_reader(*atts)
|
@@ -24,17 +24,23 @@ module L43
|
|
24
24
|
instance_variable_set("@#{key}", value)
|
25
25
|
end
|
26
26
|
_init if respond_to?(:_init)
|
27
|
+
freeze
|
27
28
|
end
|
28
29
|
|
29
30
|
define_method :to_h do |*|
|
30
31
|
first = atts.inject Hash.new do |h, attribute|
|
31
32
|
h.update(attribute => send(attribute))
|
32
33
|
end
|
33
|
-
|
34
|
-
|
35
|
-
|
34
|
+
defaults.keys.inject first do |h, attribute|
|
35
|
+
h.update(attribute => send(attribute))
|
36
|
+
end
|
36
37
|
end
|
37
38
|
alias_method :deconstruct_keys, :to_h
|
39
|
+
|
40
|
+
define_method :update do |**kwds|
|
41
|
+
new_values = to_h.merge(**kwds)
|
42
|
+
self.class.new(**new_values)
|
43
|
+
end
|
38
44
|
end
|
39
45
|
end
|
40
46
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: l43_open_object
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Robert Dober
|
@@ -13,7 +13,9 @@ dependencies: []
|
|
13
13
|
description: |-
|
14
14
|
When using the class method `attributes` in a class you get:
|
15
15
|
- an initialize method with attributes as kwd params and the respective defaults
|
16
|
+
- immutable instances
|
16
17
|
- a to_h method using all attributes
|
18
|
+
- an update method to create new imutable instances
|
17
19
|
- a destruct_keys method aliased to to_h for pattern matching
|
18
20
|
email: robert.dober@gmail.com
|
19
21
|
executables: []
|