dumped_railers 0.3.1 → 0.4
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:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5025d07432c51021973eb7064be24d2a1cacbff2a31919c87341bc2f6a71693d
|
4
|
+
data.tar.gz: bbd212538475cda7a08278da201e151acbd13bfe8f05dd3558d257f485217ad2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 02f2ac6903602017cf440ba1c7431922dc600880665d4768da022031b62806673bae06d4a66bd6d134cab7a3e002734b453c76f838a0f256454094de3166eed4
|
7
|
+
data.tar.gz: 9d6d3ea246624629e0b1a24bd42ab301623e1fefe6699cb009b1558fed0e878c47fd41288c31ef5ca6e62fbb51e254cc57b71a0d139aad2f631063d6c541fe09
|
data/CHANGELOG.md
CHANGED
@@ -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.
|
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(
|
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(
|
112
|
-
attrs.
|
113
|
-
col
|
114
|
-
}
|
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 = -> (
|
122
|
+
masking_preprocessor = -> (model, attrs) { attrs.transform_values!(&:upcase) }
|
123
123
|
```
|
124
124
|
|
125
|
-
NOTE:
|
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
|
|
data/gemfiles/Gemfile.rails_6.1
CHANGED
@@ -11,11 +11,11 @@ module DumpedRailers
|
|
11
11
|
|
12
12
|
def build!
|
13
13
|
id = @record.id
|
14
|
-
attributes =
|
15
|
-
|
16
|
-
|
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(
|
11
|
-
attributes.
|
10
|
+
def call(_model, attributes)
|
11
|
+
attributes.delete_if { |column_name, _v|
|
12
12
|
@ignorable_columns.include?(column_name)
|
13
13
|
}
|
14
14
|
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.
|
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-
|
11
|
+
date: 2021-01-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|