opt_struct 1.5.0 → 1.5.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/opt_struct/class_methods.rb +5 -3
- data/lib/opt_struct/module_methods.rb +1 -0
- data/lib/opt_struct/version.rb +1 -1
- data/lib/opt_struct.rb +12 -2
- 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: 3513e52f9bdf75f5c2f2b59e2718b3de30cbc5e9720bd6d7b8e22eb3d23975a8
|
4
|
+
data.tar.gz: '0851dbb6109b9eb2b191ae709ae08d47562e457f8dd1375084194aef3d8d00bb'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 40875af1558cbe95e6715d58d3dfa100f268d103a5fa1269ccbb7dcca7c2cf23b7670ff1303f5f51d6ce292320f37c7878339c7811ac810ce57ee6fa30777f2a
|
7
|
+
data.tar.gz: 576629818aa2c778194587112b7965182b53b36f346a9606f518d969a57c646d0d60edf5772537600b575d1b6452c10ef5fe28b163d33ceede2e07d99427e862
|
@@ -1,10 +1,12 @@
|
|
1
1
|
module OptStruct
|
2
2
|
module ClassMethods
|
3
3
|
def inherited(subclass)
|
4
|
-
|
5
|
-
|
6
|
-
|
4
|
+
# intersection of defined vars and the ones we care about
|
5
|
+
(instance_variables & OptStruct::CLASS_IVARS).each do |ivar|
|
6
|
+
# copy them to the child class
|
7
|
+
subclass.send(:instance_variable_set, ivar, instance_variable_get(ivar).dup)
|
7
8
|
end
|
9
|
+
super(subclass)
|
8
10
|
end
|
9
11
|
|
10
12
|
def defined_keys
|
data/lib/opt_struct/version.rb
CHANGED
data/lib/opt_struct.rb
CHANGED
@@ -11,15 +11,25 @@ module OptStruct
|
|
11
11
|
*OptStruct::InstanceMethods.private_instance_methods,
|
12
12
|
].freeze
|
13
13
|
|
14
|
+
# list of class instance variables defined/tracked by opt_struct
|
15
|
+
CLASS_IVARS = %i[
|
16
|
+
@defined_keys @required_keys @expected_arguments @defaults
|
17
|
+
@_callbacks @_opt_structs
|
18
|
+
]
|
19
|
+
|
14
20
|
# Default value object allows us to distinguish unspecified defaults from nil
|
15
21
|
DEFAULT = Object.new
|
16
22
|
|
17
23
|
def self._inject_struct(target, source, args = [], **defaults, &callback)
|
18
|
-
|
24
|
+
existing = source.instance_variable_get(:@_opt_structs)
|
25
|
+
structs = Array(existing).dup
|
26
|
+
|
19
27
|
if args.any? || defaults.any? || block_given?
|
20
28
|
structs << [args, defaults, callback]
|
21
29
|
end
|
22
|
-
|
30
|
+
|
31
|
+
target.instance_variable_set(:@_opt_structs, structs) if existing || structs.any?
|
32
|
+
|
23
33
|
if target.is_a?(Class)
|
24
34
|
target.instance_exec do
|
25
35
|
extend ClassMethods
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: opt_struct
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.5.
|
4
|
+
version: 1.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carl Zulauf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-08-
|
11
|
+
date: 2023-08-31 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Struct with support for keyword params and mixin support
|
14
14
|
email:
|