flextures 4.2.7 → 4.2.8

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: 9ec25de01a43e9290997564492a3d9e7130bdab30d9fc3d336fb217e43e9a832
4
- data.tar.gz: b69afe1a47cefcc14e34e7bfa0bc1b388cf5215bcfb490dd111fb03a1f5a9a04
3
+ metadata.gz: cf2d34b2424a6a16564ed647a928edb9192b5b1182605393cceba57b1c097972
4
+ data.tar.gz: 27c93837bf4afb4ab4dfacd5a7f1dadb85491c0b7093287525a012bd899705fd
5
5
  SHA512:
6
- metadata.gz: 43add46684a60b6214936b9fe40824db473bccd44984940ba02b0769074e027eb28ef927f46c7621584a0532d48c2ed8be93fb633ee5ea7f45935905f9dff476
7
- data.tar.gz: 6033adcd80cd7bc9ed63c4f045c9a5893b849a58722d633c2158bf7983416dd1300019d84e5dcbcc9e0e681ef48fd0443d1a2bae603ec978ad134461ad0c57b4
6
+ metadata.gz: ee0c12d7492320c6664273390d730e9729df0af8ef02e28a06a3dbdd51ce22124c55555e9f372d0b8d6d2efb471a9659b535d59e168501c4d90086c4a0768ab0
7
+ data.tar.gz: 5f63de4503c68eaac01dc6a3c9142af82f78b5748ec9c9073b25597080bd52014959d61080fa9294c690f472ef1f504ded820ee8b086eb98587afc38482b4a97
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- flextures (4.2.7)
4
+ flextures (4.2.8)
5
5
  activerecord
6
6
  activesupport
7
7
 
@@ -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
- trans = TRANSLATER[type]
162
- return trans.call(v, format) if trans
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 { |column| { name: column.name, type: column.type } }
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(attr_type, format, type)
195
+ def self.create_filter(attr_types, format, type)
187
196
  filter = DumpFilter[format[:table].to_s.to_sym] || {}
188
197
  ->(row) {
189
- attr_type.map do |h|
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
- attr_type = self.dump_attributes klass, format
202
- filter = self.create_filter attr_type, format, :csv
203
- self.dump_csv klass, attr_type, filter, format
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, attr_type, values_filter, format)
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<< attr_type.map { |h| h[:name].to_s }
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
- attr_type = self.dump_attributes klass, format
230
- filter = self.create_filter attr_type, format, :yml
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
 
@@ -1,3 +1,3 @@
1
1
  module Flextures
2
- VERSION="4.2.7".freeze
2
+ VERSION="4.2.8".freeze
3
3
  end
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.7
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-10 00:00:00.000000000 Z
11
+ date: 2018-07-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord