flextures 2.0.3 → 2.0.4
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/Gemfile +2 -0
- data/Gemfile.lock +12 -0
- data/README.ja.rdoc +1 -1
- data/README.rdoc +1 -1
- data/VERSION +1 -1
- data/flextures.gemspec +5 -2
- data/lib/flextures/flextures.rb +5 -5
- data/lib/flextures/flextures_loader.rb +13 -6
- data/lib/flextures/version.rb +1 -1
- data/lib/flextures.rb +1 -0
- data/test/unit/test_flextures_hooks.rb +10 -3
- metadata +19 -3
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,9 +1,19 @@
|
|
1
1
|
GEM
|
2
2
|
remote: http://rubygems.org/
|
3
3
|
specs:
|
4
|
+
activemodel (3.2.8)
|
5
|
+
activesupport (= 3.2.8)
|
6
|
+
builder (~> 3.0.0)
|
7
|
+
activerecord (3.2.8)
|
8
|
+
activemodel (= 3.2.8)
|
9
|
+
activesupport (= 3.2.8)
|
10
|
+
arel (~> 3.0.2)
|
11
|
+
tzinfo (~> 0.3.29)
|
4
12
|
activesupport (3.2.8)
|
5
13
|
i18n (~> 0.6)
|
6
14
|
multi_json (~> 1.0)
|
15
|
+
arel (3.0.2)
|
16
|
+
builder (3.0.3)
|
7
17
|
git (1.2.5)
|
8
18
|
i18n (0.6.0)
|
9
19
|
jeweler (1.8.3)
|
@@ -22,11 +32,13 @@ GEM
|
|
22
32
|
shoulda-context (1.0.0)
|
23
33
|
shoulda-matchers (1.2.0)
|
24
34
|
activesupport (>= 3.0.0)
|
35
|
+
tzinfo (0.3.33)
|
25
36
|
|
26
37
|
PLATFORMS
|
27
38
|
ruby
|
28
39
|
|
29
40
|
DEPENDENCIES
|
41
|
+
activerecord
|
30
42
|
bundler (= 1.2.0)
|
31
43
|
jeweler (= 1.8.3)
|
32
44
|
shoulda
|
data/README.ja.rdoc
CHANGED
@@ -55,7 +55,7 @@ Usersモデルのfixture(users.csvか users.yml)をロードする
|
|
55
55
|
MODEL : モデル名を指定してロード。モデル名はカンマ区切りで複数指定が可能
|
56
56
|
DIR : フィクスチャをロード&ダンプするディレクトリを指定する
|
57
57
|
FIXTURES : ロード、ダンプをするファイル名をRails標準以外のもので直接指定(Userモデルのusers.csv以外を指定)
|
58
|
-
|
58
|
+
FILE : ロード、ダンプをするファイル名をRails標準以外のもので直接指定(Userモデルのusers.csv以外を指定)
|
59
59
|
T : TABLEのエイリアス
|
60
60
|
M : モデル名指定のエイリアス
|
61
61
|
D : ディレクトリ指定のエイリアス
|
data/README.rdoc
CHANGED
@@ -56,7 +56,7 @@ Other options...
|
|
56
56
|
MODEL : set model name
|
57
57
|
DIR : set directory name
|
58
58
|
FIXTURES : set fixture file name
|
59
|
-
|
59
|
+
FILE : set fixture file name
|
60
60
|
T : alias TABLE option
|
61
61
|
M : alias MODEL option
|
62
62
|
D : alias DIR option
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
2.0.
|
1
|
+
2.0.4
|
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.4"
|
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-
|
12
|
+
s.date = "2012-10-03"
|
13
13
|
s.description = "load and dump fixtures"
|
14
14
|
s.email = "babanba.n@gmail.com"
|
15
15
|
s.extra_rdoc_files = [
|
@@ -60,13 +60,16 @@ Gem::Specification.new do |s|
|
|
60
60
|
s.specification_version = 3
|
61
61
|
|
62
62
|
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
63
|
+
s.add_runtime_dependency(%q<activerecord>, [">= 0"])
|
63
64
|
s.add_development_dependency(%q<bundler>, ["= 1.2.0"])
|
64
65
|
s.add_development_dependency(%q<jeweler>, ["= 1.8.3"])
|
65
66
|
else
|
67
|
+
s.add_dependency(%q<activerecord>, [">= 0"])
|
66
68
|
s.add_dependency(%q<bundler>, ["= 1.2.0"])
|
67
69
|
s.add_dependency(%q<jeweler>, ["= 1.8.3"])
|
68
70
|
end
|
69
71
|
else
|
72
|
+
s.add_dependency(%q<activerecord>, [">= 0"])
|
70
73
|
s.add_dependency(%q<bundler>, ["= 1.2.0"])
|
71
74
|
s.add_dependency(%q<jeweler>, ["= 1.8.3"])
|
72
75
|
end
|
data/lib/flextures/flextures.rb
CHANGED
@@ -89,7 +89,7 @@ module Flextures
|
|
89
89
|
end
|
90
90
|
end
|
91
91
|
|
92
|
-
#
|
92
|
+
# parse arguments functions
|
93
93
|
module ARGS
|
94
94
|
# 書き出し 、読み込み すべきファイルとオプションを書きだす
|
95
95
|
def self.parse option={}
|
@@ -104,9 +104,9 @@ module Flextures
|
|
104
104
|
end
|
105
105
|
end
|
106
106
|
|
107
|
-
table_names = Flextures::deletable_tables.map{ |
|
107
|
+
table_names = Flextures::deletable_tables.map{ |name| { table: name, file: name } } if table_names.empty?
|
108
108
|
|
109
|
-
# ENV["FIXTURES"]
|
109
|
+
# parse ENV["FIXTURES"] paameter
|
110
110
|
fixtures_args_parser =->(s){
|
111
111
|
names = s.split(',')
|
112
112
|
if ENV["TABLE"] or ENV["T"] or ENV["MODEL"] or ENV["M"]
|
@@ -115,7 +115,7 @@ module Flextures
|
|
115
115
|
names.map{ |name| { table: name, file: name } }
|
116
116
|
end
|
117
117
|
}
|
118
|
-
#
|
118
|
+
# parse filename define parameters
|
119
119
|
table_names = fixtures_args_parser.call ENV["FIXTURES"] if ENV["FIXTURES"]
|
120
120
|
table_names = fixtures_args_parser.call ENV["FILE"] if ENV["FILE"]
|
121
121
|
table_names = fixtures_args_parser.call ENV["F"] if ENV["F"]
|
@@ -127,7 +127,7 @@ module Flextures
|
|
127
127
|
table_names
|
128
128
|
end
|
129
129
|
|
130
|
-
#
|
130
|
+
# check exist filename block
|
131
131
|
def self.exist
|
132
132
|
return->(name){ File.exists?("#{LOAD_DIR}#{name}.csv") or File.exists?("#{LOAD_DIR}#{name}.yml") }
|
133
133
|
end
|
@@ -120,11 +120,12 @@ module Flextures
|
|
120
120
|
fixtures = Flextures::deletable_tables if fixtures.size== 1 and :all == fixtures.first
|
121
121
|
|
122
122
|
last_hash = {}
|
123
|
-
last_hash = fixtures.pop if fixtures.last.is_a? Hash
|
123
|
+
last_hash = fixtures.pop if fixtures.last.is_a? Hash
|
124
124
|
|
125
125
|
load_hash = fixtures.inject({}){ |h,name| h[name.to_sym] = name; h }
|
126
126
|
load_hash.merge!(last_hash)
|
127
|
-
load_hash.map { |k,v| { table: k, file: v, loader: :fun } }
|
127
|
+
load_hash = load_hash.map { |k,v| { table: k, file: v, loader: :fun } }
|
128
|
+
[load_hash, options]
|
128
129
|
end
|
129
130
|
|
130
131
|
# fixturesをまとめてロード、主にテストtest/unit, rspec で使用する
|
@@ -138,11 +139,12 @@ module Flextures
|
|
138
139
|
#
|
139
140
|
# @params [Hash] 読み込むテーブルとファイル名のペア
|
140
141
|
def self.flextures *fixtures
|
141
|
-
parse_flextures_options(*fixtures)
|
142
|
+
loas_hash, options = parse_flextures_options(*fixtures)
|
143
|
+
load_hash.each{ |params| Loader::load params }
|
142
144
|
end
|
143
145
|
|
144
146
|
# csv 優先で存在している fixtures をロード
|
145
|
-
def self.load format
|
147
|
+
def self.load format, option
|
146
148
|
table_name, file_name, method = file_exist format
|
147
149
|
if method
|
148
150
|
send(method, format)
|
@@ -153,9 +155,11 @@ module Flextures
|
|
153
155
|
end
|
154
156
|
|
155
157
|
# CSVのデータをロードする
|
156
|
-
def self.csv format
|
158
|
+
def self.csv format, options={}
|
157
159
|
table_name, file_name, ext = file_exist format, [:csv]
|
158
160
|
|
161
|
+
# キャッシュ利用可能ならそれをそのまま使う
|
162
|
+
return if options[:cache] and @@table_cache[table_name.to_sym] and @@table_cache[table_name.to_sym] == file_name
|
159
163
|
@@table_cache[table_name.to_sym] = file_name
|
160
164
|
|
161
165
|
print "try loading #{file_name}.csv\n" unless [:fun].include? format[:loader]
|
@@ -166,6 +170,7 @@ module Flextures
|
|
166
170
|
filter = create_filter klass, LoadFilter[table_name], file_name, :csv
|
167
171
|
# rails3_acts_as_paranoid がdelete_allで物理削除しないことの対策
|
168
172
|
klass.send( klass.respond_to?(:delete_all!) ? :delete_all! : :delete_all )
|
173
|
+
|
169
174
|
CSV.open( "#{file_name}.csv" ) do |csv|
|
170
175
|
keys = csv.shift # keyの設定
|
171
176
|
warning "CSV", attributes, keys
|
@@ -179,9 +184,11 @@ module Flextures
|
|
179
184
|
end
|
180
185
|
|
181
186
|
# YAML形式でデータをロードする
|
182
|
-
def self.yml format
|
187
|
+
def self.yml format, option={}
|
183
188
|
table_name, file_name, ext = file_exist format, [:yml]
|
184
189
|
|
190
|
+
# キャッシュ利用可能ならそれをそのまま使う
|
191
|
+
return if options[:cache] and @@table_cache[table_name.to_sym] and @@table_cache[table_name.to_sym] == file_name
|
185
192
|
@@table_cache[table_name.to_sym] = file_name
|
186
193
|
|
187
194
|
print "try loading #{file_name}.yml\n" unless [:fun].include? format[:loader]
|
data/lib/flextures/version.rb
CHANGED
data/lib/flextures.rb
CHANGED
@@ -5,7 +5,7 @@ class FlexturesHookTest < Test::Unit::TestCase
|
|
5
5
|
context ".parse_flextures_options" do
|
6
6
|
context "通常動作" do
|
7
7
|
setup do
|
8
|
-
@ret = Flextures::Loader.parse_flextures_options(:users)
|
8
|
+
@ret, @options = Flextures::Loader.parse_flextures_options(:users)
|
9
9
|
end
|
10
10
|
should "指定したテーブル分だけハッシュが返されている" do
|
11
11
|
assert_equal 1, @ret.size
|
@@ -17,7 +17,7 @@ class FlexturesHookTest < Test::Unit::TestCase
|
|
17
17
|
end
|
18
18
|
context "違うファイルをロードした時" do
|
19
19
|
setup do
|
20
|
-
@ret = Flextures::Loader.parse_flextures_options( :users => :users_another3 )
|
20
|
+
@ret, @options = Flextures::Loader.parse_flextures_options( :users => :users_another3 )
|
21
21
|
end
|
22
22
|
should "指定したテーブル分だけハッシュが返されている" do
|
23
23
|
assert_equal 1, @ret.size
|
@@ -27,8 +27,15 @@ class FlexturesHookTest < Test::Unit::TestCase
|
|
27
27
|
assert_equal h, @ret.first
|
28
28
|
end
|
29
29
|
end
|
30
|
+
context "オプション指定があった時" do
|
31
|
+
setup do
|
32
|
+
@ret, @options = Flextures::Loader.parse_flextures_options({ cache: true }, :users)
|
33
|
+
end
|
34
|
+
should "オプションを取り出している" do
|
35
|
+
assert_equal true, @options[:cache]
|
36
|
+
end
|
37
|
+
end
|
30
38
|
end
|
31
|
-
|
32
39
|
end
|
33
40
|
end
|
34
41
|
|
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.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,24 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-10-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: activerecord
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :runtime
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
14
30
|
- !ruby/object:Gem::Dependency
|
15
31
|
name: bundler
|
16
32
|
requirement: !ruby/object:Gem::Requirement
|
@@ -98,7 +114,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
98
114
|
version: '0'
|
99
115
|
segments:
|
100
116
|
- 0
|
101
|
-
hash: -
|
117
|
+
hash: -204193459
|
102
118
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
103
119
|
none: false
|
104
120
|
requirements:
|