opt_struct 1.3.0 → 1.4.0
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 +3 -5
- data/lib/opt_struct/version.rb +1 -1
- data/lib/opt_struct.rb +3 -0
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 193867b718e2e264678a0ad084fc6ee5d76854203e74d13e6fc64404dfb042e8
|
4
|
+
data.tar.gz: b226650ae4b38741e70de40d8e0ffde6666f6e80f7b6735c316dfd303f74a435
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 16565e6596e06089f3cc463917af8ee13d573ad8ded530a39f121e3d4d2b1eb05b5b5e3bf308fe770750e7067adf06d08d72b0ef438ff939bdab4ef02605f2be
|
7
|
+
data.tar.gz: 942ccab03a688b1fc8b11db1d571d9cf6d8b96db49243120847f1083a7cb40bbdcedffdd38f252c483db395692f91f1dbfa275f2c876d159bcf2b5a230f533d2
|
@@ -37,9 +37,9 @@ module OptStruct
|
|
37
37
|
option_writer *keys, **options
|
38
38
|
end
|
39
39
|
|
40
|
-
def option(key, default =
|
40
|
+
def option(key, default = OptStruct::DEFAULT, required: false, **options)
|
41
41
|
default = options[:default] if options.key?(:default)
|
42
|
-
defaults[key] = default
|
42
|
+
defaults[key] = default unless default == OptStruct::DEFAULT
|
43
43
|
required_keys << key if required
|
44
44
|
option_accessor key, **options
|
45
45
|
end
|
@@ -91,11 +91,9 @@ module OptStruct
|
|
91
91
|
|
92
92
|
private
|
93
93
|
|
94
|
-
RESERVED_WORDS = %i(class defaults options fetch check_required_args check_required_keys)
|
95
|
-
|
96
94
|
def check_reserved_words(words)
|
97
95
|
Array(words).each do |word|
|
98
|
-
if RESERVED_WORDS.member?(word)
|
96
|
+
if OptStruct::RESERVED_WORDS.member?(word)
|
99
97
|
raise ArgumentError, "Use of reserved word is not permitted: #{word.inspect}"
|
100
98
|
end
|
101
99
|
end
|
data/lib/opt_struct/version.rb
CHANGED
data/lib/opt_struct.rb
CHANGED
@@ -5,6 +5,9 @@ require "opt_struct/instance_methods"
|
|
5
5
|
module OptStruct
|
6
6
|
RESERVED_WORDS = %i(class defaults options fetch check_required_args check_required_keys).freeze
|
7
7
|
|
8
|
+
# Default value object allows us to distinguish unspecified defaults from nil
|
9
|
+
DEFAULT = Object.new
|
10
|
+
|
8
11
|
def self._inject_struct(target, source, args = [], **defaults, &callback)
|
9
12
|
structs = Array(source.instance_variable_get(:@_opt_structs)).dup
|
10
13
|
if args.any? || defaults.any? || block_given?
|
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.
|
4
|
+
version: 1.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carl Zulauf
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2022-02-23 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Struct with support for keyword params and mixin support
|
14
14
|
email:
|
@@ -28,7 +28,7 @@ homepage: https://github.com/carlzulauf/opt_struct
|
|
28
28
|
licenses:
|
29
29
|
- MIT
|
30
30
|
metadata: {}
|
31
|
-
post_install_message:
|
31
|
+
post_install_message:
|
32
32
|
rdoc_options: []
|
33
33
|
require_paths:
|
34
34
|
- lib
|
@@ -43,8 +43,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
43
|
- !ruby/object:Gem::Version
|
44
44
|
version: '0'
|
45
45
|
requirements: []
|
46
|
-
rubygems_version: 3.
|
47
|
-
signing_key:
|
46
|
+
rubygems_version: 3.3.7
|
47
|
+
signing_key:
|
48
48
|
specification_version: 4
|
49
49
|
summary: The Option Struct
|
50
50
|
test_files: []
|