eac_ruby_utils 0.53.0 → 0.54.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/lib/eac_ruby_utils/common_constructor.rb +53 -0
- data/lib/eac_ruby_utils/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: 2f22ad5641eaab5162d43b211dbd8a032f52873559bac3b10f50aa37088fe8e7
|
4
|
+
data.tar.gz: 3f2c0ef1b38f9d777cd1ad944b55d2457e6e3323a8ae80ed767d6b75ee0c8c48
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a26a2ca577a6eb10e4efff3ca1d3c28231fa6af4dacad3494d0f3a861b50f4ee44f8873800994f67d2e62475a5385ffb094f66b1114cc6deab43ddfe514c15e8
|
7
|
+
data.tar.gz: 0c7622bf2346fd91630bb8689e637275195f7d4e784d9b2a45489c384637f3451e2be17127485e1ca092b32439f7d67e16327b9c0aa5558d1d35730c5c7f470c
|
@@ -61,6 +61,8 @@ module EacRubyUtils
|
|
61
61
|
setup_class_attr_readers(klass)
|
62
62
|
setup_class_attr_writers(klass)
|
63
63
|
setup_class_initialize(klass)
|
64
|
+
|
65
|
+
klass
|
64
66
|
end
|
65
67
|
|
66
68
|
def setup_class_attr_readers(klass)
|
@@ -79,9 +81,14 @@ module EacRubyUtils
|
|
79
81
|
klass.define_callbacks :initialize
|
80
82
|
klass.send(:define_method, :initialize) do |*args|
|
81
83
|
Initialize.new(common_constructor, args, self).run
|
84
|
+
super(*SuperArgs.new(common_constructor, args, self).result)
|
82
85
|
end
|
83
86
|
end
|
84
87
|
|
88
|
+
def super_args
|
89
|
+
options[:super_args]
|
90
|
+
end
|
91
|
+
|
85
92
|
class Initialize
|
86
93
|
attr_reader :common_constructor, :args, :object
|
87
94
|
|
@@ -129,5 +136,51 @@ module EacRubyUtils
|
|
129
136
|
" (given #{args.count}, expected #{common_constructor.args_count})"
|
130
137
|
end
|
131
138
|
end
|
139
|
+
|
140
|
+
class SuperArgs
|
141
|
+
attr_reader :common_constructor, :args, :object
|
142
|
+
|
143
|
+
def initialize(common_constructor, args, object)
|
144
|
+
@common_constructor = common_constructor
|
145
|
+
@args = args
|
146
|
+
@object = object
|
147
|
+
end
|
148
|
+
|
149
|
+
def auto_result
|
150
|
+
r = []
|
151
|
+
sub_args.each do |name, value|
|
152
|
+
i = super_arg_index(name)
|
153
|
+
r[i] = value if i
|
154
|
+
end
|
155
|
+
r
|
156
|
+
end
|
157
|
+
|
158
|
+
def result
|
159
|
+
result_from_options || auto_result
|
160
|
+
end
|
161
|
+
|
162
|
+
def result_from_options
|
163
|
+
return unless common_constructor.super_args
|
164
|
+
|
165
|
+
object.instance_exec(&common_constructor.super_args)
|
166
|
+
end
|
167
|
+
|
168
|
+
def sub_args
|
169
|
+
common_constructor.args.each_with_index.map do |name, index|
|
170
|
+
[name, args[index]]
|
171
|
+
end.to_h
|
172
|
+
end
|
173
|
+
|
174
|
+
def super_arg_index(name)
|
175
|
+
super_method.parameters.each_with_index do |arg, index|
|
176
|
+
return index if arg[1] == name
|
177
|
+
end
|
178
|
+
nil
|
179
|
+
end
|
180
|
+
|
181
|
+
def super_method
|
182
|
+
object.class.superclass ? object.class.superclass.instance_method(:initialize) : nil
|
183
|
+
end
|
184
|
+
end
|
132
185
|
end
|
133
186
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: eac_ruby_utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.54.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Esquilo Azul Company
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-12-
|
11
|
+
date: 2020-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|