flextures 4.2.7 → 4.2.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/flextures/flextures_dumper.rb +21 -12
- data/lib/flextures/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cf2d34b2424a6a16564ed647a928edb9192b5b1182605393cceba57b1c097972
|
4
|
+
data.tar.gz: 27c93837bf4afb4ab4dfacd5a7f1dadb85491c0b7093287525a012bd899705fd
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee0c12d7492320c6664273390d730e9729df0af8ef02e28a06a3dbdd51ce22124c55555e9f372d0b8d6d2efb471a9659b535d59e168501c4d90086c4a0768ab0
|
7
|
+
data.tar.gz: 5f63de4503c68eaac01dc6a3c9142af82f78b5748ec9c9073b25597080bd52014959d61080fa9294c690f472ef1f504ded820ee8b086eb98587afc38482b4a97
|
data/Gemfile.lock
CHANGED
@@ -146,6 +146,12 @@ module Flextures
|
|
146
146
|
[proc { |d| d.to_s }]
|
147
147
|
self.translate_creater d, procs
|
148
148
|
},
|
149
|
+
enum:->( d, format ){
|
150
|
+
procs = (format == :yml) ?
|
151
|
+
[:blankstr, :nullstr, :ymlspecialstr] :
|
152
|
+
[:null, proc{ |s| s.to_s.gsub(/\r\n/,"\n").gsub(/\r/,"\n") } ]
|
153
|
+
self.translate_creater d, procs
|
154
|
+
},
|
149
155
|
# use null only value
|
150
156
|
null:->( d, format ){
|
151
157
|
format==:yml ? "null" : ""
|
@@ -158,8 +164,8 @@ module Flextures
|
|
158
164
|
# @params [Symbol] format data type (:yml or :csv)
|
159
165
|
# @return translated value
|
160
166
|
def self.trans(v, type, format)
|
161
|
-
|
162
|
-
return
|
167
|
+
translater = TRANSLATER[type]
|
168
|
+
return translater.call(v, format) if translater
|
163
169
|
v
|
164
170
|
end
|
165
171
|
|
@@ -168,7 +174,10 @@ module Flextures
|
|
168
174
|
# @params [Hash] options dump options
|
169
175
|
# @return [Array] columns format information
|
170
176
|
def self.dump_attributes(klass, options)
|
171
|
-
columns = klass.columns.map
|
177
|
+
columns = klass.columns.map do |column|
|
178
|
+
type_name = klass.defined_enums[column.name.to_s] ? :enum : column.type
|
179
|
+
{ name: column.name, type: type_name }
|
180
|
+
end
|
172
181
|
# option[:minus] colum is delete columns
|
173
182
|
columns.reject! { |column| options[:minus].include?(column[:name]) } if options[:minus]
|
174
183
|
# option[:plus] colum is new columns
|
@@ -183,10 +192,10 @@ module Flextures
|
|
183
192
|
# @params [Hash] options options
|
184
193
|
# @params [Symbol] type format type (:yml or :csv)
|
185
194
|
# @return [Proc] filter function
|
186
|
-
def self.create_filter(
|
195
|
+
def self.create_filter(attr_types, format, type)
|
187
196
|
filter = DumpFilter[format[:table].to_s.to_sym] || {}
|
188
197
|
->(row) {
|
189
|
-
|
198
|
+
attr_types.map do |h|
|
190
199
|
v = filter[h[:name].to_sym] ? filter[h[:name].to_sym].call(row[h[:name]]) : trans(row[h[:name]], h[:type], type)
|
191
200
|
[h[:name],v]
|
192
201
|
end
|
@@ -198,13 +207,13 @@ module Flextures
|
|
198
207
|
# @params [Hash] options dump format options
|
199
208
|
def self.csv(format)
|
200
209
|
klass = PARENT.create_model(format[:table])
|
201
|
-
|
202
|
-
filter = self.create_filter
|
203
|
-
self.dump_csv klass,
|
210
|
+
attr_types = self.dump_attributes klass, format
|
211
|
+
filter = self.create_filter attr_types, format, :csv
|
212
|
+
self.dump_csv klass, attr_types, filter, format
|
204
213
|
end
|
205
214
|
|
206
215
|
# dump csv format data
|
207
|
-
def self.dump_csv(klass,
|
216
|
+
def self.dump_csv(klass, attr_types, values_filter, format)
|
208
217
|
# TODO: 拡張子は指定してもしなくても良いようにする
|
209
218
|
file_name = format[:file] || format[:table]
|
210
219
|
dir_name = File.join(Flextures::Configuration.dump_directory, format[:dir].to_s)
|
@@ -212,7 +221,7 @@ module Flextures
|
|
212
221
|
outfile = File.join(dir_name, "#{file_name}.csv")
|
213
222
|
CSV.open(outfile,'w') do |csv|
|
214
223
|
# dump column names
|
215
|
-
csv<<
|
224
|
+
csv<< attr_types.map { |h| h[:name].to_s }
|
216
225
|
# dump column datas
|
217
226
|
klass.all.each do |row|
|
218
227
|
csv<< values_filter.call(row).map(&:last)
|
@@ -226,8 +235,8 @@ module Flextures
|
|
226
235
|
# @params [Hash] options dump format options
|
227
236
|
def self.yml(format)
|
228
237
|
klass = PARENT::create_model(format[:table])
|
229
|
-
|
230
|
-
filter = self.create_filter
|
238
|
+
attr_types = self.dump_attributes klass, format
|
239
|
+
filter = self.create_filter attr_types, format, :yml
|
231
240
|
self.dump_yml(klass, filter, format)
|
232
241
|
end
|
233
242
|
|
data/lib/flextures/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flextures
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.2.
|
4
|
+
version: 4.2.8
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- baban
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-13 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|