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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: bbf26caa4bc2f3c06841bbca6d9d439a810ad68825ebaae2b75d72d44a7a5d2d
4
- data.tar.gz: 4b2f72384af585541e217397ecf02962a9b8e536ec5ea2a0091f832ded92901d
3
+ metadata.gz: 43a4d648f92b357bd4751c7f4961b57d6f5d306b90c97ebb0dff6be7f7b4c932
4
+ data.tar.gz: 89c802bf38daaa3ab9238073af9f6bdf761bd0b67b234c2283b9f0fd7270129d
5
5
  SHA512:
6
- metadata.gz: c41c8f75d47f57ab3142808e2ba029fbf99956860577f9a2e8ab1d777d89cd78166f7626644c1922df017eeaea6417e778746953345686b492bc4db6247d6fff
7
- data.tar.gz: c28e25054a89c6cc5b16cac8f54279c33dcedab48e92c24cdb14ea1f0958fd543b75207740b423323c2dbfcd564ad004c0f578030b1a6b46cb71b059295180c9
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 ")
@@ -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
@@ -1,3 +1,3 @@
1
1
  module LiveFixtures
2
- VERSION = "3.0.0"
2
+ VERSION = "3.1.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: live_fixtures
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.0.0
4
+ version: 3.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - jleven