glue_gun_dsl 0.1.18 → 0.1.19
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 +24 -14
- data/lib/glue_gun/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 68fc0793c49beee7168734f15f10ef57334c0fbbb0f4373c74cfdad16b416a2f
|
4
|
+
data.tar.gz: 34ba98c7f1518de7b16ae4c2d1e4cd9f5c8224ad911c3d7bc14ed21dec139fe8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 72d8a6751b6ed9d9ea22f8dfb8e89386b2217bbdfc17f922716a208ca9fce8a290762ceb43dcb301d32e9733058c1ea7433b8435a8b6f3b9feb96db83ceaeaaa
|
7
|
+
data.tar.gz: 4cece38fc3e06acd4c285a4e8d04e19d69c01b39ac80af8815f967b96df7f863ef225bad172fb4e5231552a107ae092445feee107b3419225db3e6c9d26f59b1
|
data/lib/glue_gun/dsl.rb
CHANGED
@@ -107,7 +107,7 @@ module GlueGun
|
|
107
107
|
options = {}
|
108
108
|
end
|
109
109
|
|
110
|
-
dependency_builder = DependencyBuilder.new(component_type)
|
110
|
+
dependency_builder = DependencyBuilder.new(component_type, options)
|
111
111
|
|
112
112
|
if factory_class.present?
|
113
113
|
dependency_builder.set_factory_class(factory_class)
|
@@ -182,7 +182,12 @@ module GlueGun
|
|
182
182
|
is_array = init_args.is_a?(Array)
|
183
183
|
is_hash = definition.is_hash?(init_args)
|
184
184
|
|
185
|
-
|
185
|
+
if init_args.nil? && definition.default_option_name.nil?
|
186
|
+
return nil if definition.lazy?
|
187
|
+
if definition.when_block.nil?
|
188
|
+
raise "No default option or when block present for component_type #{component_type}. Don't know how to build!"
|
189
|
+
end
|
190
|
+
end
|
186
191
|
|
187
192
|
if is_array
|
188
193
|
dep = []
|
@@ -312,14 +317,15 @@ module GlueGun
|
|
312
317
|
end
|
313
318
|
|
314
319
|
class DependencyBuilder
|
315
|
-
attr_reader :component_type, :option_configs, :when_block, :is_only, :factory_class
|
320
|
+
attr_reader :component_type, :option_configs, :when_block, :is_only, :factory_class, :lazy, :parent
|
316
321
|
|
317
|
-
def initialize(component_type)
|
322
|
+
def initialize(component_type, options)
|
318
323
|
@component_type = component_type
|
319
324
|
@option_configs = {}
|
320
325
|
@default_option_name = nil
|
321
326
|
@single_option = nil
|
322
327
|
@is_only = false
|
328
|
+
@lazy = options.key?(:lazy) ? options.dig(:lazy) : true
|
323
329
|
end
|
324
330
|
|
325
331
|
def set_factory_class(factory_class)
|
@@ -356,6 +362,10 @@ module GlueGun
|
|
356
362
|
!factory?
|
357
363
|
end
|
358
364
|
|
365
|
+
def lazy?
|
366
|
+
@lazy == true
|
367
|
+
end
|
368
|
+
|
359
369
|
def is_hash?(init_args)
|
360
370
|
return false unless init_args.is_a?(Hash)
|
361
371
|
|
@@ -369,33 +379,33 @@ module GlueGun
|
|
369
379
|
end
|
370
380
|
end
|
371
381
|
|
372
|
-
def initialize_factory_dependency(init_args,
|
373
|
-
builder.initialize_single_dependency(init_args,
|
382
|
+
def initialize_factory_dependency(init_args, instance)
|
383
|
+
builder.initialize_single_dependency(init_args, instance)
|
374
384
|
end
|
375
385
|
|
376
|
-
def initialize_builder_dependency(init_args,
|
386
|
+
def initialize_builder_dependency(init_args, instance)
|
377
387
|
if init_args && init_args.is_a?(Hash) && init_args.key?(:option_name)
|
378
388
|
option_name = init_args[:option_name]
|
379
389
|
init_args = init_args[:value]
|
380
390
|
else
|
381
|
-
option_name, init_args = determine_option_name(init_args)
|
391
|
+
option_name, init_args = determine_option_name(init_args, instance)
|
382
392
|
end
|
383
393
|
|
384
394
|
option_config = option_configs[option_name]
|
385
395
|
|
386
396
|
raise ArgumentError, "Unknown #{component_type} option '#{option_name}'" unless option_config
|
387
397
|
|
388
|
-
[instantiate_dependency(option_config, init_args,
|
398
|
+
[instantiate_dependency(option_config, init_args, instance), option_config]
|
389
399
|
end
|
390
400
|
|
391
|
-
def initialize_single_dependency(init_args,
|
401
|
+
def initialize_single_dependency(init_args, instance)
|
392
402
|
if dependency_injected?(init_args)
|
393
403
|
dep = init_args
|
394
404
|
option_config = injected_dependency(init_args)
|
395
405
|
elsif factory?
|
396
|
-
dep, option_config = initialize_factory_dependency(init_args,
|
406
|
+
dep, option_config = initialize_factory_dependency(init_args, instance)
|
397
407
|
else
|
398
|
-
dep, option_config = initialize_builder_dependency(init_args,
|
408
|
+
dep, option_config = initialize_builder_dependency(init_args, instance)
|
399
409
|
end
|
400
410
|
|
401
411
|
[dep, option_config]
|
@@ -421,12 +431,12 @@ module GlueGun
|
|
421
431
|
dep_attributes
|
422
432
|
end
|
423
433
|
|
424
|
-
def determine_option_name(init_args)
|
434
|
+
def determine_option_name(init_args, instance)
|
425
435
|
option_name = nil
|
426
436
|
|
427
437
|
# Use when block if defined
|
428
438
|
if when_block
|
429
|
-
result = instance_exec(init_args, &when_block)
|
439
|
+
result = instance.instance_exec(init_args, &when_block)
|
430
440
|
if result.is_a?(Hash) && result[:option]
|
431
441
|
option_name = result[:option]
|
432
442
|
as_attr = result[:as]
|
data/lib/glue_gun/version.rb
CHANGED