glue_gun_dsl 0.1.12 → 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: a663641fdcec4866446e9d72583c2e3be4e038604cb22466ee094e81fc17bb79
4
- data.tar.gz: 7cc36ed0ad6903f243a129fddee1426995364f703505dad2812322e890a14322
3
+ metadata.gz: 204effd0afcc5b7a8b1ac6f80ec1ddde4f99039817b0fe84e1a6747c76c13e27
4
+ data.tar.gz: 227f7029e97ef1639ffbbebf5b0d8273ff0c7a084b5950aa8040c9f91e3be26c
5
5
  SHA512:
6
- metadata.gz: 10571a6ef7a315f566f5d49140aa0e4743433707ab5c8363d862f7fd318d775e32b6d636fb6698900c0d39706a0da2e77fb35bb3812f919aca4bd1d350df383e
7
- data.tar.gz: 8e0754d69e1ae48e7d0c8ca396d8afd747967c51bbaced995af0b82f203b431a2eeaf8c47784a08273ce8b6596acb330964063a31f8cdaf414b8b1a1f35a4e66
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.12"
4
+ VERSION = "0.1.14"
5
5
  end
data/lib/glue_gun.rb CHANGED
@@ -1,4 +1,5 @@
1
1
  require "active_model"
2
+ require "active_record"
2
3
  require "active_support/concern"
3
4
 
4
5
  module GlueGun
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.12
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