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 +4 -4
- data/lib/glue_gun/dsl.rb +22 -9
- data/lib/glue_gun/version.rb +1 -1
- data/lib/glue_gun.rb +1 -0
- 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: 204effd0afcc5b7a8b1ac6f80ec1ddde4f99039817b0fe84e1a6747c76c13e27
|
4
|
+
data.tar.gz: 227f7029e97ef1639ffbbebf5b0d8273ff0c7a084b5950aa8040c9f91e3be26c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
|
102
|
-
|
103
|
-
|
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 =
|
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]
|
data/lib/glue_gun/version.rb
CHANGED
data/lib/glue_gun.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.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-
|
11
|
+
date: 2024-10-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|