glue_gun_dsl 0.1.16 → 0.1.17
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 +4 -4
- data/lib/glue_gun/dsl.rb +49 -8
- 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: '0962a5666114730f40d7b78a9e70e2762480f318cf4790641c47e8406d6af3aa'
|
4
|
+
data.tar.gz: 161576a11d2ff360e5c4fc34327c9db3ecf3201fe9f81fd864e84c34ce223c12
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3231f0758ae02faea304068b16bd9da17b6910a2f2f3ccd3ddec5c08ee6c9af651b36fc376e9e9a80d330d24448c4d18389cab87a76ade9fbd5db52eeaabb1d6
|
7
|
+
data.tar.gz: 1f5f68fd1879dc28a708214a794d0d2f39410b912e0659d63a67c2244dffb82b89dea4084bfa4db028c0e0aef46a501a4b017a000c64c7fc8027798a669c303e
|
data/lib/glue_gun/dsl.rb
CHANGED
@@ -106,15 +106,13 @@ module GlueGun
|
|
106
106
|
factory_class = options
|
107
107
|
options = {}
|
108
108
|
end
|
109
|
-
is_array = options[:array] || false
|
110
|
-
is_hash = options[:hash] || false
|
111
109
|
|
112
110
|
if factory_class.present?
|
113
|
-
dependency_definitions[component_type] = { factory_class: factory_class
|
111
|
+
dependency_definitions[component_type] = { factory_class: factory_class }
|
114
112
|
else
|
115
113
|
dependency_builder = DependencyBuilder.new(component_type)
|
116
114
|
dependency_builder.instance_eval(&block)
|
117
|
-
dependency_definitions[component_type] = { builder: dependency_builder
|
115
|
+
dependency_definitions[component_type] = { builder: dependency_builder }
|
118
116
|
end
|
119
117
|
|
120
118
|
# Define singleton method to allow hardcoding dependencies in subclasses
|
@@ -178,10 +176,51 @@ module GlueGun
|
|
178
176
|
end
|
179
177
|
end
|
180
178
|
|
179
|
+
def allowed_configurations(init_args, definition)
|
180
|
+
if definition[:factory_class]
|
181
|
+
factory_instance = definition[:factory_class].new
|
182
|
+
dep_defs = factory_instance.dependency_definitions
|
183
|
+
definition = dep_defs[dep_defs.keys.first]
|
184
|
+
return allowed_configurations(init_args, definition)
|
185
|
+
elsif definition[:builder]
|
186
|
+
builder = definition[:builder]
|
187
|
+
allowed_configs = builder.option_configs.keys
|
188
|
+
end
|
189
|
+
|
190
|
+
allowed_configs
|
191
|
+
end
|
192
|
+
|
193
|
+
def is_hash?(init_args, definition)
|
194
|
+
return false unless init_args.is_a?(Hash)
|
195
|
+
|
196
|
+
allowed_configs = allowed_configurations(init_args, definition)
|
197
|
+
return false if allowed_configs.count == 1 && allowed_configs == [:default]
|
198
|
+
|
199
|
+
if init_args.key?(:option_name)
|
200
|
+
allowed_configs.exclude?(init_args[:option_name])
|
201
|
+
else
|
202
|
+
init_args.keys.none? { |k| allowed_configs.include?(k) }
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
206
|
+
def validate_hash_dependencies(init_args, definition, component_type)
|
207
|
+
allowed_configs = allowed_configurations(init_args, definition)
|
208
|
+
|
209
|
+
init_args.each do |_named_key, configuration|
|
210
|
+
next unless configuration.is_a?(Hash)
|
211
|
+
|
212
|
+
key = configuration.keys.first
|
213
|
+
if key.nil? || allowed_configs.exclude?(key)
|
214
|
+
raise ArgumentError,
|
215
|
+
"Unknown #{component_type} option: #{init_args.keys.first}."
|
216
|
+
end
|
217
|
+
end
|
218
|
+
end
|
219
|
+
|
181
220
|
def initialize_dependency(component_type, init_args = {}, definition = nil)
|
182
221
|
definition ||= self.class.dependency_definitions[component_type]
|
183
|
-
is_array =
|
184
|
-
is_hash = definition
|
222
|
+
is_array = init_args.is_a?(Array)
|
223
|
+
is_hash = is_hash?(init_args, definition)
|
185
224
|
|
186
225
|
if is_array
|
187
226
|
dep = []
|
@@ -194,6 +233,8 @@ module GlueGun
|
|
194
233
|
elsif is_hash
|
195
234
|
dep = {}
|
196
235
|
config = {}
|
236
|
+
validate_hash_dependencies(init_args, definition, component_type)
|
237
|
+
|
197
238
|
init_args.each do |key, args|
|
198
239
|
d, c = initialize_single_dependency(component_type, args, definition)
|
199
240
|
dep[key] = d
|
@@ -390,14 +431,14 @@ module GlueGun
|
|
390
431
|
else
|
391
432
|
factory.dependency_definitions.values.first.values.first.option_configs
|
392
433
|
end
|
393
|
-
option_configs.values.
|
434
|
+
option_configs.values.detect do |option|
|
394
435
|
option_class = option.class_name
|
395
436
|
value.is_a?(option_class)
|
396
437
|
end
|
397
438
|
end
|
398
439
|
|
399
440
|
def dependency_injected?(component_type, value)
|
400
|
-
injected_dependency(component_type, value).
|
441
|
+
injected_dependency(component_type, value).present?
|
401
442
|
end
|
402
443
|
|
403
444
|
def dependencies
|
data/lib/glue_gun/version.rb
CHANGED