glue_gun_dsl 0.1.18 → 0.1.19

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 1cf96906f1af3fd62ba4c0e7aa061d9d109aee45ced7284e7776cb74d7dca313
4
- data.tar.gz: 47f2454a802ce7a9bd335e7413fd2851551eae2437d4de9bebb0f1f31ad82b53
3
+ metadata.gz: 68fc0793c49beee7168734f15f10ef57334c0fbbb0f4373c74cfdad16b416a2f
4
+ data.tar.gz: 34ba98c7f1518de7b16ae4c2d1e4cd9f5c8224ad911c3d7bc14ed21dec139fe8
5
5
  SHA512:
6
- metadata.gz: 8f4be572fe72494ab001d7ea71ec0f35064d1914a7982ab026ffd12f40126dd01051c1594e9baf78ae3a6415b3bfb44d7524f512986af53dcaa0db3ab5924ba3
7
- data.tar.gz: fcf9a586af6236a3595b6a215daca49239a5e7407ab4086626dbcc105f755a76a82ae45de536047a7a8464be0035a89b81e8c4ca5bb11dd1c7aca31eae049b97
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
- return nil if init_args.nil? && definition.default_option_name.nil?
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, parent)
373
- builder.initialize_single_dependency(init_args, parent)
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, parent)
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, parent), option_config]
398
+ [instantiate_dependency(option_config, init_args, instance), option_config]
389
399
  end
390
400
 
391
- def initialize_single_dependency(init_args, parent)
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, parent)
406
+ dep, option_config = initialize_factory_dependency(init_args, instance)
397
407
  else
398
- dep, option_config = initialize_builder_dependency(init_args, parent)
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]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GlueGun
4
- VERSION = "0.1.18"
4
+ VERSION = "0.1.19"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: glue_gun_dsl
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.18
4
+ version: 0.1.19
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Shollenberger