flextures 1.9.14 → 1.9.15
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.
- data/VERSION +1 -1
- data/flextures.gemspec +2 -2
- data/lib/flextures/flextures_dumper.rb +12 -8
- data/lib/flextures/flextures_factory.rb +21 -1
- data/lib/flextures/flextures_loader.rb +2 -2
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.9.
|
1
|
+
1.9.15
|
data/flextures.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = "flextures"
|
8
|
-
s.version = "1.9.
|
8
|
+
s.version = "1.9.15"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["baban"]
|
12
|
-
s.date = "2012-07-
|
12
|
+
s.date = "2012-07-15"
|
13
13
|
s.description = "load and dump fixtures"
|
14
14
|
s.email = "babanba.n@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -3,6 +3,8 @@
|
|
3
3
|
module Flextures
|
4
4
|
# データを吐き出す処理をまとめる
|
5
5
|
module Dumper
|
6
|
+
PARENT = Flextures
|
7
|
+
|
6
8
|
# procに機能追加、関数合成のためのメソッドを追加する
|
7
9
|
class Proc < ::Proc
|
8
10
|
def *(other)
|
@@ -60,18 +62,13 @@ module Flextures
|
|
60
62
|
s
|
61
63
|
},
|
62
64
|
ymlnulltime: proc { |d|
|
63
|
-
return "null" if d.nil?
|
64
|
-
return "null" if d==""
|
65
|
-
return "null" if d==false
|
65
|
+
return "null" if d.nil? or d=="" or d==false
|
66
66
|
d
|
67
67
|
},
|
68
68
|
}
|
69
|
-
|
70
|
-
pr.call(val)
|
69
|
+
rules.inject(proc{ |d| d }) { |sum,i| sum * (rule_map[i] || i) }.call(val)
|
71
70
|
end
|
72
71
|
|
73
|
-
PARENT = Flextures
|
74
|
-
|
75
72
|
TRANSLATER = {
|
76
73
|
binary:->( d, format ){
|
77
74
|
procs = (format == :yml)?
|
@@ -156,11 +153,18 @@ module Flextures
|
|
156
153
|
table_name = format[:table]
|
157
154
|
klass = PARENT.create_model(table_name)
|
158
155
|
attributes = klass.columns.map { |column| column.name }
|
156
|
+
filter = DumpFilter[table_name]
|
159
157
|
CSV.open(outfile,'w') do |csv|
|
160
158
|
attr_type = klass.columns.map { |column| { name: column.name, type: column.type } }
|
161
159
|
csv<< attributes
|
162
160
|
klass.all.each do |row|
|
163
|
-
csv<< attr_type.map
|
161
|
+
csv<< attr_type.map do |h|
|
162
|
+
if (filter && filter[h[:name].to_sym])
|
163
|
+
filter[h[:name].to_sym].call(row[h[:name]])
|
164
|
+
else
|
165
|
+
trans(row[h[:name]], h[:type], :csv)
|
166
|
+
end
|
167
|
+
end
|
164
168
|
end
|
165
169
|
end
|
166
170
|
outfile
|
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Flextures
|
4
4
|
# ロードするデータを必要に応じて加工する
|
5
|
-
class
|
5
|
+
class LoadFilter
|
6
6
|
# 設置ファイルから取得した Factoryの一覧を取得
|
7
7
|
FACTORIES={}
|
8
8
|
|
@@ -29,5 +29,25 @@ module Flextures
|
|
29
29
|
end
|
30
30
|
def self.[](table_name); self.get(table_name); end
|
31
31
|
end
|
32
|
+
class DumpFilter
|
33
|
+
# 設置ファイルから取得した Factoryの一覧を取得
|
34
|
+
FACTORIES={}
|
35
|
+
|
36
|
+
# Factory を定義
|
37
|
+
# @params table_name
|
38
|
+
# @params options
|
39
|
+
# @params block
|
40
|
+
# @return Flextures::Factory
|
41
|
+
def self.define table_name, hash
|
42
|
+
FACTORIES[table_name.to_sym]=hash
|
43
|
+
end
|
44
|
+
|
45
|
+
# Factoryを取得
|
46
|
+
def self.get table_name
|
47
|
+
FACTORIES[table_name.to_sym]
|
48
|
+
end
|
49
|
+
def self.[](table_name); self.get(table_name); end
|
50
|
+
end
|
51
|
+
Factory = LoadFilter
|
32
52
|
end
|
33
53
|
|
@@ -142,7 +142,7 @@ module Flextures
|
|
142
142
|
|
143
143
|
klass = PARENT::create_model table_name
|
144
144
|
attributes = klass.columns.map &:name
|
145
|
-
filter = create_filter klass,
|
145
|
+
filter = create_filter klass, LoadFilter[table_name], file_name, :csv
|
146
146
|
# rails3_acts_as_paranoid がdelete_allで物理削除しないことの対策
|
147
147
|
klass.send( klass.respond_to?(:delete_all!) ? :delete_all! : :delete_all )
|
148
148
|
CSV.open( "#{file_name}.csv" ) do |csv|
|
@@ -169,7 +169,7 @@ module Flextures
|
|
169
169
|
# rails3_acts_as_paranoid がdelete_allで物理削除しないことの対策
|
170
170
|
klass.send( klass.respond_to?(:delete_all!) ? :delete_all! : :delete_all )
|
171
171
|
attributes = klass.columns.map &:name
|
172
|
-
filter = create_filter klass,
|
172
|
+
filter = create_filter klass, LoadFilter[table_name], file_name, :yml
|
173
173
|
[attributes, filter]
|
174
174
|
}.call
|
175
175
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flextures
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.9.
|
4
|
+
version: 1.9.15
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-07-
|
12
|
+
date: 2012-07-15 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -90,7 +90,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
90
90
|
version: '0'
|
91
91
|
segments:
|
92
92
|
- 0
|
93
|
-
hash:
|
93
|
+
hash: 258123791
|
94
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
95
|
none: false
|
96
96
|
requirements:
|