live_fixtures 2.2.0 → 3.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +15 -0
- data/lib/live_fixtures/export/fixture.rb +5 -3
- data/lib/live_fixtures/export.rb +3 -2
- data/lib/live_fixtures/import/fixtures.rb +5 -5
- data/lib/live_fixtures/version.rb +1 -1
- metadata +8 -8
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,21 @@
|
|
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
|
+
|
13
|
+
## [3.0.0] - 2023-07-24
|
14
|
+
### Added
|
15
|
+
support ruby >= 3.1
|
16
|
+
|
17
|
+
### Removed
|
18
|
+
drop support for ruby < 3.1, rails < 6.0
|
19
|
+
|
5
20
|
## [2.2.0] - 2020-12-09
|
6
21
|
### Added
|
7
22
|
support rails 6, ruby 1.66, 1.7.2
|
@@ -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
|
@@ -66,12 +66,12 @@ class LiveFixtures::Import
|
|
66
66
|
end
|
67
67
|
|
68
68
|
join_table_rows.each do |table_name, rows|
|
69
|
-
rows.each do |
|
70
|
-
targets.each do |target|
|
69
|
+
rows.each do |row|
|
70
|
+
row[:targets].each do |target|
|
71
71
|
assoc_fk = @label_to_id[target] || target
|
72
|
-
|
73
|
-
|
74
|
-
yield [table_name, NO_LABEL,
|
72
|
+
row_with_fk = { row[:association].foreign_key => fetch_id_for_label(row[:label]),
|
73
|
+
row[:association].association_foreign_key => assoc_fk }
|
74
|
+
yield [table_name, NO_LABEL, row_with_fk]
|
75
75
|
end
|
76
76
|
end
|
77
77
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: live_fixtures
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 3.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- jleven
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 1980-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|
@@ -16,7 +16,7 @@ dependencies:
|
|
16
16
|
requirements:
|
17
17
|
- - ">="
|
18
18
|
- !ruby/object:Gem::Version
|
19
|
-
version: '
|
19
|
+
version: '6.0'
|
20
20
|
- - "<"
|
21
21
|
- !ruby/object:Gem::Version
|
22
22
|
version: 7.0.0
|
@@ -26,7 +26,7 @@ dependencies:
|
|
26
26
|
requirements:
|
27
27
|
- - ">="
|
28
28
|
- !ruby/object:Gem::Version
|
29
|
-
version: '
|
29
|
+
version: '6.0'
|
30
30
|
- - "<"
|
31
31
|
- !ruby/object:Gem::Version
|
32
32
|
version: 7.0.0
|
@@ -106,14 +106,14 @@ dependencies:
|
|
106
106
|
requirements:
|
107
107
|
- - "~>"
|
108
108
|
- !ruby/object:Gem::Version
|
109
|
-
version: '
|
109
|
+
version: '4.0'
|
110
110
|
type: :development
|
111
111
|
prerelease: false
|
112
112
|
version_requirements: !ruby/object:Gem::Requirement
|
113
113
|
requirements:
|
114
114
|
- - "~>"
|
115
115
|
- !ruby/object:Gem::Version
|
116
|
-
version: '
|
116
|
+
version: '4.0'
|
117
117
|
- !ruby/object:Gem::Dependency
|
118
118
|
name: byebug
|
119
119
|
requirement: !ruby/object:Gem::Requirement
|
@@ -227,14 +227,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
227
227
|
requirements:
|
228
228
|
- - ">="
|
229
229
|
- !ruby/object:Gem::Version
|
230
|
-
version: '
|
230
|
+
version: '3.1'
|
231
231
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
232
232
|
requirements:
|
233
233
|
- - ">="
|
234
234
|
- !ruby/object:Gem::Version
|
235
235
|
version: '0'
|
236
236
|
requirements: []
|
237
|
-
rubygems_version: 3.
|
237
|
+
rubygems_version: 3.4.13
|
238
238
|
signing_key:
|
239
239
|
specification_version: 4
|
240
240
|
summary: Tools for exporting and importing between databases managed by ActiveRecord.
|