dumped_railers 0.3.1 → 0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cbb1709558461827585966be0f48b9741555fc9d70cd22a6c7970cb22260e6a6
4
- data.tar.gz: f4db2cebc825ff52aeda68f2e06e466dd16663172e4b76289347374e35b046d4
3
+ metadata.gz: 5025d07432c51021973eb7064be24d2a1cacbff2a31919c87341bc2f6a71693d
4
+ data.tar.gz: bbd212538475cda7a08278da201e151acbd13bfe8f05dd3558d257f485217ad2
5
5
  SHA512:
6
- metadata.gz: 51ddf56172e72afb4977cb899be013ac6678627905df7e90b6dc147b2afcfd0b2b6c9cd010e8a9a500dd9aa48ccc2a0ff70cf82fc02778fa7ef505f0d8df7f52
7
- data.tar.gz: 24ee1c963fb89cb99dfcb2064c3d77e0e626525a14452e362aa12aeb9dd9f5f6409feb5c44a8f53ecb91d1eacd92f4793c8ab440714b1177a24d4d573048e7f0
6
+ metadata.gz: 02f2ac6903602017cf440ba1c7431922dc600880665d4768da022031b62806673bae06d4a66bd6d134cab7a3e002734b453c76f838a0f256454094de3166eed4
7
+ data.tar.gz: 9d6d3ea246624629e0b1a24bd42ab301623e1fefe6699cb009b1558fed0e878c47fd41288c31ef5ca6e62fbb51e254cc57b71a0d139aad2f631063d6c541fe09
@@ -44,6 +44,13 @@
44
44
  ### Added
45
45
  - Support `before_save`/`after_save` callbacks with import! method. The callbacks are invoked just before (or after) each table's records are saved.
46
46
 
47
- ## [0.3.0]
47
+ ## [0.3.1]
48
48
  ### Added
49
49
  - Accept multiple (array) callbacks for `before_save` / `after_save` arguments with DumpedRailers.import!.
50
+
51
+ ## [0.4.0]
52
+ ### Changed
53
+ - **BREAKING** preprocessor interface has changed so as that its API have consistency with that of callbacks.
54
+ - Preprocessors now require arguments (`model`, `attributes`) in this order. Before version < 0.4, it was (`attributes`, `model`)
55
+ - Attributes needs to be updated destructively within preprocessors. Return values are no longer required reflect the changes.
56
+
data/README.md CHANGED
@@ -103,15 +103,15 @@ end
103
103
  DumpedRailers.dump!(User, Item, base_dir: 'tmp/', preprocessors: [MaskingPreprocessor.new])
104
104
  ```
105
105
 
106
- * "Preprocessors" can be lambda, or module, or any objects that can repond to #call(atrs, model).
106
+ * "Preprocessors" can be lambda, or module, or any objects that can repond to #call(model, attributes).
107
107
 
108
108
 
109
109
  ```ruby
110
110
  class MaskingPreprocessor
111
- def call(attrs, model)
112
- attrs.map { |col, value|
113
- col.match?(/password/) ? [col, '<MASKED>'] : [col, value]
114
- }.to_h
111
+ def call(model, attrs)
112
+ attrs.each { |col, _value|
113
+ attrs[col] = '<MASKED>' if col.match?(/password/)
114
+ }
115
115
  end
116
116
  end
117
117
  ```
@@ -119,10 +119,12 @@ end
119
119
  * a lambda object can be accepted as well
120
120
 
121
121
  ```ruby
122
- masking_preprocessor = -> (attrs, model) { attrs.transform_values(&:upcase) }
122
+ masking_preprocessor = -> (model, attrs) { attrs.transform_values!(&:upcase) }
123
123
  ```
124
124
 
125
- NOTE: The proprocessors must return attributes in the same format `{ attributes_name: value }` so that preprocessors and dump handlers can preprocessors in nested manner.
125
+ NOTE:
126
+ * In order to reflect changes to the output, **preprocessors must change the attributes destructively**.
127
+ * If you set multiple preprocessors, each preprocessor will be invoked sequentially from left to right, which means your second preprocessor receives attributes only after your first preprocessor update them.
126
128
 
127
129
  ### Limiting Import with Authorized Models Only
128
130
 
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
3
  # Specify your gem's dependencies in dumped_railers.gemspec
4
- gem 'activerecord', '6.1.0'
4
+ gem 'activerecord', '6.1.1'
5
5
 
6
6
  gemspec path: '../'
@@ -11,11 +11,11 @@ module DumpedRailers
11
11
 
12
12
  def build!
13
13
  id = @record.id
14
- attributes =
15
- @preprocessors.inject(@record.attributes) { |attrs, preprocessor|
16
- preprocessor.call(attrs, @model)
17
- }
18
-
14
+ attributes = @record.attributes.deep_dup
15
+ @preprocessors.each do |preprocessor|
16
+ preprocessor.call(@model, attributes)
17
+ end
18
+
19
19
  # convert "belong_to association" foreign keys into record-unique labels
20
20
  @model.reflect_on_all_associations.select(&:belongs_to?).each do |rel|
21
21
  # skip ignorables
@@ -39,15 +39,15 @@ module DumpedRailers
39
39
 
40
40
  [record_label_for(@model.name, id), attributes]
41
41
  end
42
-
42
+
43
43
  private
44
-
44
+
45
45
  def record_label_for(class_name, id, type=nil)
46
46
  return nil unless id
47
47
 
48
48
  identifier = "#{class_name.to_s.underscore}_#{id}"
49
49
  type_specifier = "(#{type})" if type
50
-
50
+
51
51
  "__#{identifier}#{type_specifier}"
52
52
  end
53
53
  end
@@ -7,8 +7,8 @@ module DumpedRailers
7
7
  @ignorable_columns = ignorable_columns.compact.map(&:to_s)
8
8
  end
9
9
 
10
- def call(attributes, _model)
11
- attributes.reject { |column_name, _v|
10
+ def call(_model, attributes)
11
+ attributes.delete_if { |column_name, _v|
12
12
  @ignorable_columns.include?(column_name)
13
13
  }
14
14
  end
@@ -1,3 +1,3 @@
1
1
  module DumpedRailers
2
- VERSION = '0.3.1'
2
+ VERSION = '0.4'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dumped_railers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: '0.4'
5
5
  platform: ruby
6
6
  authors:
7
7
  - Koji Onishi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-01-08 00:00:00.000000000 Z
11
+ date: 2021-01-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler