glue_gun_dsl 0.1.13 → 0.1.14

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a744558606a85cbfc6641c33ba4aae92925712e9ee8b30555aad1309773def0e
4
- data.tar.gz: 49d3742eccba3ed436ee950b74c8aa5627d5a36ac1cca8fafe625904f9cd567d
3
+ metadata.gz: 204effd0afcc5b7a8b1ac6f80ec1ddde4f99039817b0fe84e1a6747c76c13e27
4
+ data.tar.gz: 227f7029e97ef1639ffbbebf5b0d8273ff0c7a084b5950aa8040c9f91e3be26c
5
5
  SHA512:
6
- metadata.gz: 3fd64a4f71a0fd2fee778ce93609bbda6bbf38aff76feeeb9c8bd8d427c75def7c83471ac091cf40dbcc6f7ca16070ed2a89cf1d19e3e1d3eb48c2196d213edf
7
- data.tar.gz: 46e927fdfe42d553b6ee39e069cfea564fa2d10afd6548618d5bfd1b35db964024d0156a84986f126f85929b78a89de31c3994f61b43780906a3b3cf0b0c2194
6
+ metadata.gz: 3ee786e7b526c47e62de741a0fd0eb686e890d8e176e4424157d7bd4488f81e0750b7efb2d1d27ee0092e415d92b342ae7d4f6575e1c82ce932aaebcaf56cc26
7
+ data.tar.gz: 67434b47dc06d5b258d5a1f1286859879c414b4131d17e66a8651378586312ff0b157825e45e2a939625b3a355a0dcbcff7691f0220d5f61cf6fbe8ba2933746
data/lib/glue_gun/dsl.rb CHANGED
@@ -28,7 +28,7 @@ module GlueGun
28
28
  prepend ClassMethods
29
29
  end
30
30
 
31
- # Overriding ActiveModel.assign_attributes to ensure change propagation to dependenices
31
+ # Overriding ActiveModel.assign_attributes to ensure change propagation to dependencies
32
32
  def assign_attributes(new_attributes)
33
33
  super(new_attributes)
34
34
  propagate_changes if initialized?
@@ -79,6 +79,7 @@ module GlueGun
79
79
  elsif ActiveModel.version >= Gem::Version.new("5")
80
80
  ActiveModel::Type::Value.new
81
81
  end
82
+
82
83
  # Override the attribute method to define custom setters
83
84
  def attribute(name, type = DEFAULT_TYPE, **options)
84
85
  super(name, type, **options)
@@ -97,10 +98,14 @@ module GlueGun
97
98
  end
98
99
  end
99
100
 
100
- def dependency(component_type, &block)
101
- dependency_builder = DependencyBuilder.new(component_type)
102
- dependency_builder.instance_eval(&block)
103
- dependency_definitions[component_type] = dependency_builder
101
+ def dependency(component_type, factory_class = nil, &block)
102
+ if factory_class
103
+ dependency_definitions[component_type] = factory_class
104
+ else
105
+ dependency_builder = DependencyBuilder.new(component_type)
106
+ dependency_builder.instance_eval(&block)
107
+ dependency_definitions[component_type] = dependency_builder
108
+ end
104
109
 
105
110
  # Define singleton method to allow hardcoding dependencies in subclasses
106
111
  define_singleton_method component_type do |option = nil, options = {}|
@@ -157,16 +162,24 @@ module GlueGun
157
162
  end
158
163
 
159
164
  def initialize_dependencies(attributes)
160
- self.class.dependency_definitions.each do |component_type, _|
165
+ self.class.dependency_definitions.each do |component_type, definition|
161
166
  value = attributes[component_type] || self.class.hardcoded_dependencies[component_type]
162
- instance_variable_set("@#{component_type}", initialize_dependency(component_type, value))
167
+ instance_variable_set("@#{component_type}", initialize_dependency(component_type, value, definition))
163
168
  end
164
169
  end
165
170
 
166
- def initialize_dependency(component_type, init_args = {})
171
+ def initialize_dependency(component_type, init_args = {}, definition = nil)
172
+ definition ||= self.class.dependency_definitions[component_type]
173
+
174
+ if definition.is_a?(Class) && definition.include?(GlueGun::DSL)
175
+ # If the definition is a factory class, use it to create the dependency
176
+ factory_instance = definition.new
177
+ return factory_instance.send(:initialize_dependency, component_type, init_args)
178
+ end
179
+
167
180
  return init_args if dependency_injected?(component_type, init_args)
168
181
 
169
- dependency_builder = self.class.dependency_definitions[component_type]
182
+ dependency_builder = definition
170
183
 
171
184
  if init_args && init_args.is_a?(Hash) && init_args.key?(:option_name)
172
185
  option_name = init_args[:option_name]
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module GlueGun
4
- VERSION = "0.1.13"
4
+ VERSION = "0.1.14"
5
5
  end
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.13
4
+ version: 0.1.14
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-08 00:00:00.000000000 Z
11
+ date: 2024-10-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activemodel