fabrication 2.29.0 → 2.31.0
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/fabrication/generator/base.rb +24 -7
- data/lib/fabrication/generator/sequel.rb +19 -7
- data/lib/fabrication/schematic/manager.rb +1 -1
- data/lib/fabrication/sequencer.rb +1 -1
- data/lib/fabrication/support.rb +3 -3
- data/lib/fabrication/version.rb +1 -1
- data/lib/fabrication.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3efaba7356d0a3fcade7fe08a68719f8d0f452bc8cd72a88e087c10434931745
|
4
|
+
data.tar.gz: 1beb71f4903b74255a06c46ee6ca15e464d3ed6b0400a02ba01cd65cefd205a7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 04bd08bc59c91ff463cac12869d0a4211b969f50635748e830842e62198c9f9ec7dad7bebbc1db32d6e65fd46d76559041da27c689d067d65835978ade6fb86d
|
7
|
+
data.tar.gz: 6a4259285d0c8f8787df5a8a6d9dcfe823de65282a50873e06d0660b94bd3f0051a0bfd5e64f6fe6b809637782404646e55c0889a793fd9f70dd7b19ef43a70c
|
@@ -11,6 +11,9 @@ module Fabrication
|
|
11
11
|
if callbacks[:initialize_with]
|
12
12
|
build_instance_with_constructor_override(callbacks[:initialize_with])
|
13
13
|
elsif callbacks[:on_init]
|
14
|
+
Fabrication::Support.log_deprecation(
|
15
|
+
'The on_init callback has been replaced by initialize_with. Please see the documentation for usage'
|
16
|
+
)
|
14
17
|
build_instance_with_init_callback(callbacks[:on_init])
|
15
18
|
else
|
16
19
|
build_instance
|
@@ -19,18 +22,29 @@ module Fabrication
|
|
19
22
|
_instance
|
20
23
|
end
|
21
24
|
|
22
|
-
def create(attributes = [], callbacks =
|
25
|
+
def create(attributes = [], callbacks = {})
|
23
26
|
build(attributes, callbacks)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
+
execute_deprecated_callbacks(callbacks, :before_validation, :before_create)
|
28
|
+
execute_deprecated_callbacks(callbacks, :after_validation, :before_create)
|
29
|
+
execute_deprecated_callbacks(callbacks, :before_save, :before_create)
|
27
30
|
execute_callbacks(callbacks[:before_create])
|
28
31
|
persist
|
29
32
|
execute_callbacks(callbacks[:after_create])
|
30
|
-
|
33
|
+
execute_deprecated_callbacks(callbacks, :after_save, :after_create)
|
31
34
|
_instance
|
32
35
|
end
|
33
36
|
|
37
|
+
def execute_deprecated_callbacks(callbacks, callback_type, replacement_callback)
|
38
|
+
if callbacks[callback_type]
|
39
|
+
Fabrication::Support.log_deprecation(
|
40
|
+
"Using #{callback_type} is deprecated but you can replace it " \
|
41
|
+
"with #{replacement_callback} with the same result."
|
42
|
+
)
|
43
|
+
end
|
44
|
+
|
45
|
+
execute_callbacks(callbacks[callback_type])
|
46
|
+
end
|
47
|
+
|
34
48
|
def execute_callbacks(callbacks)
|
35
49
|
callbacks&.each { |callback| _instance.instance_exec(_instance, _transient_attributes, &callback) }
|
36
50
|
end
|
@@ -96,18 +110,21 @@ module Fabrication
|
|
96
110
|
|
97
111
|
protected
|
98
112
|
|
99
|
-
attr_accessor :resolved_class, :_instance
|
113
|
+
attr_accessor :resolved_class, :_instance
|
100
114
|
|
101
115
|
def _attributes
|
102
116
|
@_attributes ||= {}
|
103
117
|
end
|
104
118
|
|
119
|
+
def _transient_attributes
|
120
|
+
@_transient_attributes ||= {}
|
121
|
+
end
|
122
|
+
|
105
123
|
def persist
|
106
124
|
_instance.save! if _instance.respond_to?(:save!)
|
107
125
|
end
|
108
126
|
|
109
127
|
def process_attributes(attributes)
|
110
|
-
self._transient_attributes = ({})
|
111
128
|
attributes.each do |attribute|
|
112
129
|
_attributes[attribute.name] = attribute.processed_value(_attributes)
|
113
130
|
_transient_attributes[attribute.name] = _attributes[attribute.name] if attribute.transient?
|
@@ -11,14 +11,11 @@ module Fabrication
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def set_attributes
|
14
|
-
_attributes.each do |
|
15
|
-
if
|
16
|
-
|
17
|
-
_instance.after_save_hook do
|
18
|
-
value.each { |o| _instance.send(reflection.add_method, o) }
|
19
|
-
end
|
14
|
+
_attributes.each do |field_name, value|
|
15
|
+
if value.is_a?(Array) && (association = association_for(field_name))
|
16
|
+
set_association(association, field_name, value)
|
20
17
|
else
|
21
|
-
|
18
|
+
set_attribute(field_name, value)
|
22
19
|
end
|
23
20
|
end
|
24
21
|
end
|
@@ -29,6 +26,21 @@ module Fabrication
|
|
29
26
|
|
30
27
|
private
|
31
28
|
|
29
|
+
def association_for(field_name)
|
30
|
+
resolved_class.association_reflections[field_name]
|
31
|
+
end
|
32
|
+
|
33
|
+
def set_attribute(field_name, value)
|
34
|
+
_instance.send("#{field_name}=", value)
|
35
|
+
end
|
36
|
+
|
37
|
+
def set_association(association, field_name, value)
|
38
|
+
_instance.associations[field_name] = value
|
39
|
+
_instance.after_save_hook do
|
40
|
+
value.each { |o| _instance.send(association.add_method, o) }
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
32
44
|
def load_instance_hooks
|
33
45
|
klass = resolved_class.respond_to?(:cti_base_model) ? resolved_class.cti_models.first : resolved_class
|
34
46
|
klass.plugin :instance_hooks unless klass.new.respond_to? :after_save_hook
|
data/lib/fabrication/support.rb
CHANGED
@@ -34,9 +34,9 @@ module Fabrication
|
|
34
34
|
if name_string.respond_to?(:camelize)
|
35
35
|
name_string.camelize
|
36
36
|
else
|
37
|
-
name_string
|
38
|
-
"::#{Regexp.last_match(1).upcase}"
|
39
|
-
|
37
|
+
name_string
|
38
|
+
.gsub(%r{/(.?)}) { "::#{Regexp.last_match(1).upcase}" }
|
39
|
+
.gsub(/(?:^|_)(.)/) { Regexp.last_match(1).upcase }
|
40
40
|
end
|
41
41
|
end
|
42
42
|
|
data/lib/fabrication/version.rb
CHANGED
data/lib/fabrication.rb
CHANGED
@@ -51,7 +51,7 @@ module Fabrication
|
|
51
51
|
end
|
52
52
|
|
53
53
|
def self.schematics
|
54
|
-
Support.log_deprecation('Fabrication.schematics has been replaced by '\
|
54
|
+
Support.log_deprecation('Fabrication.schematics has been replaced by ' \
|
55
55
|
'Fabrication.manager and will be removed in 3.0.0.')
|
56
56
|
manager
|
57
57
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: fabrication
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.31.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul Elliott
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2023-11-27 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Fabrication is an object generation framework for ActiveRecord, Mongoid,
|
14
14
|
DataMapper, Sequel, or any other Ruby object.
|
@@ -70,14 +70,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
70
70
|
requirements:
|
71
71
|
- - ">="
|
72
72
|
- !ruby/object:Gem::Version
|
73
|
-
version:
|
73
|
+
version: 3.0.0
|
74
74
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
75
|
requirements:
|
76
76
|
- - ">="
|
77
77
|
- !ruby/object:Gem::Version
|
78
78
|
version: '0'
|
79
79
|
requirements: []
|
80
|
-
rubygems_version: 3.
|
80
|
+
rubygems_version: 3.4.10
|
81
81
|
signing_key:
|
82
82
|
specification_version: 4
|
83
83
|
summary: Generates object instances for test suites, seed files, etc.
|