opt_struct 1.7.0 → 1.8.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/README.md +4 -0
- data/lib/opt_struct/class_methods.rb +8 -3
- data/lib/opt_struct/instance_methods.rb +5 -1
- data/lib/opt_struct/version.rb +1 -1
- metadata +3 -6
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 4c47c60bff407dea977e1408716b9d47e0f4b05a16128734601ce2f6e4fbbe50
|
|
4
|
+
data.tar.gz: 10a2da04669533bafa82384ce79a43083202e0692a93956ef731efc0c5932963
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 344f1d25a46748a08c60650f706f4f50697324e6985c6d0c6d57aeb1d0de3cb1ec36f82313aac2d5eaf1733d116ed549818b1d9aa472d725cec88c2209b8e5b8
|
|
7
|
+
data.tar.gz: c763bced17752180653844b5d6893f477542fe913eceea3d0be084d7a78d1e8d23d94287302f494a743a1da502f04bf86746f0c1e94d9468fd50153c82377133
|
data/README.md
CHANGED
|
@@ -345,3 +345,7 @@ Available callbacks
|
|
|
345
345
|
## Inheritance, Expanded
|
|
346
346
|
|
|
347
347
|
See `spec/inheritance_spec.rb` for examples of just how crazy you can get.
|
|
348
|
+
|
|
349
|
+
## Ruby Versions
|
|
350
|
+
|
|
351
|
+
This gem is expected to work with rubies as old as ~2.0, though official support and automated testing only covers non-EOL (End of Life) versions. Currently, that's ruby 3.3+. Tests are also performed against jruby and truffleruby to ensure portability.
|
|
@@ -59,9 +59,14 @@ module OptStruct
|
|
|
59
59
|
option_writer *keys, **options
|
|
60
60
|
end
|
|
61
61
|
|
|
62
|
-
def option(key, default = OptStruct::DEFAULT, required: false, **options)
|
|
63
|
-
|
|
64
|
-
|
|
62
|
+
def option(key, default = OptStruct::DEFAULT, required: false, **options, &default_block)
|
|
63
|
+
if options.key?(:default)
|
|
64
|
+
defaults[key] = options[:default]
|
|
65
|
+
elsif default != OptStruct::DEFAULT
|
|
66
|
+
defaults[key] = default
|
|
67
|
+
elsif default_block
|
|
68
|
+
defaults[key] = default_block
|
|
69
|
+
end
|
|
65
70
|
required_keys << key if required
|
|
66
71
|
option_accessor key, **options
|
|
67
72
|
end
|
|
@@ -36,7 +36,11 @@ module OptStruct
|
|
|
36
36
|
options[key] =
|
|
37
37
|
case default_value
|
|
38
38
|
when Proc
|
|
39
|
-
|
|
39
|
+
if default_value.arity == 0
|
|
40
|
+
instance_exec(&default_value)
|
|
41
|
+
else
|
|
42
|
+
instance_exec(self, &default_value)
|
|
43
|
+
end
|
|
40
44
|
when Symbol
|
|
41
45
|
respond_to?(default_value, true) ? send(default_value) : default_value
|
|
42
46
|
else
|
data/lib/opt_struct/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: opt_struct
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.
|
|
4
|
+
version: 1.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Carl Zulauf
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
12
11
|
dependencies: []
|
|
13
12
|
description: Struct with support for keyword params and mixin support
|
|
14
13
|
email:
|
|
@@ -28,7 +27,6 @@ homepage: https://github.com/carlzulauf/opt_struct
|
|
|
28
27
|
licenses:
|
|
29
28
|
- MIT
|
|
30
29
|
metadata: {}
|
|
31
|
-
post_install_message:
|
|
32
30
|
rdoc_options: []
|
|
33
31
|
require_paths:
|
|
34
32
|
- lib
|
|
@@ -43,8 +41,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
43
41
|
- !ruby/object:Gem::Version
|
|
44
42
|
version: '0'
|
|
45
43
|
requirements: []
|
|
46
|
-
rubygems_version: 3.
|
|
47
|
-
signing_key:
|
|
44
|
+
rubygems_version: 3.7.2
|
|
48
45
|
specification_version: 4
|
|
49
46
|
summary: The Option Struct
|
|
50
47
|
test_files: []
|