fabrication 2.29.0 → 2.30.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/fabrication/generator/base.rb +24 -7
- data/lib/fabrication/generator/sequel.rb +19 -7
- data/lib/fabrication/support.rb +3 -3
- data/lib/fabrication/version.rb +1 -1
- data/lib/fabrication.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 38d9550f8e85412ca21c540ad7f850a61f9f511dce7048487c8cfc49f965922d
|
4
|
+
data.tar.gz: a2e732f74342b3342584483af9b2a446f4bf42fea8af50edbf1d792203e4d16b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: bc4ed3c24fcd1d18ffff850a98d35fafe5408e2b166d234944a82d34e272a9a1fa1da1dff5df6677f7d083ac7cade969f10dcdc95e2fe8cb2b45d3f1719096e8
|
7
|
+
data.tar.gz: 28ad7426b1426f3b1f284bf1cf172397b83734b3865f91d64e755995da846f5bf4efc4629e90ee7a800c309e9f39898fac5ff3c87ab2607e7c0a6290d57490f8
|
@@ -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.30.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: 2022-
|
11
|
+
date: 2022-07-25 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.
|
@@ -77,7 +77,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
77
77
|
- !ruby/object:Gem::Version
|
78
78
|
version: '0'
|
79
79
|
requirements: []
|
80
|
-
rubygems_version: 3.
|
80
|
+
rubygems_version: 3.3.7
|
81
81
|
signing_key:
|
82
82
|
specification_version: 4
|
83
83
|
summary: Generates object instances for test suites, seed files, etc.
|