glue_gun_dsl 0.1.10 → 0.1.11
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 +48 -16
- data/lib/glue_gun/version.rb +1 -1
- metadata +50 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: edbf3090421208672fdc17def682401b63dab26703932337106fc21e54e3a589
|
4
|
+
data.tar.gz: 5f7948854600c6472a35119724d5bcdff04e0ae333bc11278559e05432cac849
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5d20c2554f8908224286358e4f16f36ce52839db20103ccc3368554088c63fc6af82ae7de6a6d2ebbdf4a3974d7db66502cc7b809f70a9c3cca6f3cb495e0a0f
|
7
|
+
data.tar.gz: c01c8d848e36cd7632daddbac3b0f6e3d3f552a59649ce25fafc9aa1437d0d21fcbaa886e72cae1962bc1a3a8bc95ea8c839b00944793ea4f2e7193361ff4981
|
data/lib/glue_gun/dsl.rb
CHANGED
@@ -3,11 +3,14 @@ module GlueGun
|
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
5
|
included do
|
6
|
-
include
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
unless ancestors.include?(ActiveRecord::Base)
|
7
|
+
include ActiveModel::Model
|
8
|
+
include ActiveModel::Attributes
|
9
|
+
include ActiveModel::Validations
|
10
|
+
include ActiveModel::AttributeAssignment
|
11
|
+
include ActiveModel::Dirty
|
12
|
+
include ActiveRecord::Callbacks
|
13
|
+
end
|
11
14
|
|
12
15
|
class_attribute :attribute_definitions, instance_writer: false, default: {}
|
13
16
|
class_attribute :dependency_definitions, instance_writer: false, default: {}
|
@@ -18,7 +21,6 @@ module GlueGun
|
|
18
21
|
const_set(:AttributeMethods, attribute_methods_module)
|
19
22
|
prepend attribute_methods_module
|
20
23
|
|
21
|
-
# Prepend Initialization module to override initialize
|
22
24
|
prepend Initialization
|
23
25
|
|
24
26
|
# Prepend ClassMethods into the singleton class of the including class
|
@@ -31,10 +33,21 @@ module GlueGun
|
|
31
33
|
super(new_attributes)
|
32
34
|
propagate_changes if initialized?
|
33
35
|
end
|
36
|
+
|
37
|
+
if ancestors.include?(ActiveRecord::Base)
|
38
|
+
columns.each do |column|
|
39
|
+
# Skip if already defined via GlueGun::DSL's attribute method
|
40
|
+
next if attribute_definitions.key?(column.name.to_sym)
|
41
|
+
|
42
|
+
# Define a ConfigAttr for each ActiveRecord column
|
43
|
+
attribute(column.name.to_sym, column.type)
|
44
|
+
end
|
45
|
+
end
|
34
46
|
end
|
35
47
|
|
36
48
|
module Initialization
|
37
49
|
def initialize(attrs = {})
|
50
|
+
attrs ||= {}
|
38
51
|
attrs = attrs.symbolize_keys
|
39
52
|
# Separate dependency configurations from normal attributes
|
40
53
|
dependency_attributes = {}
|
@@ -56,9 +69,6 @@ module GlueGun
|
|
56
69
|
# Initialize dependencies after attributes have been set
|
57
70
|
initialize_dependencies(dependency_attributes)
|
58
71
|
|
59
|
-
# Validate the main object's attributes
|
60
|
-
validate!
|
61
|
-
|
62
72
|
@initialized = true
|
63
73
|
end
|
64
74
|
end
|
@@ -75,7 +85,7 @@ module GlueGun
|
|
75
85
|
attribute_definitions[name.to_sym] = { type: type, options: options }
|
76
86
|
|
77
87
|
# Define dirty tracking for the attribute
|
78
|
-
define_attribute_methods name
|
88
|
+
define_attribute_methods name unless ancestors.include?(ActiveRecord::Base)
|
79
89
|
|
80
90
|
attribute_methods_module = const_get(:AttributeMethods)
|
81
91
|
|
@@ -106,6 +116,14 @@ module GlueGun
|
|
106
116
|
instance_variable_get("@#{component_type}") ||
|
107
117
|
instance_variable_set("@#{component_type}", initialize_dependency(component_type))
|
108
118
|
end
|
119
|
+
|
120
|
+
attribute_methods_module = const_get(:AttributeMethods)
|
121
|
+
attribute_methods_module.class_eval do
|
122
|
+
define_method "#{component_type}=" do |init_args|
|
123
|
+
instance_variable_set("@#{component_type}", initialize_dependency(component_type, init_args))
|
124
|
+
# propagate_attribute_change(component_type, value) if initialized?
|
125
|
+
end
|
126
|
+
end
|
109
127
|
end
|
110
128
|
|
111
129
|
def inherited(subclass)
|
@@ -194,11 +212,6 @@ module GlueGun
|
|
194
212
|
value = attr_config.process_value(value, self) if attr_config.respond_to?(:process_value)
|
195
213
|
dep_attributes[attr_name] = value
|
196
214
|
end
|
197
|
-
|
198
|
-
# After getting the value, check if it's required and nil
|
199
|
-
if value.nil? && attr_config.required
|
200
|
-
raise ArgumentError, "Missing required attribute '#{attr_name}' for #{option_config.class_name}"
|
201
|
-
end
|
202
215
|
end
|
203
216
|
|
204
217
|
dep_attributes
|
@@ -242,7 +255,7 @@ module GlueGun
|
|
242
255
|
def instantiate_dependency(option_config, dep_attributes)
|
243
256
|
dependency_class = option_config.class_name
|
244
257
|
dependency_instance = dependency_class.new(dep_attributes)
|
245
|
-
dependency_instance.validate! if dependency_instance.respond_to?(:validate!)
|
258
|
+
dependency_instance.validate! if false # dependency_instance.respond_to?(:validate!)
|
246
259
|
dependency_instance
|
247
260
|
end
|
248
261
|
|
@@ -288,6 +301,25 @@ module GlueGun
|
|
288
301
|
@dependencies ||= {}
|
289
302
|
end
|
290
303
|
|
304
|
+
def validate_dependencies
|
305
|
+
errors.clear
|
306
|
+
self.class.dependency_definitions.keys.each do |component_type|
|
307
|
+
dependency = send(component_type)
|
308
|
+
|
309
|
+
# Only validate if the dependency responds to `valid?`
|
310
|
+
next unless dependency.respond_to?(:valid?) && !dependency.valid?
|
311
|
+
|
312
|
+
dependency.errors.each do |error|
|
313
|
+
if error.is_a?(ActiveModel::Error)
|
314
|
+
attribute = error.attribute
|
315
|
+
message = error.message
|
316
|
+
end
|
317
|
+
errors.add("#{component_type}.#{attribute}", message)
|
318
|
+
end
|
319
|
+
end
|
320
|
+
errors.none?
|
321
|
+
end
|
322
|
+
|
291
323
|
class ConfigAttr
|
292
324
|
attr_reader :name, :default, :required, :source, :block
|
293
325
|
|
data/lib/glue_gun/version.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.11
|
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-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activemodel
|
@@ -30,6 +30,26 @@ dependencies:
|
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '8'
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: activerecord
|
35
|
+
requirement: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: '6'
|
40
|
+
- - "<"
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: '8'
|
43
|
+
type: :runtime
|
44
|
+
prerelease: false
|
45
|
+
version_requirements: !ruby/object:Gem::Requirement
|
46
|
+
requirements:
|
47
|
+
- - ">="
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '6'
|
50
|
+
- - "<"
|
51
|
+
- !ruby/object:Gem::Version
|
52
|
+
version: '8'
|
33
53
|
- !ruby/object:Gem::Dependency
|
34
54
|
name: activesupport
|
35
55
|
requirement: !ruby/object:Gem::Requirement
|
@@ -64,6 +84,20 @@ dependencies:
|
|
64
84
|
- - ">="
|
65
85
|
- !ruby/object:Gem::Version
|
66
86
|
version: '0'
|
87
|
+
- !ruby/object:Gem::Dependency
|
88
|
+
name: combustion
|
89
|
+
requirement: !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - "~>"
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
version: '1.3'
|
94
|
+
type: :development
|
95
|
+
prerelease: false
|
96
|
+
version_requirements: !ruby/object:Gem::Requirement
|
97
|
+
requirements:
|
98
|
+
- - "~>"
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: '1.3'
|
67
101
|
- !ruby/object:Gem::Dependency
|
68
102
|
name: guard
|
69
103
|
requirement: !ruby/object:Gem::Requirement
|
@@ -134,6 +168,20 @@ dependencies:
|
|
134
168
|
- - "~>"
|
135
169
|
- !ruby/object:Gem::Version
|
136
170
|
version: '3.0'
|
171
|
+
- !ruby/object:Gem::Dependency
|
172
|
+
name: sqlite3
|
173
|
+
requirement: !ruby/object:Gem::Requirement
|
174
|
+
requirements:
|
175
|
+
- - "~>"
|
176
|
+
- !ruby/object:Gem::Version
|
177
|
+
version: '1.4'
|
178
|
+
type: :development
|
179
|
+
prerelease: false
|
180
|
+
version_requirements: !ruby/object:Gem::Requirement
|
181
|
+
requirements:
|
182
|
+
- - "~>"
|
183
|
+
- !ruby/object:Gem::Version
|
184
|
+
version: '1.4'
|
137
185
|
description: GlueGun makes dependency injection and hydration a first-order concern
|
138
186
|
email:
|
139
187
|
- brett.shollenberger@gmail.com
|