live_fixtures 3.0.0 → 3.1.1
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/CHANGELOG.md +8 -0
- data/lib/live_fixtures/export/fixture.rb +5 -3
- data/lib/live_fixtures/export.rb +3 -2
- data/lib/live_fixtures/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: 43a4d648f92b357bd4751c7f4961b57d6f5d306b90c97ebb0dff6be7f7b4c932
|
|
4
|
+
data.tar.gz: 89c802bf38daaa3ab9238073af9f6bdf761bd0b67b234c2283b9f0fd7270129d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: eecf0c868c069a33fcdb2d1ac38dce617409b28eba873149bab74fbcb802324b2b2921d0afb982de1142bc02036e467cef658de71ddaacd0a9e51b514f0a6f51
|
|
7
|
+
data.tar.gz: c37c360ccf11eb29c09308827cde01948fab84201ba6b2228b50eec31352d8c106a5e263e6ee8207f11dbb35f2788d8866e2e1182f8250a867b4ec63a8fd25f7
|
data/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,14 @@
|
|
|
2
2
|
All notable changes to this project will be documented in this file.
|
|
3
3
|
This project adheres to [Semantic Versioning](http://semver.org/).
|
|
4
4
|
|
|
5
|
+
## [3.1.1] - 2024-04-04
|
|
6
|
+
### Fixed
|
|
7
|
+
Expose the `skip_attributes` option in LiveFixtures::Export.
|
|
8
|
+
|
|
9
|
+
## [3.1.0] - 2024-04-04
|
|
10
|
+
### Added
|
|
11
|
+
It's now possible to specify a list of attributes to skip while exporting.
|
|
12
|
+
|
|
5
13
|
## [3.0.0] - 2023-07-24
|
|
6
14
|
### Added
|
|
7
15
|
support ruby >= 3.1
|
|
@@ -7,15 +7,16 @@ module LiveFixtures::Export::Fixture
|
|
|
7
7
|
# @param model [ActiveRecord::Base] an ActiveRecord record to serialize
|
|
8
8
|
# @param references [Symbol, Array<Symbol>] the names of associations whose foreign_keys should be replaced with references
|
|
9
9
|
# @param more_attributes [Hash{String => Time, DateTime, Date, Hash, String, LiveFixtures::Export::Template, LiveFixtures::Export::Reference, #to_s}] a hash of additional attributes to serialize with each record.
|
|
10
|
+
# @param skip_attributes [Array<String>] a list of attributes to skip when serializing the model
|
|
10
11
|
# @return [String] the model serialized in YAML, with specified foreign_keys replaced by references, including additional attributes.
|
|
11
|
-
def to_yaml(model, references = [], more_attributes = {})
|
|
12
|
+
def to_yaml(model, references = [], more_attributes = {}, skip_attributes: [])
|
|
12
13
|
table_name = model.class.table_name
|
|
13
14
|
|
|
14
15
|
more_attributes.merge! attributes_from_references(model, references)
|
|
15
16
|
|
|
16
17
|
<<-YML
|
|
17
18
|
#{table_name}_#{model.id || SecureRandom.uuid.underscore}:
|
|
18
|
-
#{yml_attributes(model, more_attributes)}
|
|
19
|
+
#{yml_attributes(model, more_attributes, skip_attributes)}
|
|
19
20
|
|
|
20
21
|
YML
|
|
21
22
|
end
|
|
@@ -35,9 +36,10 @@ module LiveFixtures::Export::Fixture
|
|
|
35
36
|
end
|
|
36
37
|
end
|
|
37
38
|
|
|
38
|
-
private_class_method def yml_attributes(model, more_attributes)
|
|
39
|
+
private_class_method def yml_attributes(model, more_attributes, skip_attributes)
|
|
39
40
|
model.attributes.except("id").merge(more_attributes).map do |name, value|
|
|
40
41
|
next if value.nil?
|
|
42
|
+
next if skip_attributes.include?(name)
|
|
41
43
|
|
|
42
44
|
serialize_attribute(model, name, value)
|
|
43
45
|
end.compact.join("\n ")
|
data/lib/live_fixtures/export.rb
CHANGED
|
@@ -48,6 +48,7 @@ module LiveFixtures::Export
|
|
|
48
48
|
# Export models to a yml file named after the corresponding table.
|
|
49
49
|
# @param models [Enumerable] an Enumerable containing ActiveRecord models.
|
|
50
50
|
# @param with_references [Array<Symbol>] the associations whose foreign_keys should be replaced with references.
|
|
51
|
+
# @param skip_attributes [Array<String>] the attributes to skip when exporting the model.
|
|
51
52
|
#
|
|
52
53
|
# Takes an optional block that will be invoked for each model.
|
|
53
54
|
# The block should return a hash of attributes to be merged and
|
|
@@ -55,7 +56,7 @@ module LiveFixtures::Export
|
|
|
55
56
|
# @yield [model] an optional block that will be invoked for each model.
|
|
56
57
|
# @yieldparam model [ActiveRecord::Base] each successive model.
|
|
57
58
|
# @yieldreturn [Hash{String => Object}] a hash of attributes to be merged and saved with the model's attributes.
|
|
58
|
-
def export_fixtures(models, with_references = [])
|
|
59
|
+
def export_fixtures(models, with_references = [], skip_attributes: [])
|
|
59
60
|
return [] unless models.present?
|
|
60
61
|
|
|
61
62
|
model_class = models.first.class
|
|
@@ -70,7 +71,7 @@ module LiveFixtures::Export
|
|
|
70
71
|
|
|
71
72
|
iterator.new(models).each do |model|
|
|
72
73
|
more_attributes = block_given? ? yield(model) : {}
|
|
73
|
-
file.write Fixture.to_yaml(model, with_references, more_attributes)
|
|
74
|
+
file.write Fixture.to_yaml(model, with_references, more_attributes, skip_attributes: skip_attributes)
|
|
74
75
|
end
|
|
75
76
|
end
|
|
76
77
|
end
|