opt_struct 1.4.0 → 1.5.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 +13 -8
- data/lib/opt_struct/instance_methods.rb +10 -13
- data/lib/opt_struct/version.rb +1 -1
- data/lib/opt_struct.rb +7 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 29701f52f41c942f328cc7a9303a72baa59d96cc1b0b8d9e803e9a80bac6aef3
|
4
|
+
data.tar.gz: 91c84c884b3a4ea3833db8c80083217efb8d942983aa0cb1072fd0b177c135b5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 27ceba23b7146f571232215d3228c59d9d6632e0628b694ded56fb8f308ad9257182c0f29edf41bbb9dc151570e5b855f40412ad066b33abfe042d18a3342344
|
7
|
+
data.tar.gz: 74f73309afd32192f9ea1b7d48f193e209f0e056381d20762001f57ec6b113387d11a8e9532a713b28855e2e052f210a8f0cff1df9b1c1319e8701934e9d0687
|
@@ -7,10 +7,22 @@ module OptStruct
|
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
|
+
def defined_keys
|
11
|
+
@defined_keys ||= []
|
12
|
+
end
|
13
|
+
|
10
14
|
def required_keys
|
11
15
|
@required_keys ||= []
|
12
16
|
end
|
13
17
|
|
18
|
+
def expected_arguments
|
19
|
+
@expected_arguments ||= []
|
20
|
+
end
|
21
|
+
|
22
|
+
def defaults
|
23
|
+
@defaults ||= {}
|
24
|
+
end
|
25
|
+
|
14
26
|
def required(*keys, **options)
|
15
27
|
required_keys.concat keys
|
16
28
|
option_accessor *keys, **options
|
@@ -33,6 +45,7 @@ module OptStruct
|
|
33
45
|
|
34
46
|
def option_accessor(*keys, **options)
|
35
47
|
check_reserved_words(keys)
|
48
|
+
defined_keys.concat keys
|
36
49
|
option_reader *keys, **options
|
37
50
|
option_writer *keys, **options
|
38
51
|
end
|
@@ -52,20 +65,12 @@ module OptStruct
|
|
52
65
|
end
|
53
66
|
end
|
54
67
|
|
55
|
-
def defaults
|
56
|
-
@defaults ||= {}
|
57
|
-
end
|
58
|
-
|
59
68
|
def expect_arguments(*arguments)
|
60
69
|
required(*arguments)
|
61
70
|
expected_arguments.concat(arguments)
|
62
71
|
end
|
63
72
|
alias_method :expect_argument, :expect_arguments
|
64
73
|
|
65
|
-
def expected_arguments
|
66
|
-
@expected_arguments ||= []
|
67
|
-
end
|
68
|
-
|
69
74
|
def init(meth = nil, &blk)
|
70
75
|
add_callback(:init, meth || blk)
|
71
76
|
end
|
@@ -29,27 +29,24 @@ module OptStruct
|
|
29
29
|
def assign_defaults
|
30
30
|
defaults.each do |key, default_value|
|
31
31
|
next if options.key?(key)
|
32
|
-
options[key] =
|
32
|
+
options[key] =
|
33
|
+
case default_value
|
34
|
+
when Proc
|
35
|
+
instance_exec(&default_value)
|
36
|
+
when Symbol
|
37
|
+
respond_to?(default_value) ? send(default_value) : default_value
|
38
|
+
else
|
39
|
+
default_value
|
40
|
+
end
|
33
41
|
end
|
34
42
|
end
|
35
43
|
|
36
44
|
def assign_arguments(args)
|
37
|
-
self.class.expected_arguments.
|
45
|
+
self.class.expected_arguments.each_with_index do |key, i|
|
38
46
|
options[key] = args[i] if args.length > i
|
39
47
|
end
|
40
48
|
end
|
41
49
|
|
42
|
-
def read_default_value(default)
|
43
|
-
case default
|
44
|
-
when Proc
|
45
|
-
instance_exec(&default)
|
46
|
-
when Symbol
|
47
|
-
respond_to?(default) ? send(default) : default
|
48
|
-
else
|
49
|
-
default
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
50
|
def with_init_callbacks(&init_block)
|
54
51
|
callbacks = self.class.all_callbacks
|
55
52
|
return yield if callbacks.nil? || callbacks.empty?
|
data/lib/opt_struct/version.rb
CHANGED
data/lib/opt_struct.rb
CHANGED
@@ -3,7 +3,13 @@ require "opt_struct/module_methods"
|
|
3
3
|
require "opt_struct/instance_methods"
|
4
4
|
|
5
5
|
module OptStruct
|
6
|
-
|
6
|
+
|
7
|
+
RESERVED_WORDS = [
|
8
|
+
:class, :options,
|
9
|
+
*OptStruct::InstanceMethods.instance_methods,
|
10
|
+
*OptStruct::InstanceMethods.protected_instance_methods,
|
11
|
+
*OptStruct::InstanceMethods.private_instance_methods,
|
12
|
+
].freeze
|
7
13
|
|
8
14
|
# Default value object allows us to distinguish unspecified defaults from nil
|
9
15
|
DEFAULT = Object.new
|
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.5.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: 2023-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Struct with support for keyword params and mixin support
|
14
14
|
email:
|
@@ -43,7 +43,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
43
43
|
- !ruby/object:Gem::Version
|
44
44
|
version: '0'
|
45
45
|
requirements: []
|
46
|
-
rubygems_version: 3.
|
46
|
+
rubygems_version: 3.2.33
|
47
47
|
signing_key:
|
48
48
|
specification_version: 4
|
49
49
|
summary: The Option Struct
|