opt_struct 1.0.3 → 1.1.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 +1 -7
- data/lib/opt_struct/instance_methods.rb +12 -13
- data/lib/opt_struct/version.rb +1 -1
- 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: 33f00177f26d90bc4c9407bfb63860b7ef223f73545311fd26e0e64039f9da92
|
4
|
+
data.tar.gz: 6d5a5f91b1955e81607abb22c1704b36c3dbb9870a76fa6b26e494e19ccb3b4b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e11a757d9319851bddcc69052076996d618fe2f281822abd281fcfa4cefda3a4d2cda3c424e9ef3882800f76ff7435ddc327f71bfab69742e8ca5dfae98e1003
|
7
|
+
data.tar.gz: f9174dce367fee3f1fea9bed17c8c004e1b6a8b73d4597e3bcb6bfb02d08d3e36b0b76e3bb0989d66e05983f4d895c6b4e0392a08555edf71887053548972782
|
@@ -18,13 +18,7 @@ module OptStruct
|
|
18
18
|
|
19
19
|
def option_reader(*keys)
|
20
20
|
keys.each do |key|
|
21
|
-
define_method(key)
|
22
|
-
if options.key?(key)
|
23
|
-
options[key]
|
24
|
-
elsif defaults.key?(key)
|
25
|
-
options[key] = read_default_value(key)
|
26
|
-
end
|
27
|
-
end
|
21
|
+
define_method(key) { options[key] }
|
28
22
|
end
|
29
23
|
end
|
30
24
|
|
@@ -4,6 +4,7 @@ module OptStruct
|
|
4
4
|
with_init_callbacks do
|
5
5
|
@options = options
|
6
6
|
assign_arguments(arguments)
|
7
|
+
assign_defaults
|
7
8
|
check_required_keys
|
8
9
|
end
|
9
10
|
end
|
@@ -24,23 +25,21 @@ module OptStruct
|
|
24
25
|
raise ArgumentError, "missing required keywords: #{missing.inspect}"
|
25
26
|
end
|
26
27
|
end
|
27
|
-
|
28
|
+
|
29
|
+
def assign_defaults
|
30
|
+
defaults.each do |key, default_value|
|
31
|
+
next if options.key?(key) # || default_value.nil?
|
32
|
+
options[key] = read_default_value(default_value)
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
28
36
|
def assign_arguments(args)
|
29
37
|
self.class.expected_arguments.map.with_index do |key, i|
|
30
|
-
if args.length > i
|
31
|
-
options[key] = args[i]
|
32
|
-
elsif !options.key?(key)
|
33
|
-
if defaults.key?(key)
|
34
|
-
options[key] = read_default_value(key)
|
35
|
-
else
|
36
|
-
raise ArgumentError, "missing required argument: #{key}"
|
37
|
-
end
|
38
|
-
end
|
38
|
+
options[key] = args[i] if args.length > i
|
39
39
|
end
|
40
40
|
end
|
41
|
-
|
42
|
-
def read_default_value(
|
43
|
-
default = defaults[key]
|
41
|
+
|
42
|
+
def read_default_value(default)
|
44
43
|
case default
|
45
44
|
when Proc
|
46
45
|
instance_exec(&default)
|
data/lib/opt_struct/version.rb
CHANGED
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.0
|
4
|
+
version: 1.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Carl Zulauf
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-01-09 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Struct with support for keyword params and mixin support
|
14
14
|
email:
|