glue_gun_dsl 0.1.15 → 0.1.17
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/glue_gun/dsl.rb +63 -6
- data/lib/glue_gun/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: '0962a5666114730f40d7b78a9e70e2762480f318cf4790641c47e8406d6af3aa'
|
4
|
+
data.tar.gz: 161576a11d2ff360e5c4fc34327c9db3ecf3201fe9f81fd864e84c34ce223c12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3231f0758ae02faea304068b16bd9da17b6910a2f2f3ccd3ddec5c08ee6c9af651b36fc376e9e9a80d330d24448c4d18389cab87a76ade9fbd5db52eeaabb1d6
|
7
|
+
data.tar.gz: 1f5f68fd1879dc28a708214a794d0d2f39410b912e0659d63a67c2244dffb82b89dea4084bfa4db028c0e0aef46a501a4b017a000c64c7fc8027798a669c303e
|
data/lib/glue_gun/dsl.rb
CHANGED
@@ -106,14 +106,13 @@ module GlueGun
|
|
106
106
|
factory_class = options
|
107
107
|
options = {}
|
108
108
|
end
|
109
|
-
is_array = options[:array] || false
|
110
109
|
|
111
110
|
if factory_class.present?
|
112
|
-
dependency_definitions[component_type] = { factory_class: factory_class
|
111
|
+
dependency_definitions[component_type] = { factory_class: factory_class }
|
113
112
|
else
|
114
113
|
dependency_builder = DependencyBuilder.new(component_type)
|
115
114
|
dependency_builder.instance_eval(&block)
|
116
|
-
dependency_definitions[component_type] = { builder: dependency_builder
|
115
|
+
dependency_definitions[component_type] = { builder: dependency_builder }
|
117
116
|
end
|
118
117
|
|
119
118
|
# Define singleton method to allow hardcoding dependencies in subclasses
|
@@ -177,9 +176,51 @@ module GlueGun
|
|
177
176
|
end
|
178
177
|
end
|
179
178
|
|
179
|
+
def allowed_configurations(init_args, definition)
|
180
|
+
if definition[:factory_class]
|
181
|
+
factory_instance = definition[:factory_class].new
|
182
|
+
dep_defs = factory_instance.dependency_definitions
|
183
|
+
definition = dep_defs[dep_defs.keys.first]
|
184
|
+
return allowed_configurations(init_args, definition)
|
185
|
+
elsif definition[:builder]
|
186
|
+
builder = definition[:builder]
|
187
|
+
allowed_configs = builder.option_configs.keys
|
188
|
+
end
|
189
|
+
|
190
|
+
allowed_configs
|
191
|
+
end
|
192
|
+
|
193
|
+
def is_hash?(init_args, definition)
|
194
|
+
return false unless init_args.is_a?(Hash)
|
195
|
+
|
196
|
+
allowed_configs = allowed_configurations(init_args, definition)
|
197
|
+
return false if allowed_configs.count == 1 && allowed_configs == [:default]
|
198
|
+
|
199
|
+
if init_args.key?(:option_name)
|
200
|
+
allowed_configs.exclude?(init_args[:option_name])
|
201
|
+
else
|
202
|
+
init_args.keys.none? { |k| allowed_configs.include?(k) }
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def validate_hash_dependencies(init_args, definition, component_type)
|
207
|
+
allowed_configs = allowed_configurations(init_args, definition)
|
208
|
+
|
209
|
+
init_args.each do |_named_key, configuration|
|
210
|
+
next unless configuration.is_a?(Hash)
|
211
|
+
|
212
|
+
key = configuration.keys.first
|
213
|
+
if key.nil? || allowed_configs.exclude?(key)
|
214
|
+
raise ArgumentError,
|
215
|
+
"Unknown #{component_type} option: #{init_args.keys.first}."
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
180
220
|
def initialize_dependency(component_type, init_args = {}, definition = nil)
|
181
221
|
definition ||= self.class.dependency_definitions[component_type]
|
182
|
-
is_array =
|
222
|
+
is_array = init_args.is_a?(Array)
|
223
|
+
is_hash = is_hash?(init_args, definition)
|
183
224
|
|
184
225
|
if is_array
|
185
226
|
dep = []
|
@@ -189,6 +230,16 @@ module GlueGun
|
|
189
230
|
dep.push(d)
|
190
231
|
config.push(c)
|
191
232
|
end
|
233
|
+
elsif is_hash
|
234
|
+
dep = {}
|
235
|
+
config = {}
|
236
|
+
validate_hash_dependencies(init_args, definition, component_type)
|
237
|
+
|
238
|
+
init_args.each do |key, args|
|
239
|
+
d, c = initialize_single_dependency(component_type, args, definition)
|
240
|
+
dep[key] = d
|
241
|
+
config[key] = c
|
242
|
+
end
|
192
243
|
else
|
193
244
|
dep, config = initialize_single_dependency(component_type, init_args, definition)
|
194
245
|
end
|
@@ -341,6 +392,12 @@ module GlueGun
|
|
341
392
|
dependency_instance.zip(option_config).each do |dep, opt|
|
342
393
|
propagate_attribute_to_instance(attr_name, value, dep, opt)
|
343
394
|
end
|
395
|
+
elsif dependency_instance.is_a?(Hash)
|
396
|
+
option_config = dependencies.dig(component_type, :option)
|
397
|
+
|
398
|
+
dependency_instance.each do |key, dep|
|
399
|
+
propagate_attribute_to_instance(attr_name, value, dep, option_config[key])
|
400
|
+
end
|
344
401
|
else
|
345
402
|
option_config = dependencies.dig(component_type, :option)
|
346
403
|
next unless option_config
|
@@ -374,14 +431,14 @@ module GlueGun
|
|
374
431
|
else
|
375
432
|
factory.dependency_definitions.values.first.values.first.option_configs
|
376
433
|
end
|
377
|
-
option_configs.values.
|
434
|
+
option_configs.values.detect do |option|
|
378
435
|
option_class = option.class_name
|
379
436
|
value.is_a?(option_class)
|
380
437
|
end
|
381
438
|
end
|
382
439
|
|
383
440
|
def dependency_injected?(component_type, value)
|
384
|
-
injected_dependency(component_type, value).
|
441
|
+
injected_dependency(component_type, value).present?
|
385
442
|
end
|
386
443
|
|
387
444
|
def dependencies
|
data/lib/glue_gun/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: glue_gun_dsl
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.17
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brett Shollenberger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-10-
|
11
|
+
date: 2024-10-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|