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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: '059614bdb1345ea6768c1c3334626dbca0ffa61ff47ada76831fa6b91817ce8a'
4
- data.tar.gz: fb53cbccfa0d29bf3f5574fe6d4123b40118cff79161487c91409d4fc4070c60
3
+ metadata.gz: 33f00177f26d90bc4c9407bfb63860b7ef223f73545311fd26e0e64039f9da92
4
+ data.tar.gz: 6d5a5f91b1955e81607abb22c1704b36c3dbb9870a76fa6b26e494e19ccb3b4b
5
5
  SHA512:
6
- metadata.gz: b3503358f5bc3dee6f50ab5128b5b24fabb884852f2a7cf750861a7aa13ef5c2597be0eda3b40d562fd127afe1e44586efaecdce6223208421138269384f6818
7
- data.tar.gz: fbe2e25d299bfa1ab62c9afd9168d4b9ac609469c3613b830192810cff34ed55d4bdf84f8e4a2affa5194f20fcd71a0502e25c23feba46b4b7cdb3dcea0c1b9a
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) do
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(key)
43
- default = defaults[key]
41
+
42
+ def read_default_value(default)
44
43
  case default
45
44
  when Proc
46
45
  instance_exec(&default)
@@ -1,3 +1,3 @@
1
1
  module OptStruct
2
- VERSION = "1.0.3"
2
+ VERSION = "1.1.0"
3
3
  end
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.3
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: 2019-10-06 00:00:00.000000000 Z
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: