flextures 2.0.0 → 2.0.1
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 +24 -10
- data/lib/flextures/flextures_loader.rb +9 -0
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.
|
1
|
+
2.0.1
|
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 = "2.0.
|
8
|
+
s.version = "2.0.1"
|
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-08-
|
12
|
+
s.date = "2012-08-28"
|
13
13
|
s.description = "load and dump fixtures"
|
14
14
|
s.email = "babanba.n@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -4,7 +4,6 @@ module Flextures
|
|
4
4
|
# データを吐き出す処理をまとめる
|
5
5
|
module Dumper
|
6
6
|
PARENT = Flextures
|
7
|
-
|
8
7
|
# procに機能追加、関数合成のためのメソッドを追加する
|
9
8
|
class Proc < ::Proc
|
10
9
|
def *(other)
|
@@ -32,10 +31,14 @@ module Flextures
|
|
32
31
|
return nil if d.nil?
|
33
32
|
d
|
34
33
|
},
|
35
|
-
|
34
|
+
blank2null: proc { |d|
|
36
35
|
return "null" if d==""
|
37
36
|
d
|
38
37
|
},
|
38
|
+
blankstr: proc { |d|
|
39
|
+
return '""' if d==""
|
40
|
+
d
|
41
|
+
},
|
39
42
|
false2nullstr: proc { |d|
|
40
43
|
return "null" if d==false
|
41
44
|
d
|
@@ -85,20 +88,20 @@ module Flextures
|
|
85
88
|
},
|
86
89
|
date:->( d, format ){
|
87
90
|
procs = (format == :yml) ?
|
88
|
-
[:nullstr, :
|
91
|
+
[:nullstr, :blank2null, :false2nullstr, proc { |d| d.to_s }] :
|
89
92
|
[proc { |d| d.to_s }]
|
90
93
|
self.translate_creater d, procs
|
91
94
|
},
|
92
95
|
datetime:->( d, format ){
|
93
96
|
procs = (format == :yml) ?
|
94
|
-
[:nullstr, :
|
97
|
+
[:nullstr, :blank2null, :false2nullstr, proc { |d| d.to_s }] :
|
95
98
|
[proc { |d| d.to_s }]
|
96
99
|
self.translate_creater d, procs
|
97
100
|
},
|
98
101
|
decimal:->( d, format ){
|
99
102
|
procs = (format == :yml) ?
|
100
|
-
[:nullstr, :blank2num, :bool2num, proc { |d| d.
|
101
|
-
[:blank2num, :bool2num, proc { |d| d.
|
103
|
+
[:nullstr, :blank2num, :bool2num, proc { |d| d.to_f } ] :
|
104
|
+
[:blank2num, :bool2num, proc { |d| d.to_f } ]
|
102
105
|
self.translate_creater d, procs
|
103
106
|
},
|
104
107
|
float:->(d, format){
|
@@ -115,13 +118,13 @@ module Flextures
|
|
115
118
|
},
|
116
119
|
string:->( d, format ){
|
117
120
|
procs = (format == :yml) ?
|
118
|
-
[:nullstr, :ymlspecialstr] :
|
121
|
+
[:blankstr, :nullstr, :ymlspecialstr] :
|
119
122
|
[:null, proc{ |s| s.to_s.gsub(/\r\n/,"\n").gsub(/\r/,"\n") } ]
|
120
123
|
self.translate_creater d, procs
|
121
124
|
},
|
122
125
|
text:->( d, format ){
|
123
126
|
procs = (format == :yml) ?
|
124
|
-
[:nullstr, :ymlspecialstr] :
|
127
|
+
[:blankstr, :nullstr, :ymlspecialstr] :
|
125
128
|
[:null, proc{ |s| s.to_s.gsub(/\r\n/,"\n").gsub(/\r/,"\n") } ]
|
126
129
|
self.translate_creater d, procs
|
127
130
|
},
|
@@ -150,7 +153,9 @@ module Flextures
|
|
150
153
|
def self.csv format
|
151
154
|
file_name = format[:file] || format[:table]
|
152
155
|
dir_name = format[:dir] || DUMP_DIR
|
153
|
-
|
156
|
+
# 指定されたディレクトリを作成
|
157
|
+
recursive_mkdir(dir_name)
|
158
|
+
outfile = File.join(dir_name, "#{file_name}.csv")
|
154
159
|
table_name = format[:table]
|
155
160
|
klass = PARENT.create_model(table_name)
|
156
161
|
attributes = klass.columns.map { |column| column.name }
|
@@ -175,7 +180,9 @@ module Flextures
|
|
175
180
|
def self.yml format
|
176
181
|
file_name = format[:file] || format[:table]
|
177
182
|
dir_name = format[:dir] || DUMP_DIR
|
178
|
-
|
183
|
+
# 指定されたディレクトリを作成
|
184
|
+
recursive_mkdir(dir_name)
|
185
|
+
outfile = File.join(dir_name, "#{file_name}.yml")
|
179
186
|
table_name = format[:table]
|
180
187
|
klass = PARENT::create_model(table_name)
|
181
188
|
attributes = klass.columns.map { |colum| colum.name }
|
@@ -199,6 +206,13 @@ module Flextures
|
|
199
206
|
end
|
200
207
|
outfile
|
201
208
|
end
|
209
|
+
|
210
|
+
def self.recursive_mkdir(path)
|
211
|
+
return if FileTest.exist?(path)
|
212
|
+
dir = File.dirname(path)
|
213
|
+
recursive_mkdir(dir)
|
214
|
+
Dir.mkdir(path)
|
215
|
+
end
|
202
216
|
end
|
203
217
|
end
|
204
218
|
|
@@ -13,6 +13,8 @@ module Flextures
|
|
13
13
|
module Loader
|
14
14
|
PARENT = Flextures
|
15
15
|
|
16
|
+
@@table_cache = {}
|
17
|
+
|
16
18
|
# 型に応じて勝手にdefault値を設定する
|
17
19
|
COMPLETER = {
|
18
20
|
binary:->{ 0 },
|
@@ -114,6 +116,9 @@ module Flextures
|
|
114
116
|
# ハッシュで指定
|
115
117
|
# fixtures :users => :users2
|
116
118
|
def self.flextures *fixtures
|
119
|
+
options = {}
|
120
|
+
options = fixtures.shift if fixtures.size > 1 and fixtures.first.is_a?(Hash)
|
121
|
+
|
117
122
|
# :allですべてのfixtureを反映
|
118
123
|
fixtures = Flextures::deletable_tables if fixtures.size== 1 and :all == fixtures.first
|
119
124
|
fixtures_hash = fixtures.pop if fixtures.last and fixtures.last.is_a? Hash # ハッシュ取り出し
|
@@ -137,6 +142,8 @@ module Flextures
|
|
137
142
|
def self.csv format
|
138
143
|
table_name, file_name, ext = file_exist format, [:csv]
|
139
144
|
|
145
|
+
@@table_cache[table_name.to_sym] = file_name
|
146
|
+
|
140
147
|
print "try loading #{file_name}.csv\n" unless [:fun].include? format[:loader]
|
141
148
|
return nil unless File.exist? "#{file_name}.csv"
|
142
149
|
|
@@ -161,6 +168,8 @@ module Flextures
|
|
161
168
|
def self.yml format
|
162
169
|
table_name, file_name, ext = file_exist format, [:yml]
|
163
170
|
|
171
|
+
@@table_cache[table_name.to_sym] = file_name
|
172
|
+
|
164
173
|
print "try loading #{file_name}.yml\n" unless [:fun].include? format[:loader]
|
165
174
|
return nil unless File.exist? "#{file_name}.yml"
|
166
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: 2.0.
|
4
|
+
version: 2.0.1
|
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-08-
|
12
|
+
date: 2012-08-28 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: -596499121
|
94
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
95
|
none: false
|
96
96
|
requirements:
|