striuct 0.6.1 → 0.9.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/MIT-LICENSE.txt +21 -0
- data/README.md +44 -60
- data/lib/striuct/{requirements.rb → bootstrap.rb} +6 -2
- data/lib/striuct/classmethods/README.md +2 -2
- data/lib/striuct/classmethods/adjustment.rb +77 -13
- data/lib/striuct/classmethods/attributes.rb +94 -92
- data/lib/striuct/classmethods/conflict_management.rb +109 -106
- data/lib/striuct/classmethods/constructor.rb +55 -65
- data/lib/striuct/classmethods/copy.rb +45 -43
- data/lib/striuct/classmethods/default.rb +23 -21
- data/lib/striuct/classmethods/enum.rb +46 -44
- data/lib/striuct/classmethods/fix.rb +23 -21
- data/lib/striuct/classmethods/hashdeepdupulicatable.rb +15 -15
- data/lib/striuct/classmethods/inner.rb +57 -55
- data/lib/striuct/classmethods/length.rb +12 -10
- data/lib/striuct/classmethods/macro.rb +99 -106
- data/lib/striuct/classmethods/names.rb +69 -65
- data/lib/striuct/classmethods/predicate.rb +131 -129
- data/lib/striuct/classmethods/requirements.rb +2 -2
- data/lib/striuct/classmethods/to_struct.rb +21 -18
- data/lib/striuct/classmethods/validation.rb +15 -13
- data/lib/striuct/instancemethods/README.md +2 -2
- data/lib/striuct/instancemethods/assign.rb +29 -27
- data/lib/striuct/instancemethods/cast.rb +28 -26
- data/lib/striuct/instancemethods/compare.rb +26 -24
- data/lib/striuct/instancemethods/default.rb +31 -29
- data/lib/striuct/instancemethods/delegate_class_methods.rb +35 -33
- data/lib/striuct/instancemethods/enum.rb +86 -84
- data/lib/striuct/instancemethods/getter.rb +39 -37
- data/lib/striuct/instancemethods/hashy.rb +99 -97
- data/lib/striuct/instancemethods/lock.rb +46 -44
- data/lib/striuct/instancemethods/object.rb +50 -48
- data/lib/striuct/instancemethods/requirements.rb +9 -13
- data/lib/striuct/instancemethods/safety.rb +11 -9
- data/lib/striuct/instancemethods/setter.rb +46 -45
- data/lib/striuct/instancemethods/to_s.rb +39 -37
- data/lib/striuct/instancemethods/validation.rb +46 -29
- data/lib/striuct/instancemethods/values.rb +50 -48
- data/lib/striuct/singleton_class.rb +25 -18
- data/lib/striuct/structs.rb +3 -3
- data/lib/striuct.rb +7 -3
- metadata +18 -209
- data/.gitignore +0 -35
- data/.travis.yml +0 -17
- data/.yardopts +0 -1
- data/Gemfile +0 -11
- data/MIT-LICENSE +0 -22
- data/Rakefile +0 -11
- data/benchmark/basics.rb +0 -56
- data/example/README.rb +0 -50
- data/example/example1.rb +0 -195
- data/example/example2.rb +0 -20
- data/example/see_trace.rb +0 -32
- data/lib/striuct/instancemethods/keyvalidatable.rb +0 -9
- data/striuct.gemspec +0 -45
- data/test/helper.rb +0 -3
- data/test/test_sglc-constructor.rb +0 -36
- data/test/test_subc-c-add_members.rb +0 -13
- data/test/test_subc-c-close_member.rb +0 -36
- data/test/test_subc-c-constructor.rb +0 -92
- data/test/test_subc-c-copy.rb +0 -71
- data/test/test_subc-c-freeze.rb +0 -36
- data/test/test_subc-c-inheritable.rb +0 -58
- data/test/test_subc-c-safety_naming.rb +0 -73
- data/test/test_subc-f-alias_member.rb +0 -54
- data/test/test_subc-f-enum.rb +0 -159
- data/test/test_subc-f-predicate.rb +0 -647
- data/test/test_subc-f-to_struct.rb +0 -61
- data/test/test_subc-f-validation_util.rb +0 -59
- data/test/test_subc-f_debug.rb +0 -39
- data/test/test_subc-f_name.rb +0 -525
- data/test/test_subc-i-accessor.rb +0 -138
- data/test/test_subc-i-adjuster.rb +0 -95
- data/test/test_subc-i-assign.rb +0 -53
- data/test/test_subc-i-basic.rb +0 -43
- data/test/test_subc-i-cast.rb +0 -27
- data/test/test_subc-i-compare.rb +0 -52
- data/test/test_subc-i-copy.rb +0 -23
- data/test/test_subc-i-default_value.rb +0 -129
- data/test/test_subc-i-freeze.rb +0 -19
- data/test/test_subc-i-hashlike.rb +0 -144
- data/test/test_subc-i-keyvalidatable.rb +0 -25
- data/test/test_subc-i-lock.rb +0 -40
- data/test/test_subc-i-must.rb +0 -30
- data/test/test_subc-i-to_s_family.rb +0 -26
- data/test/test_subc-i-validation_specific_conditions.rb +0 -297
- data/test/test_subc-i-validation_with_getter.rb +0 -33
- data/test/test_version.rb +0 -13
@@ -1,130 +1,132 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
@
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Striuct
|
4
|
+
module ClassMethods
|
5
|
+
# @group Basic Predicate
|
6
|
+
|
7
|
+
# @param [Symbol, String, #to_sym] name
|
8
|
+
def has_autonym?(name)
|
9
|
+
name = name.to_sym
|
10
|
+
rescue NoMethodError
|
11
|
+
false
|
12
|
+
else
|
13
|
+
@autonyms.include?(name)
|
14
|
+
end
|
15
|
+
|
16
|
+
alias_method :autonym?, :has_autonym?
|
17
|
+
|
18
|
+
# @param [Symbol, String, #to_sym] als
|
19
|
+
def has_alias?(als)
|
20
|
+
als = als.to_sym
|
21
|
+
rescue NoMethodError
|
22
|
+
false
|
23
|
+
else
|
24
|
+
@aliases.key?(als)
|
25
|
+
end
|
26
|
+
|
27
|
+
alias_method :alias?, :has_alias?
|
28
|
+
alias_method :aliased?, :has_alias? # obsolete
|
29
|
+
|
30
|
+
# @param [Symbol, String, #to_sym] name
|
31
|
+
def has_member?(name)
|
32
|
+
autonym_for_member(name)
|
33
|
+
rescue Exception
|
34
|
+
false
|
35
|
+
else
|
36
|
+
true
|
37
|
+
end
|
38
|
+
|
39
|
+
alias_method :member?, :has_member?
|
40
|
+
|
41
|
+
# @param [Integer, #to_int] index
|
42
|
+
def has_index?(index)
|
43
|
+
@autonyms.fetch(index)
|
44
|
+
rescue Exception
|
45
|
+
false
|
46
|
+
else
|
47
|
+
true
|
48
|
+
end
|
49
|
+
|
50
|
+
alias_method :index?, :has_index?
|
51
|
+
|
52
|
+
# @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
|
53
|
+
def has_key?(key)
|
54
|
+
has_member?(key) || has_index?(key)
|
55
|
+
end
|
56
|
+
|
57
|
+
alias_method :key?, :has_key?
|
58
|
+
|
59
|
+
# @param [Symbol, String, #to_sym] autonym
|
60
|
+
def with_aliases?(autonym)
|
61
|
+
autonym = autonym.to_sym
|
62
|
+
rescue NoMethodError
|
63
|
+
false
|
64
|
+
else
|
65
|
+
@aliases.value?(autonym)
|
66
|
+
end
|
67
|
+
|
68
|
+
# @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
|
69
|
+
def with_default?(key)
|
70
|
+
autonym = autonym_for_key(key)
|
71
|
+
rescue Exception
|
72
|
+
false
|
73
|
+
else
|
74
|
+
_attributes_for(autonym).with_default?
|
75
|
+
end
|
76
|
+
|
77
|
+
# @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
|
78
|
+
def with_condition?(key)
|
79
|
+
autonym = autonym_for_key(key)
|
80
|
+
rescue Exception
|
81
|
+
false
|
82
|
+
else
|
83
|
+
_attributes_for(autonym).with_condition?
|
84
|
+
end
|
85
|
+
|
86
|
+
alias_method :restrict?, :with_condition?
|
87
|
+
|
88
|
+
# @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
|
89
|
+
def with_must?(key)
|
90
|
+
autonym = autonym_for_key(key)
|
91
|
+
rescue Exception
|
92
|
+
false
|
93
|
+
else
|
94
|
+
_attributes_for(autonym).with_must?
|
95
|
+
end
|
96
|
+
|
97
|
+
alias_method :must?, :with_must?
|
98
|
+
|
99
|
+
# @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
|
100
|
+
def with_safety_getter?(key)
|
101
|
+
autonym = autonym_for_key(key)
|
102
|
+
rescue Exception
|
103
|
+
false
|
104
|
+
else
|
105
|
+
_attributes_for(autonym).with_safety_getter?
|
106
|
+
end
|
107
|
+
|
108
|
+
alias_method :with_safety_reader?, :with_safety_getter?
|
109
|
+
|
110
|
+
# @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
|
111
|
+
def with_safety_setter?(key)
|
112
|
+
autonym = autonym_for_key(key)
|
113
|
+
rescue Exception
|
114
|
+
false
|
115
|
+
else
|
116
|
+
_attributes_for(autonym).with_safety_setter?
|
117
|
+
end
|
118
|
+
|
119
|
+
alias_method :with_safety_writer?, :with_safety_setter?
|
120
|
+
|
121
|
+
# @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
|
122
|
+
def with_adjuster?(key)
|
123
|
+
autonym = autonym_for_key(key)
|
124
|
+
rescue Exception
|
125
|
+
false
|
126
|
+
else
|
127
|
+
_attributes_for(autonym).with_adjuster?
|
128
|
+
end
|
129
|
+
|
130
|
+
# @endgroup
|
64
131
|
end
|
65
|
-
|
66
|
-
# @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
|
67
|
-
def with_default?(key)
|
68
|
-
autonym = autonym_for_key key
|
69
|
-
rescue Exception
|
70
|
-
false
|
71
|
-
else
|
72
|
-
_attributes_for(autonym).with_default?
|
73
|
-
end
|
74
|
-
|
75
|
-
# @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
|
76
|
-
def with_condition?(key)
|
77
|
-
autonym = autonym_for_key key
|
78
|
-
rescue Exception
|
79
|
-
false
|
80
|
-
else
|
81
|
-
_attributes_for(autonym).with_condition?
|
82
|
-
end
|
83
|
-
|
84
|
-
alias_method :restrict?, :with_condition?
|
85
|
-
|
86
|
-
# @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
|
87
|
-
def with_must?(key)
|
88
|
-
autonym = autonym_for_key key
|
89
|
-
rescue Exception
|
90
|
-
false
|
91
|
-
else
|
92
|
-
_attributes_for(autonym).with_must?
|
93
|
-
end
|
94
|
-
|
95
|
-
alias_method :must?, :with_must?
|
96
|
-
|
97
|
-
# @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
|
98
|
-
def with_safety_getter?(key)
|
99
|
-
autonym = autonym_for_key key
|
100
|
-
rescue Exception
|
101
|
-
false
|
102
|
-
else
|
103
|
-
_attributes_for(autonym).with_safety_getter?
|
104
|
-
end
|
105
|
-
|
106
|
-
alias_method :with_safety_reader?, :with_safety_getter?
|
107
|
-
|
108
|
-
# @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
|
109
|
-
def with_safety_setter?(key)
|
110
|
-
autonym = autonym_for_key key
|
111
|
-
rescue Exception
|
112
|
-
false
|
113
|
-
else
|
114
|
-
_attributes_for(autonym).with_safety_setter?
|
115
|
-
end
|
116
|
-
|
117
|
-
alias_method :with_safety_writer?, :with_safety_setter?
|
118
|
-
|
119
|
-
# @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
|
120
|
-
def with_adjuster?(key)
|
121
|
-
autonym = autonym_for_key key
|
122
|
-
rescue Exception
|
123
|
-
false
|
124
|
-
else
|
125
|
-
_attributes_for(autonym).with_adjuster?
|
126
|
-
end
|
127
|
-
|
128
|
-
# @endgroup
|
129
|
-
|
130
|
-
end; end
|
132
|
+
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
3
|
require_relative 'hashdeepdupulicatable'
|
4
4
|
require_relative 'attributes'
|
@@ -15,4 +15,4 @@ require_relative 'default'
|
|
15
15
|
require_relative 'adjustment'
|
16
16
|
require_relative 'macro'
|
17
17
|
require_relative 'conflict_management'
|
18
|
-
require_relative 'validation'
|
18
|
+
require_relative 'validation'
|
@@ -1,24 +1,27 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
class Striuct
|
4
|
+
module ClassMethods
|
5
|
+
# @group To Ruby's Struct Class
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
7
|
+
# @return [Class]
|
8
|
+
def to_struct_class
|
9
|
+
raise 'No defined members' if autonyms.empty?
|
8
10
|
|
9
|
-
|
10
|
-
|
11
|
+
struct_cls = ::Struct.new(*autonyms)
|
12
|
+
return struct_cls unless name
|
11
13
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
already_cls
|
17
|
-
else
|
18
|
-
::Striuct::Structs.const_set const_suffix, struct_cls
|
19
|
-
end
|
20
|
-
end
|
14
|
+
const_suffix = name.slice(/[^:]+\z/).to_sym
|
15
|
+
if ::Striuct::Structs.const_defined?(const_suffix, false) &&
|
16
|
+
(already_cls = ::Striuct::Structs.const_get(const_suffix, false)).members == autonyms
|
17
|
+
raise unless already_cls.superclass.equal?(Struct)
|
21
18
|
|
22
|
-
|
19
|
+
already_cls
|
20
|
+
else
|
21
|
+
::Striuct::Structs.const_set(const_suffix, struct_cls)
|
22
|
+
end
|
23
|
+
end
|
23
24
|
|
24
|
-
|
25
|
+
# @endgroup
|
26
|
+
end
|
27
|
+
end
|
@@ -1,15 +1,17 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
def condition_for(key)
|
7
|
-
autonym = autonym_for_key key
|
8
|
-
raise KeyError unless with_condition? autonym
|
9
|
-
|
10
|
-
_attributes_for(autonym).condition
|
11
|
-
end
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
class Striuct
|
4
|
+
module ClassMethods
|
5
|
+
# @group Validation
|
12
6
|
|
13
|
-
|
7
|
+
# @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
|
8
|
+
def condition_for(key)
|
9
|
+
autonym = autonym_for_key(key)
|
10
|
+
raise KeyError unless with_condition?(autonym)
|
14
11
|
|
15
|
-
|
12
|
+
_attributes_for(autonym).condition
|
13
|
+
end
|
14
|
+
|
15
|
+
# @endgroup
|
16
|
+
end
|
17
|
+
end
|
@@ -1,33 +1,35 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
def assigned?(key)
|
7
|
-
@db.has_key? autonym_for_key(key)
|
8
|
-
end
|
3
|
+
class Striuct
|
4
|
+
module InstanceMethods
|
5
|
+
# @group Assign / Unassign
|
9
6
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
# @return value / nil - value assigned under the key
|
14
|
-
def unassign(key)
|
15
|
-
_check_frozen
|
16
|
-
_check_locked key
|
17
|
-
if must? key
|
18
|
-
raise InvalidOperationError, "`#{key}` require a value under `must` option"
|
7
|
+
# @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
|
8
|
+
def assigned?(key)
|
9
|
+
@db.key?(autonym_for_key(key))
|
19
10
|
end
|
20
|
-
|
21
|
-
@db.delete autonym_for_key(key)
|
22
|
-
end
|
23
|
-
|
24
|
-
alias_method :delete_at, :unassign
|
25
11
|
|
26
|
-
|
27
|
-
def empty?
|
28
|
-
_autonyms.none?{|autonym|@db.has_key? autonym}
|
29
|
-
end
|
12
|
+
alias_method :assign?, :assigned?
|
30
13
|
|
31
|
-
|
14
|
+
# @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
|
15
|
+
# @return value / nil - value assigned under the key
|
16
|
+
def unassign(key)
|
17
|
+
_check_frozen
|
18
|
+
_check_locked(key)
|
19
|
+
if must?(key)
|
20
|
+
raise InvalidOperationError, "`#{key}` require a value under `must` option"
|
21
|
+
end
|
22
|
+
|
23
|
+
@db.delete(autonym_for_key(key))
|
24
|
+
end
|
32
25
|
|
33
|
-
|
26
|
+
alias_method :delete_at, :unassign
|
27
|
+
|
28
|
+
# true if all members are not yet assigned
|
29
|
+
def empty?
|
30
|
+
_autonyms.none? { |autonym| @db.key?(autonym) }
|
31
|
+
end
|
32
|
+
|
33
|
+
# @endgroup
|
34
|
+
end
|
35
|
+
end
|
@@ -1,32 +1,34 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
class Striuct
|
4
|
+
module InstanceMethods
|
5
|
+
# @group Cast
|
4
6
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
7
|
+
# @return [self]
|
8
|
+
def to_striuct
|
9
|
+
self
|
10
|
+
end
|
9
11
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
# @param [Boolean] include_no_assign
|
16
|
-
# @return [Hash]
|
17
|
-
def to_h(include_no_assign=true)
|
18
|
-
return @db.dup unless include_no_assign
|
12
|
+
# @return [Struct]
|
13
|
+
def to_struct
|
14
|
+
self.class.to_struct_class.new(*values)
|
15
|
+
end
|
19
16
|
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
def values
|
25
|
-
each_value.to_a
|
26
|
-
end
|
27
|
-
|
28
|
-
alias_method :to_a, :values
|
17
|
+
# @param [Boolean] include_no_assign
|
18
|
+
# @return [Hash]
|
19
|
+
def to_h(include_no_assign: true)
|
20
|
+
return @db.dup unless include_no_assign
|
29
21
|
|
30
|
-
|
22
|
+
each_pair.to_a.to_h
|
23
|
+
end
|
31
24
|
|
32
|
-
|
25
|
+
# @return [Array]
|
26
|
+
def values
|
27
|
+
each_value.to_a
|
28
|
+
end
|
29
|
+
|
30
|
+
alias_method :to_a, :values
|
31
|
+
|
32
|
+
# @endgroup
|
33
|
+
end
|
34
|
+
end
|
@@ -1,30 +1,32 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
# @group Compare with other
|
4
|
-
|
5
|
-
# @return [Boolean]
|
6
|
-
def ==(other)
|
7
|
-
other.instance_of?(self.class) &&
|
8
|
-
each_pair.all?{|autonym, val|other._get(autonym) == val}
|
9
|
-
end
|
1
|
+
# frozen_string_literal: true
|
10
2
|
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
other.instance_of?(self.class) && other._db.eql?(@db)
|
15
|
-
end
|
3
|
+
class Striuct
|
4
|
+
module InstanceMethods
|
5
|
+
# @group Compare with other
|
16
6
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
7
|
+
# @return [Boolean]
|
8
|
+
def ==(other)
|
9
|
+
other.instance_of?(self.class) &&
|
10
|
+
each_pair.all? { |autonym, val| other._get(autonym) == val }
|
11
|
+
end
|
21
12
|
|
22
|
-
|
13
|
+
alias_method :===, :==
|
23
14
|
|
24
|
-
|
25
|
-
|
26
|
-
|
15
|
+
def eql?(other)
|
16
|
+
other.instance_of?(self.class) && other._db.eql?(@db)
|
17
|
+
end
|
27
18
|
|
28
|
-
|
19
|
+
# @return [Integer]
|
20
|
+
def hash
|
21
|
+
@db.hash
|
22
|
+
end
|
29
23
|
|
30
|
-
|
24
|
+
protected
|
25
|
+
|
26
|
+
def _db
|
27
|
+
@db
|
28
|
+
end
|
29
|
+
|
30
|
+
# @endgroup
|
31
|
+
end
|
32
|
+
end
|
@@ -1,36 +1,38 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
def default?(key)
|
7
|
-
autonym = autonym_for_key key
|
3
|
+
class Striuct
|
4
|
+
module InstanceMethods
|
5
|
+
# @group Default Value
|
8
6
|
|
9
|
-
|
10
|
-
|
7
|
+
# @param [Symbol, String, #to_sym, Integer, #to_int] key - name / index
|
8
|
+
def default?(key)
|
9
|
+
autonym = autonym_for_key(key)
|
10
|
+
|
11
|
+
default_value_for(autonym) == fetch_by_autonym(autonym)
|
12
|
+
end
|
11
13
|
|
12
|
-
|
14
|
+
private
|
13
15
|
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
16
|
+
# @param [Symbol] target_autonyms - MUST already converted to native autonym
|
17
|
+
# @return [self]
|
18
|
+
def _set_defaults(*target_autonyms)
|
19
|
+
target_autonyms.each do |autonym|
|
20
|
+
if with_default?(autonym)
|
21
|
+
default = default_value_for(autonym)
|
22
|
+
_set(autonym, (
|
23
|
+
if default_type_for(autonym) == :lazy
|
24
|
+
args = [self, autonym][0, default.arity]
|
25
|
+
default.call(*args)
|
26
|
+
else
|
27
|
+
default
|
28
|
+
end
|
29
|
+
))
|
30
|
+
end
|
28
31
|
end
|
29
|
-
end
|
30
|
-
|
31
|
-
self
|
32
|
-
end
|
33
32
|
|
34
|
-
|
33
|
+
self
|
34
|
+
end
|
35
35
|
|
36
|
-
|
36
|
+
# @endgroup
|
37
|
+
end
|
38
|
+
end
|
@@ -1,37 +1,39 @@
|
|
1
|
-
|
1
|
+
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
:autonym_for_alias,
|
7
|
-
:autonym_for_member,
|
8
|
-
:autonym_for_index,
|
9
|
-
:autonym_for_key,
|
10
|
-
:autonyms, :members, :all_members, :aliases, :attributes,
|
11
|
-
:has_autonym?, :autonym?,
|
12
|
-
:has_alias?, :alias?, :aliased?,
|
13
|
-
:has_member?, :member?,
|
14
|
-
:has_index?, :index?,
|
15
|
-
:has_key?, :key?,
|
16
|
-
:with_aliases?,
|
17
|
-
:aliases_for_autonym,
|
18
|
-
:length, :size,
|
19
|
-
:with_condition?, :restrict?,
|
20
|
-
:condition_for,
|
21
|
-
:with_safety_getter?, :with_safety_reader?,
|
22
|
-
:with_safety_setter?, :with_safety_writer?,
|
23
|
-
:with_must?, :must?,
|
24
|
-
:with_default?,
|
25
|
-
:default_value_for, :default_type_for,
|
26
|
-
:with_adjuster?,
|
27
|
-
:adjuster_for
|
3
|
+
class Striuct
|
4
|
+
module InstanceMethods
|
5
|
+
# @group Delegate Class Methods
|
28
6
|
|
29
|
-
|
7
|
+
def_delegators :'self.class',
|
8
|
+
:autonym_for_alias,
|
9
|
+
:autonym_for_member,
|
10
|
+
:autonym_for_index,
|
11
|
+
:autonym_for_key,
|
12
|
+
:autonyms, :members, :all_members, :aliases, :attributes,
|
13
|
+
:has_autonym?, :autonym?,
|
14
|
+
:has_alias?, :alias?, :aliased?,
|
15
|
+
:has_member?, :member?,
|
16
|
+
:has_index?, :index?,
|
17
|
+
:has_key?, :key?,
|
18
|
+
:with_aliases?,
|
19
|
+
:aliases_for_autonym,
|
20
|
+
:length, :size,
|
21
|
+
:with_condition?, :restrict?,
|
22
|
+
:condition_for,
|
23
|
+
:with_safety_getter?, :with_safety_reader?,
|
24
|
+
:with_safety_setter?, :with_safety_writer?,
|
25
|
+
:with_must?, :must?,
|
26
|
+
:with_default?,
|
27
|
+
:default_value_for, :default_type_for,
|
28
|
+
:with_adjuster?,
|
29
|
+
:adjuster_for
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
private
|
32
|
+
|
33
|
+
def _autonyms
|
34
|
+
self.class.__send__(:_autonyms)
|
35
|
+
end
|
34
36
|
|
35
|
-
|
36
|
-
|
37
|
-
end
|
37
|
+
# @endgroup
|
38
|
+
end
|
39
|
+
end
|