flextures 1.9.9 → 1.9.10
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 +8 -2
- data/lib/flextures/flextures_loader.rb +26 -18
- metadata +3 -3
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.9.
|
1
|
+
1.9.10
|
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.10"
|
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-04-
|
12
|
+
s.date = "2012-04-27"
|
13
13
|
s.description = "load and dump fixtures"
|
14
14
|
s.email = "babanba.n@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -65,8 +65,11 @@ module Flextures
|
|
65
65
|
if s.kind_of?(String)
|
66
66
|
s = s.gsub(/\t/," ") if s["\t"]
|
67
67
|
s = s.sub(/ +/, "") if s[0]==' '
|
68
|
+
is_nl = false
|
69
|
+
is_nl |= s["\n"]
|
70
|
+
is_nl |= ["[","]","{","}","|","#","@","~","!","'","$","&","^","<",">","?","-","+","=",";",":",".",",","*","`","(",")"].member? s[0]
|
68
71
|
s = s.gsub(/\r\n/,"\n").gsub(/\r/,"\n") # 改行方法統一
|
69
|
-
s = "|-\n " + s.gsub(/\n/,"\n ") if
|
72
|
+
s = "|-\n " + s.gsub(/\n/,"\n ") if is_nl
|
70
73
|
end
|
71
74
|
end
|
72
75
|
if format == :csv
|
@@ -82,8 +85,11 @@ module Flextures
|
|
82
85
|
if s.kind_of?(String)
|
83
86
|
s = s.gsub(/\t/," ") if s["\t"]
|
84
87
|
s = s.sub(/ +/, "") if s[0]==' '
|
88
|
+
is_nl = false
|
89
|
+
is_nl |= s["\n"]
|
90
|
+
is_nl |= ["[","]","{","}","|","#","@","~","!","'","$","&","^","<",">","?","-","+","=",";",":",".",",","*","`","(",")"].member? s[0]
|
85
91
|
s = s.gsub(/\r\n/,"\n").gsub(/\r/,"\n") # 改行方法統一
|
86
|
-
s = "|-\n " + s.gsub(/\n/,"\n ") if
|
92
|
+
s = "|-\n " + s.gsub(/\n/,"\n ") if is_nl
|
87
93
|
end
|
88
94
|
end
|
89
95
|
if format == :csv
|
@@ -101,17 +101,6 @@ module Flextures
|
|
101
101
|
[table_name, "#{dir_name}#{file_name}",ext]
|
102
102
|
end
|
103
103
|
|
104
|
-
# csv 優先で存在している fixtures をロード
|
105
|
-
def self.load format
|
106
|
-
table_name, file_name, method = file_exist format
|
107
|
-
if method
|
108
|
-
self::send(method, format)
|
109
|
-
else
|
110
|
-
# ファイルが存在しない時
|
111
|
-
print "Warning: #{file_name} is not exist!\n"
|
112
|
-
end
|
113
|
-
end
|
114
|
-
|
115
104
|
# fixturesをまとめてロード、主にテストtest/unit, rspec で使用する
|
116
105
|
#
|
117
106
|
# 全テーブルが対象
|
@@ -124,15 +113,27 @@ module Flextures
|
|
124
113
|
# :allですべてのfixtureを反映
|
125
114
|
fixtures = Flextures::deletable_tables if fixtures.size== 1 and :all == fixtures.first
|
126
115
|
fixtures_hash = fixtures.pop if fixtures.last and fixtures.last.is_a? Hash # ハッシュ取り出し
|
127
|
-
fixtures.each{ |table_name| Loader::load table: table_name }
|
128
|
-
fixtures_hash.each{ |k,v| Loader::load table: k, file: v } if fixtures_hash
|
116
|
+
fixtures.each{ |table_name| Loader::load table: table_name, loader: :fun }
|
117
|
+
fixtures_hash.each{ |k,v| Loader::load table: k, file: v, loader: :fun } if fixtures_hash
|
129
118
|
fixtures
|
130
119
|
end
|
131
120
|
|
121
|
+
# csv 優先で存在している fixtures をロード
|
122
|
+
def self.load format
|
123
|
+
table_name, file_name, method = file_exist format
|
124
|
+
if method
|
125
|
+
send(method, format)
|
126
|
+
else
|
127
|
+
# ファイルが存在しない時
|
128
|
+
print "Warning: #{file_name} is not exist!\n"
|
129
|
+
end
|
130
|
+
end
|
131
|
+
|
132
132
|
# CSVのデータをロードする
|
133
133
|
def self.csv format
|
134
134
|
table_name, file_name, ext = file_exist format, [:csv]
|
135
135
|
|
136
|
+
print "try loading #{file_name}.yml\n" unless [:fun].include? format[:loader]
|
136
137
|
return nil unless File.exist? "#{file_name}.csv"
|
137
138
|
|
138
139
|
klass = PARENT::create_model table_name
|
@@ -155,13 +156,20 @@ module Flextures
|
|
155
156
|
def self.yml format
|
156
157
|
table_name, file_name, ext = file_exist format, [:yml]
|
157
158
|
|
159
|
+
print "try loading #{file_name}.yml\n" unless [:fun].include? format[:loader]
|
158
160
|
return nil unless File.exist? "#{file_name}.yml"
|
159
161
|
|
160
|
-
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
162
|
+
attributes, filter = ->{
|
163
|
+
klass = PARENT::create_model table_name
|
164
|
+
klass.delete_all
|
165
|
+
attributes = klass.columns.map &:name
|
166
|
+
filter = create_filter klass, Factory[table_name], file_name, :yml
|
167
|
+
[attributes, filter]
|
168
|
+
}.call
|
169
|
+
|
170
|
+
yaml = YAML.load(File.open("#{file_name}.yml"))
|
171
|
+
return false unless yaml # ファイルの中身が空の場合
|
172
|
+
yaml.each do |k,h|
|
165
173
|
warning "YAML", attributes, h.keys
|
166
174
|
o = filter.call h
|
167
175
|
o.save
|
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.10
|
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-04-
|
12
|
+
date: 2012-04-27 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: -722953521
|
94
94
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
95
95
|
none: false
|
96
96
|
requirements:
|