l43_open_object 0.1.0 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/lib/l43/open_object.rb +12 -5
  3. data/lib/l43.rb +4 -0
  4. metadata +5 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 8266d0945c81a03a6902408c89ebcd5041d7cf4638966953e19472fe34000666
4
- data.tar.gz: 2e840ffdacf43598be767a6d7480decfba0689ca993a674a764219ab3e4ec996
3
+ metadata.gz: 9976c1247191d0a07f77df9ba0b986cd57412458c1167a7a8751f82c03fce094
4
+ data.tar.gz: d65d9275e3cdd6b756d913918310487764bb60cb8a43617183fbf7f020b3857c
5
5
  SHA512:
6
- metadata.gz: ebb1e47640c197641912776ad07751bfaa3e070a6955b79cd9ab1a31f4200ce9799b0c605cfb9ca02faa91f33863b73aed5703c5fa5fbefb3a4ef2e41bf3c181
7
- data.tar.gz: 8e5dd764d310b6f31f44d77e316769aa20a8910f709b09d9ce56f2178fa146b402476a386d858a09aaa48a8f4ec425121248f292dadbd18321287f7890718cd6
6
+ metadata.gz: b280373d581088fc015c9d460dd806a5bfb0c3049cf274582453bccb53951523b95320bdef551e273ff00e5a04f50f0e47a964585438a7a29cd17c52cc94f9b1
7
+ data.tar.gz: 5aee83609062b79c9fa3947c1126c22a45351ba816dba24af83ba6779a9e77487d670feec520d01ec91a3a5a9ba2d29ecc8222369c83298368ed34af34d797a2
@@ -2,14 +2,15 @@
2
2
 
3
3
  module L43
4
4
  module OpenObject
5
- VERSION = "0.1.0"
5
+ VERSION = "0.2.0"
6
6
 
7
7
  def attributes(*atts, **defaults)
8
8
  attr_reader(*atts)
9
9
  attr_reader(*defaults.keys)
10
10
 
11
11
  define_method :== do |other|
12
- other&.to_h == to_h
12
+ return false unless self.class === other
13
+ other.to_h == to_h
13
14
  end
14
15
 
15
16
  define_method :initialize do |**kwds|
@@ -23,17 +24,23 @@ module L43
23
24
  instance_variable_set("@#{key}", value)
24
25
  end
25
26
  _init if respond_to?(:_init)
27
+ freeze
26
28
  end
27
29
 
28
30
  define_method :to_h do |*|
29
31
  first = atts.inject Hash.new do |h, attribute|
30
32
  h.update(attribute => send(attribute))
31
33
  end
32
- defaults.keys.inject first do |h, attribute|
33
- h.update(attribute => send(attribute))
34
- end
34
+ defaults.keys.inject first do |h, attribute|
35
+ h.update(attribute => send(attribute))
36
+ end
35
37
  end
36
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
37
44
  end
38
45
  end
39
46
  end
data/lib/l43.rb ADDED
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'l43/open_object'
4
+ # SPDX-License-Identifier: AGPL-3.0-or-later
metadata CHANGED
@@ -1,19 +1,21 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: l43_open_object
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Dober
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-24 00:00:00.000000000 Z
11
+ date: 2024-04-25 00:00:00.000000000 Z
12
12
  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: []
@@ -21,6 +23,7 @@ extensions: []
21
23
  extra_rdoc_files: []
22
24
  files:
23
25
  - LICENSE
26
+ - lib/l43.rb
24
27
  - lib/l43/open_object.rb
25
28
  homepage: https://codeberg.org/lab419/l43_open_object
26
29
  licenses: