glue_gun_dsl 0.1.5 → 0.1.7
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 +29 -5
- data/lib/glue_gun/version.rb +1 -1
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fd26c5b4ba6c9831e91835a2d771d9cec019b94d25124e68ed006ba40aa545e8
|
4
|
+
data.tar.gz: 7d5572e0ff530ef4ed03b2ae8b8cde2261b7215fed9cec34f81722a0238287b6
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5847c254dfe071b87b731d835a50b62be82f9c7638b281174e3aacd60cc29621c8c7027abcb09597e426b2275b7183b2ba8b6dd6f1fc192e0d50f7c4bc65b954
|
7
|
+
data.tar.gz: ebcea322a43228b6912176dfd7bb3a66df37da5ea5ce82c1415d1fe93ab1961b1ce7a244da3590a627488d0d6c62a24f9fe3a70d055679d347077276b127d011
|
data/lib/glue_gun/dsl.rb
CHANGED
@@ -7,6 +7,7 @@ module GlueGun
|
|
7
7
|
include ActiveModel::Attributes
|
8
8
|
include ActiveModel::Validations
|
9
9
|
include ActiveModel::AttributeAssignment
|
10
|
+
include ActiveModel::Dirty
|
10
11
|
|
11
12
|
class_attribute :attribute_definitions, instance_writer: false, default: {}
|
12
13
|
class_attribute :dependency_definitions, instance_writer: false, default: {}
|
@@ -24,16 +25,22 @@ module GlueGun
|
|
24
25
|
class << self
|
25
26
|
prepend ClassMethods
|
26
27
|
end
|
28
|
+
|
29
|
+
# Overriding ActiveModel.assign_attributes to ensure change propagation to dependenices
|
30
|
+
def assign_attributes(new_attributes)
|
31
|
+
super(new_attributes)
|
32
|
+
propagate_changes if initialized?
|
33
|
+
end
|
27
34
|
end
|
28
35
|
|
29
36
|
module Initialization
|
30
|
-
def initialize(
|
31
|
-
|
37
|
+
def initialize(attrs = {})
|
38
|
+
attrs = attrs.symbolize_keys
|
32
39
|
# Separate dependency configurations from normal attributes
|
33
40
|
dependency_attributes = {}
|
34
41
|
normal_attributes = {}
|
35
42
|
|
36
|
-
|
43
|
+
attrs.each do |key, value|
|
37
44
|
if self.class.dependency_definitions.key?(key)
|
38
45
|
dependency_attributes[key] = value
|
39
46
|
else
|
@@ -57,12 +64,19 @@ module GlueGun
|
|
57
64
|
end
|
58
65
|
|
59
66
|
module ClassMethods
|
67
|
+
DEFAULT_TYPE = if ActiveModel.version >= Gem::Version.new("7")
|
68
|
+
nil
|
69
|
+
elsif ActiveModel.version >= Gem::Version.new("5")
|
70
|
+
ActiveModel::Type::Value.new
|
71
|
+
end
|
60
72
|
# Override the attribute method to define custom setters
|
61
|
-
def attribute(name, type =
|
62
|
-
# Call the original attribute method from ActiveModel::Attributes
|
73
|
+
def attribute(name, type = DEFAULT_TYPE, **options)
|
63
74
|
super(name, type, **options)
|
64
75
|
attribute_definitions[name.to_sym] = { type: type, options: options }
|
65
76
|
|
77
|
+
# Define dirty tracking for the attribute
|
78
|
+
define_attribute_methods name
|
79
|
+
|
66
80
|
attribute_methods_module = const_get(:AttributeMethods)
|
67
81
|
|
68
82
|
attribute_methods_module.class_eval do
|
@@ -234,6 +248,16 @@ module GlueGun
|
|
234
248
|
dependency_instance
|
235
249
|
end
|
236
250
|
|
251
|
+
def propagate_changes
|
252
|
+
changed_attributes.each do |attr_name, _old_value|
|
253
|
+
new_value = read_attribute(attr_name)
|
254
|
+
propagate_attribute_change(attr_name, new_value)
|
255
|
+
end
|
256
|
+
|
257
|
+
# Clear the changes after propagation
|
258
|
+
changes_applied
|
259
|
+
end
|
260
|
+
|
237
261
|
def propagate_attribute_change(attr_name, value)
|
238
262
|
self.class.dependency_definitions.each do |component_type, _dependency_builder|
|
239
263
|
dependency_instance = send(component_type)
|
data/lib/glue_gun/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brett Shollenberger
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: '8'
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '6'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: '8'
|
@@ -36,7 +36,7 @@ dependencies:
|
|
36
36
|
requirements:
|
37
37
|
- - ">="
|
38
38
|
- !ruby/object:Gem::Version
|
39
|
-
version: '
|
39
|
+
version: '6'
|
40
40
|
- - "<"
|
41
41
|
- !ruby/object:Gem::Version
|
42
42
|
version: '8'
|
@@ -46,10 +46,24 @@ dependencies:
|
|
46
46
|
requirements:
|
47
47
|
- - ">="
|
48
48
|
- !ruby/object:Gem::Version
|
49
|
-
version: '
|
49
|
+
version: '6'
|
50
50
|
- - "<"
|
51
51
|
- !ruby/object:Gem::Version
|
52
52
|
version: '8'
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
name: appraisal
|
55
|
+
requirement: !ruby/object:Gem::Requirement
|
56
|
+
requirements:
|
57
|
+
- - ">="
|
58
|
+
- !ruby/object:Gem::Version
|
59
|
+
version: '0'
|
60
|
+
type: :development
|
61
|
+
prerelease: false
|
62
|
+
version_requirements: !ruby/object:Gem::Requirement
|
63
|
+
requirements:
|
64
|
+
- - ">="
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
53
67
|
- !ruby/object:Gem::Dependency
|
54
68
|
name: guard
|
55
69
|
requirement: !ruby/object:Gem::Requirement
|