flextures 4.2.6 → 4.2.7

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 586bd776775ce59421b01bc6e66ec98bba53c2dd
4
- data.tar.gz: cb64f026f8dcbe862a6a1c5a7e8bfa52f5668325
2
+ SHA256:
3
+ metadata.gz: 9ec25de01a43e9290997564492a3d9e7130bdab30d9fc3d336fb217e43e9a832
4
+ data.tar.gz: b69afe1a47cefcc14e34e7bfa0bc1b388cf5215bcfb490dd111fb03a1f5a9a04
5
5
  SHA512:
6
- metadata.gz: 56acf4fe25ba3f12b4ba7209f4826b32ac04611530d47c425003673053e6ff4a09df07ce82b1ff1128374d55285b7ae812a3ca8c9272c6612b0fc51e2cedb53d
7
- data.tar.gz: 9fcd86bf0a47028d31f7fbe182d4b15c7e2f06b4872be530efd242e731f735358dd2516a5e63a44eb5459b5e7d145cb0b0bdb4fb09395ab335325be6458fa99e
6
+ metadata.gz: 43add46684a60b6214936b9fe40824db473bccd44984940ba02b0769074e027eb28ef927f46c7621584a0532d48c2ed8be93fb633ee5ea7f45935905f9dff476
7
+ data.tar.gz: 6033adcd80cd7bc9ed63c4f045c9a5893b849a58722d633c2158bf7983416dd1300019d84e5dcbcc9e0e681ef48fd0443d1a2bae603ec978ad134461ad0c57b4
data/.document CHANGED
@@ -1,5 +1,5 @@
1
- lib/**/*.rb
2
- bin/*
3
- -
4
- features/**/*.feature
5
- LICENSE.txt
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.gitignore CHANGED
@@ -1,48 +1,50 @@
1
- # rcov generated
2
- coverage
3
-
4
- # rdoc generated
5
- rdoc
6
-
7
- # yard generated
8
- doc
9
- .yardoc
10
-
11
- # bundler
12
- .bundle
13
-
14
- # jeweler generated
15
- pkg
16
-
17
- # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
18
- #
19
- # * Create a file at ~/.gitignore
20
- # * Include files you want ignored
21
- # * Run: git config --global core.excludesfile ~/.gitignore
22
- #
23
- # After doing this, these files will be ignored in all your git projects,
24
- # saving you from having to 'pollute' every project you touch with them
25
- #
26
- # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
27
- #
28
- # For MacOS:
29
- #
30
- .DS_Store
31
-
32
- # For TextMate
33
- #*.tmproj
34
- #tmtags
35
-
36
- # For emacs:
37
- *~
38
- \#*
39
- .\#*
40
-
41
- # For vim:
42
- *.swp
43
-
44
- # For redcar:
45
- #.redcar
46
-
47
- # For rubinius:
48
- #*.rbc
1
+ # rcov generated
2
+ coverage
3
+
4
+ .ruby-version
5
+
6
+ # rdoc generated
7
+ rdoc
8
+
9
+ # yard generated
10
+ doc
11
+ .yardoc
12
+
13
+ # bundler
14
+ .bundle
15
+
16
+ # jeweler generated
17
+ pkg
18
+
19
+ # Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
20
+ #
21
+ # * Create a file at ~/.gitignore
22
+ # * Include files you want ignored
23
+ # * Run: git config --global core.excludesfile ~/.gitignore
24
+ #
25
+ # After doing this, these files will be ignored in all your git projects,
26
+ # saving you from having to 'pollute' every project you touch with them
27
+ #
28
+ # Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
29
+ #
30
+ # For MacOS:
31
+ #
32
+ .DS_Store
33
+
34
+ # For TextMate
35
+ #*.tmproj
36
+ #tmtags
37
+
38
+ # For emacs:
39
+ *~
40
+ \#*
41
+ .\#*
42
+
43
+ # For vim:
44
+ *.swp
45
+
46
+ # For redcar:
47
+ #.redcar
48
+
49
+ # For rubinius:
50
+ #*.rbc
data/CHANGELOG CHANGED
@@ -1,2 +1,2 @@
1
- 2011/10/03 Release
2
-
1
+ 2011/10/03 Release
2
+
data/Gemfile CHANGED
@@ -1,15 +1,15 @@
1
- source 'https://rubygems.org'
2
-
3
- ruby ">= 2.1.0"
4
-
5
- # Specify your gem's dependencies in flextures.gemspec
6
- gemspec
7
-
8
- gem "minitest", "5.4.0"
9
-
10
- group :test do
11
- gem "minitest-line", "0.6.2"
12
- gem "minitest-bang", "0.1.1" # let文を使えるようにする
13
- gem "minitest-implicit-subject", "1.4.0" # subject関数を追加する
14
- gem "minitest-power_assert", "0.0.3" # power assertを有効にする
15
- end
1
+ source 'https://rubygems.org'
2
+
3
+ ruby ">= 2.1.0"
4
+
5
+ # Specify your gem's dependencies in flextures.gemspec
6
+ gemspec
7
+
8
+ gem "minitest", "5.4.0"
9
+
10
+ group :test do
11
+ gem "minitest-line", "0.6.2"
12
+ gem "minitest-bang", "0.1.1" # let文を使えるようにする
13
+ gem "minitest-implicit-subject", "1.4.0" # subject関数を追加する
14
+ gem "minitest-power_assert", "0.0.3" # power assertを有効にする
15
+ end
@@ -1,58 +1,59 @@
1
- PATH
2
- remote: .
3
- specs:
4
- flextures (4.2.6)
5
- activerecord
6
- activesupport
7
-
8
- GEM
9
- remote: https://rubygems.org/
10
- specs:
11
- activemodel (5.0.0.1)
12
- activesupport (= 5.0.0.1)
13
- activerecord (5.0.0.1)
14
- activemodel (= 5.0.0.1)
15
- activesupport (= 5.0.0.1)
16
- arel (~> 7.0)
17
- activesupport (5.0.0.1)
18
- concurrent-ruby (~> 1.0, >= 1.0.2)
19
- i18n (~> 0.7)
20
- minitest (~> 5.1)
21
- tzinfo (~> 1.1)
22
- arel (7.1.4)
23
- concurrent-ruby (1.0.5)
24
- i18n (0.8.1)
25
- minitest (5.4.0)
26
- minitest-bang (0.1.1)
27
- minitest (>= 4.7.5, <= 5.4.0)
28
- minitest-implicit-subject (1.4.0)
29
- minitest
30
- minitest-line (0.6.2)
31
- minitest (~> 5.0)
32
- minitest-power_assert (0.0.3)
33
- minitest
34
- power_assert
35
- power_assert (0.2.2)
36
- rake (0.9.2.2)
37
- thread_safe (0.3.6)
38
- tzinfo (1.2.2)
39
- thread_safe (~> 0.1)
40
-
41
- PLATFORMS
42
- ruby
43
-
44
- DEPENDENCIES
45
- bundler (~> 1.6)
46
- flextures!
47
- minitest (= 5.4.0)
48
- minitest-bang (= 0.1.1)
49
- minitest-implicit-subject (= 1.4.0)
50
- minitest-line (= 0.6.2)
51
- minitest-power_assert (= 0.0.3)
52
- rake
53
-
54
- RUBY VERSION
55
- ruby 2.2.3p173
56
-
57
- BUNDLED WITH
58
- 1.14.3
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ flextures (4.2.7)
5
+ activerecord
6
+ activesupport
7
+
8
+ GEM
9
+ remote: https://rubygems.org/
10
+ specs:
11
+ activemodel (5.2.0)
12
+ activesupport (= 5.2.0)
13
+ activerecord (5.2.0)
14
+ activemodel (= 5.2.0)
15
+ activesupport (= 5.2.0)
16
+ arel (>= 9.0)
17
+ activesupport (5.2.0)
18
+ concurrent-ruby (~> 1.0, >= 1.0.2)
19
+ i18n (>= 0.7, < 2)
20
+ minitest (~> 5.1)
21
+ tzinfo (~> 1.1)
22
+ arel (9.0.0)
23
+ concurrent-ruby (1.0.5)
24
+ i18n (1.0.1)
25
+ concurrent-ruby (~> 1.0)
26
+ minitest (5.4.0)
27
+ minitest-bang (0.1.1)
28
+ minitest (>= 4.7.5, <= 5.4.0)
29
+ minitest-implicit-subject (1.4.0)
30
+ minitest
31
+ minitest-line (0.6.2)
32
+ minitest (~> 5.0)
33
+ minitest-power_assert (0.0.3)
34
+ minitest
35
+ power_assert
36
+ power_assert (0.2.2)
37
+ rake (0.9.2.2)
38
+ thread_safe (0.3.6)
39
+ tzinfo (1.2.5)
40
+ thread_safe (~> 0.1)
41
+
42
+ PLATFORMS
43
+ ruby
44
+
45
+ DEPENDENCIES
46
+ bundler (~> 1.6)
47
+ flextures!
48
+ minitest (= 5.4.0)
49
+ minitest-bang (= 0.1.1)
50
+ minitest-implicit-subject (= 1.4.0)
51
+ minitest-line (= 0.6.2)
52
+ minitest-power_assert (= 0.0.3)
53
+ rake
54
+
55
+ RUBY VERSION
56
+ ruby 2.2.3p173
57
+
58
+ BUNDLED WITH
59
+ 1.16.2
@@ -1,20 +1,20 @@
1
- Copyright (c) 2011 baban
2
-
3
- Permission is hereby granted, free of charge, to any person obtaining
4
- a copy of this software and associated documentation files (the
5
- "Software"), to deal in the Software without restriction, including
6
- without limitation the rights to use, copy, modify, merge, publish,
7
- distribute, sublicense, and/or sell copies of the Software, and to
8
- permit persons to whom the Software is furnished to do so, subject to
9
- the following conditions:
10
-
11
- The above copyright notice and this permission notice shall be
12
- included in all copies or substantial portions of the Software.
13
-
14
- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
- EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
- MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
- NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
- LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
- OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
- WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
1
+ Copyright (c) 2011 baban
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,215 +1,215 @@
1
- # flextures
2
-
3
- * [ENGLISH DOCUMENT](https://github.com/baban/flextures/blob/master/README.md)
4
-
5
- ![Ruby 2.1 higher](https://img.shields.io/badge/ruby-v2.1-red.svg)
6
- ![Rails 4.0 higher](https://img.shields.io/badge/rails-v4.0-red.svg)
7
- ![MIT Licence](https://img.shields.io/badge/licence-MIT-blue.svg)
8
-
9
- ## 要約
10
-
11
- このplug-inは、これまで開発中で溜まっていた Rails標準のfixtureの不満点を解消するために作成しました。
12
- 基本的な操作は単純で次のコマンドで、それぞれfixtureのロードとダンプを行います。
13
-
14
- ```
15
- rake db:flextures:load
16
- rake db:flextures:dump
17
- ```
18
-
19
- また、rspecやminitest中でテストデータを読み込むのにも使用できます。
20
-
21
- ```ruby
22
- describe ItemShopController do
23
- flextures :users, :items
24
- end
25
- ```
26
-
27
- 通常のfixtureとの主な違いは次の4点です。
28
-
29
- 1. yamlよりもcsvを優先する
30
- 2. migrationでテーブル構成が変わっても、カラムの変更点を無視、補完してロードを行う
31
- 3. テーブル名とfixtureのファイル名を一致させないでも、自由なロード&ダンプが出来るオプション
32
- 4. FactoyGirl風の読み込みフィルタで、Fixtureのデータを加工しながら読み込む事が出来る
33
-
34
- <a name="table_of_contents"></a>
35
- ## 目次
36
-
37
- * [必要条件](#requirements)
38
- * [使い方](#usage)
39
- * [インストール方法](#how_to_install)
40
- * [rakeコマンドでの呼び出し方](#commandline_support)
41
- * [ユニットテストでの使い方](#unittest_support)
42
- * [読み込み・書き出しフィルター](#flextures_filter)
43
- * [設定ファイル](#configuration)
44
- * [貢献](#contributing)
45
- * [ライセンス](#licence)
46
-
47
- <a name="requirements"></a>
48
- ## 必要条件
49
-
50
- * ruby2.1以上
51
-
52
- <a name="usage"></a>
53
- ## 使い方
54
-
55
- <a name="how_to_install"></a>
56
- ### インストール方法
57
-
58
- RailsのPlug-inとして使われることを想定しています
59
- gem化されているので、bundlerで次のように記述して、普通にbundle install してください
60
-
61
- ```
62
- gem "flextures"
63
- ```
64
-
65
- ```
66
- bundle install
67
- bundle exec rails generate flextures:initializer
68
- ```
69
-
70
- <a name="commandline_support"></a>
71
- ### rakeコマンド
72
-
73
- 次のコマンドで spec/fixtures/ 以下にあるfixtureのロード&ダンプを行います
74
- (読み込む基本のディレクトリは設定ファイルで変更可能)
75
-
76
- ```
77
- rake db:flextures:load
78
- rake db:flextures:dump
79
- ```
80
-
81
- rake コマンドには以下の様な書式でオプションを指定することができます
82
- 指摘出来るオプションは、ロードとダンプで共通です
83
-
84
- テーブル名で吐き出し(Userモデルusers)
85
-
86
- ```
87
- rake db:flextures:dump TABLE=users
88
- ```
89
-
90
- Usersモデルのfixture(users.csvか users.yml)をロードする
91
-
92
- ```
93
- rake db:flextures:load MODEL=User
94
- ```
95
-
96
- その他オプションは以下の通りです:
97
-
98
- | オプション | 役割 |
99
- ------------|--------------------------------------------------------------------
100
- | TABLE | テーブル名を指定してロード。テーブル名はカンマ切りで複数指定が可能 |
101
- | MODEL | モデル名を指定してロード。モデル名はカンマ区切りで複数指定が可能 |
102
- | DIR | フィクスチャをロード&ダンプするディレクトリを指定する |
103
- | FILE | loadまたはdumpするファイル名を直接指定(Userモデルのusers.csv以外を指定) |
104
- | FORMAT | ダンプ、またはロードするデータの種類を指定できる(csvかyml) |
105
- | OPTION | その他の細かい読み込みオプションはここで指定出来ます |
106
- | T | TABLEのエイリアス |
107
- | D | ディレクトリ指定のエイリアス |
108
- | F | ファイル名指定のエイリアス |
109
-
110
- migration等でテーブルの構成が変わった時には
111
- generateコマンドを実行すると、テーブル情報のloadとdumpをセットで行なってくれるので便利です
112
-
113
- ```
114
- rake db:flextures:generate T=users
115
- ```
116
-
117
- さらに詳しい説明に関しては [Wiki:Rakeコマンドラインオプション](https://github.com/baban/flextures/wiki/Rake%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%82%AA%E3%83%97%E3%82%B7%E3%83%A7%E3%83%B3)を参照して下さい
118
-
119
- <a name="unittest_support"></a>
120
- ### ユニットテストでの使い方
121
-
122
- ユニットテスト中でデータの読み込みが行いたくなったときのために
123
- fixtureのロード機能を使えます
124
-
125
- 次の例はRSpecからの読み込みですが
126
- 基本的な機能は、通常のfixturesと同じですので、fixtures と同じ感覚で使用して下さい
127
-
128
- ```ruby
129
- describe ItemShopController do
130
- flextures :users, :items
131
- end
132
- ```
133
-
134
- 基本的な違いは、yamlよりcsvを優先する、カラムの変更点を検知して警告を出しながらもロードを行う等ですが
135
- もう一つ、ハッシュ引数で指定する事で、テーブル名、ファイル名を一致させなくても フィクスチャ を読み込ませることができます
136
- そのため、すべてのテストケースで依存関係を気にしながら共通のfixtureを使わなくても良い様に出来ます
137
-
138
- ```ruby
139
- describe ItemShopController do
140
- flextures :items, :users => :users_for_itemshop # users_for_itemshop.csv をロードする
141
- end
142
- ```
143
-
144
- その他現在はShouldからの呼び出しや様々なオプションを載せていますが
145
- さらに詳しい使い方に関しては [Wiki:Unit Test Supportの説明](https://github.com/baban/flextures/wiki/Unit-test-support%E3%81%AE%E8%AA%AC%E6%98%8E) を参照して下さい
146
-
147
- <a name="flextures_filter"></a>
148
- ### 読み込み・書き出しフィルター
149
-
150
- #### 読み込みフィルター
151
-
152
- Railsのプロジェクトに `config/flextures.factory.rb` というファイルを作成して、そこにフィルタを記述することによって
153
- フィクスチャの読み込み時に、値を加工して読み込む事が可能になっています
154
- 例えば、次の様に記述するとusersテーブルのlast_login_dateの値を、常に現在の時間として設定できます
155
-
156
- ```ruby
157
- Flextures::Factory.define :users do |f|
158
- f.last_login_date = DateTime.now
159
- end
160
- ```
161
-
162
- テーブルにdefaultの値を設定していなくても
163
- カラムのデータを適当に補完する機能があるので
164
- 大量のデータを生成したい時は次のように[faker](https://github.com/stympy/faker)等と組み合わせて
165
- 必要な分だけ生成をさせると、今までより若干捗るかもしれません
166
-
167
- ```ruby
168
- require 'faker'
169
- Flextures::Factory.define :users do |f|
170
- f.name= Faker::Name.name if !f.name # ランダムで名前を生成(ただしUS仕様
171
- f.sex= [0,1].shuffle.first if !f.sex # 性別を設定
172
- # Factory Girlの様にhas_manyな感じのデータも生成できます。(初期設定でアイテムを2個持たせる)
173
- f.items<< [ Item.new( master_item_id: 1, count: 5 ), Item.new( master_item_id: 2, count: 3 ) ]
174
- end
175
- ```
176
-
177
- * [wiki:has_manyな感じのデータの精製法](https://github.com/baban/flextures/wiki/Has-many%E3%81%AA%E6%84%9F%E3%81%98%E3%81%AE%E3%83%87%E3%83%BC%E3%82%BF%E3%81%AE%E7%B2%BE%E8%A3%BD%E6%96%B9%E6%B3%95)
178
-
179
- #### 書き出しフィルター
180
-
181
- データのdump時に加工が必要になった時には、同じく`config/flextures.factory.rb`に
182
- テーブル名と、加工したい値をキーに、処理をラムダで渡してやることで可能です
183
-
184
- ```ruby
185
- Flextures::DumpFilter.define :users, {
186
- :encrypted_password => lambda { |v| Base64.encode64(v) }
187
- }
188
- ```
189
-
190
- さらに細かい使い方に関しては [Wiki:FactoryFilterについて](https://github.com/baban/flextures/wiki/Factoryfilter%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6) を参照して下さい
191
-
192
- <a name="configuration"></a>
193
- ### 設定ファイル
194
-
195
- `config/initializers/flextures.rb` で設定ファイルを作成すると、データをロード&ダンプするディレクトリなどの設定を変更できます
196
-
197
- ```ruby
198
- Flextures::Configuration.configure do |config|
199
- # Load and dump directory change "spec/fixtures/" to "test/fixtures/"
200
- config.load_directory = "test/fixtures/"
201
- config.dump_directory = "test/fixtures/"
202
- end
203
- ```
204
-
205
- その他の情報は [Wiki:設定ファイルの書式について](https://github.com/baban/flextures/wiki/%E8%A8%AD%E5%AE%9A%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%81%AE%E6%9B%B8%E5%BC%8F%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6)を参照して下さい
206
-
207
- <a name="contributing"></a>
208
- ## 貢献
209
-
210
- https://github.com/baban/flextures/graphs/contributors
211
-
212
- <a name="licence"></a>
213
- ## ライセンス
214
-
215
- このソフトウェアは [MIT ライセンス](http://www.opensource.org/licenses/MIT)によってライセンスされています。
1
+ # flextures
2
+
3
+ * [ENGLISH DOCUMENT](https://github.com/baban/flextures/blob/master/README.md)
4
+
5
+ ![Ruby 2.3 higher](https://img.shields.io/badge/ruby-v2.3-red.svg)
6
+ ![Rails 4.2 higher](https://img.shields.io/badge/rails-v4.2-red.svg)
7
+ ![MIT Licence](https://img.shields.io/badge/licence-MIT-blue.svg)
8
+
9
+ ## 要約
10
+
11
+ このplug-inは、これまで開発中で溜まっていた Rails標準のfixtureの不満点を解消するために作成しました。
12
+ 基本的な操作は単純で次のコマンドで、それぞれfixtureのロードとダンプを行います。
13
+
14
+ ```
15
+ rake db:flextures:load
16
+ rake db:flextures:dump
17
+ ```
18
+
19
+ また、rspecやminitest中でテストデータを読み込むのにも使用できます。
20
+
21
+ ```ruby
22
+ describe ItemShopController do
23
+ flextures :users, :items
24
+ end
25
+ ```
26
+
27
+ 通常のfixtureとの主な違いは次の4点です。
28
+
29
+ 1. yamlよりもcsvを優先する
30
+ 2. migrationでテーブル構成が変わっても、カラムの変更点を無視、補完してロードを行う
31
+ 3. テーブル名とfixtureのファイル名を一致させないでも、自由なロード&ダンプが出来るオプション
32
+ 4. FactoyGirl風の読み込みフィルタで、Fixtureのデータを加工しながら読み込む事が出来る
33
+
34
+ <a name="table_of_contents"></a>
35
+ ## 目次
36
+
37
+ * [必要条件](#requirements)
38
+ * [使い方](#usage)
39
+ * [インストール方法](#how_to_install)
40
+ * [rakeコマンドでの呼び出し方](#commandline_support)
41
+ * [ユニットテストでの使い方](#unittest_support)
42
+ * [読み込み・書き出しフィルター](#flextures_filter)
43
+ * [設定ファイル](#configuration)
44
+ * [貢献](#contributing)
45
+ * [ライセンス](#licence)
46
+
47
+ <a name="requirements"></a>
48
+ ## 必要条件
49
+
50
+ * ruby2.3以上
51
+
52
+ <a name="usage"></a>
53
+ ## 使い方
54
+
55
+ <a name="how_to_install"></a>
56
+ ### インストール方法
57
+
58
+ RailsのPlug-inとして使われることを想定しています
59
+ gem化されているので、bundlerで次のように記述して、普通にbundle install してください
60
+
61
+ ```
62
+ gem "flextures"
63
+ ```
64
+
65
+ ```
66
+ bundle install
67
+ bundle exec rails generate flextures:initializer
68
+ ```
69
+
70
+ <a name="commandline_support"></a>
71
+ ### rakeコマンド
72
+
73
+ 次のコマンドで spec/fixtures/ 以下にあるfixtureのロード&ダンプを行います
74
+ (読み込む基本のディレクトリは設定ファイルで変更可能)
75
+
76
+ ```
77
+ rake db:flextures:load
78
+ rake db:flextures:dump
79
+ ```
80
+
81
+ rake コマンドには以下の様な書式でオプションを指定することができます
82
+ 指摘出来るオプションは、ロードとダンプで共通です
83
+
84
+ テーブル名で吐き出し(Userモデルusers)
85
+
86
+ ```
87
+ rake db:flextures:dump TABLE=users
88
+ ```
89
+
90
+ Usersモデルのfixture(users.csvか users.yml)をロードする
91
+
92
+ ```
93
+ rake db:flextures:load MODEL=User
94
+ ```
95
+
96
+ その他オプションは以下の通りです:
97
+
98
+ | オプション | 役割 |
99
+ ------------|--------------------------------------------------------------------
100
+ | TABLE | テーブル名を指定してロード。テーブル名はカンマ切りで複数指定が可能 |
101
+ | MODEL | モデル名を指定してロード。モデル名はカンマ区切りで複数指定が可能 |
102
+ | DIR | フィクスチャをロード&ダンプするディレクトリを指定する |
103
+ | FILE | loadまたはdumpするファイル名を直接指定(Userモデルのusers.csv以外を指定) |
104
+ | FORMAT | ダンプ、またはロードするデータの種類を指定できる(csvかyml) |
105
+ | OPTION | その他の細かい読み込みオプションはここで指定出来ます |
106
+ | T | TABLEのエイリアス |
107
+ | D | ディレクトリ指定のエイリアス |
108
+ | F | ファイル名指定のエイリアス |
109
+
110
+ migration等でテーブルの構成が変わった時には
111
+ generateコマンドを実行すると、テーブル情報のloadとdumpをセットで行なってくれるので便利です
112
+
113
+ ```
114
+ rake db:flextures:generate T=users
115
+ ```
116
+
117
+ さらに詳しい説明に関しては [Wiki:Rakeコマンドラインオプション](https://github.com/baban/flextures/wiki/Rake%E3%82%B3%E3%83%9E%E3%83%B3%E3%83%89%E3%82%AA%E3%83%97%E3%82%B7%E3%83%A7%E3%83%B3)を参照して下さい
118
+
119
+ <a name="unittest_support"></a>
120
+ ### ユニットテストでの使い方
121
+
122
+ ユニットテスト中でデータの読み込みが行いたくなったときのために
123
+ fixtureのロード機能を使えます
124
+
125
+ 次の例はRSpecからの読み込みですが
126
+ 基本的な機能は、通常のfixturesと同じですので、fixtures と同じ感覚で使用して下さい
127
+
128
+ ```ruby
129
+ describe ItemShopController do
130
+ flextures :users, :items
131
+ end
132
+ ```
133
+
134
+ 基本的な違いは、yamlよりcsvを優先する、カラムの変更点を検知して警告を出しながらもロードを行う等ですが
135
+ もう一つ、ハッシュ引数で指定する事で、テーブル名、ファイル名を一致させなくても フィクスチャ を読み込ませることができます
136
+ そのため、すべてのテストケースで依存関係を気にしながら共通のfixtureを使わなくても良い様に出来ます
137
+
138
+ ```ruby
139
+ describe ItemShopController do
140
+ flextures :items, :users => :users_for_itemshop # users_for_itemshop.csv をロードする
141
+ end
142
+ ```
143
+
144
+ その他現在はShouldからの呼び出しや様々なオプションを載せていますが
145
+ さらに詳しい使い方に関しては [Wiki:Unit Test Supportの説明](https://github.com/baban/flextures/wiki/Unit-test-support%E3%81%AE%E8%AA%AC%E6%98%8E) を参照して下さい
146
+
147
+ <a name="flextures_filter"></a>
148
+ ### 読み込み・書き出しフィルター
149
+
150
+ #### 読み込みフィルター
151
+
152
+ Railsのプロジェクトに `config/flextures.factory.rb` というファイルを作成して、そこにフィルタを記述することによって
153
+ フィクスチャの読み込み時に、値を加工して読み込む事が可能になっています
154
+ 例えば、次の様に記述するとusersテーブルのlast_login_dateの値を、常に現在の時間として設定できます
155
+
156
+ ```ruby
157
+ Flextures::Factory.define :users do |f|
158
+ f.last_login_date = DateTime.now
159
+ end
160
+ ```
161
+
162
+ テーブルにdefaultの値を設定していなくても
163
+ カラムのデータを適当に補完する機能があるので
164
+ 大量のデータを生成したい時は次のように[faker](https://github.com/stympy/faker)等と組み合わせて
165
+ 必要な分だけ生成をさせると、今までより若干捗るかもしれません
166
+
167
+ ```ruby
168
+ require 'faker'
169
+ Flextures::Factory.define :users do |f|
170
+ f.name= Faker::Name.name if !f.name # ランダムで名前を生成(ただしUS仕様
171
+ f.sex= [0,1].shuffle.first if !f.sex # 性別を設定
172
+ # Factory Girlの様にhas_manyな感じのデータも生成できます。(初期設定でアイテムを2個持たせる)
173
+ f.items<< [ Item.new( master_item_id: 1, count: 5 ), Item.new( master_item_id: 2, count: 3 ) ]
174
+ end
175
+ ```
176
+
177
+ * [wiki:has_manyな感じのデータの精製法](https://github.com/baban/flextures/wiki/Has-many%E3%81%AA%E6%84%9F%E3%81%98%E3%81%AE%E3%83%87%E3%83%BC%E3%82%BF%E3%81%AE%E7%B2%BE%E8%A3%BD%E6%96%B9%E6%B3%95)
178
+
179
+ #### 書き出しフィルター
180
+
181
+ データのdump時に加工が必要になった時には、同じく`config/flextures.factory.rb`に
182
+ テーブル名と、加工したい値をキーに、処理をラムダで渡してやることで可能です
183
+
184
+ ```ruby
185
+ Flextures::DumpFilter.define :users, {
186
+ :encrypted_password => lambda { |v| Base64.encode64(v) }
187
+ }
188
+ ```
189
+
190
+ さらに細かい使い方に関しては [Wiki:FactoryFilterについて](https://github.com/baban/flextures/wiki/Factoryfilter%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6) を参照して下さい
191
+
192
+ <a name="configuration"></a>
193
+ ### 設定ファイル
194
+
195
+ `config/initializers/flextures.rb` で設定ファイルを作成すると、データをロード&ダンプするディレクトリなどの設定を変更できます
196
+
197
+ ```ruby
198
+ Flextures::Configuration.configure do |config|
199
+ # Load and dump directory change "spec/fixtures/" to "test/fixtures/"
200
+ config.load_directory = "test/fixtures/"
201
+ config.dump_directory = "test/fixtures/"
202
+ end
203
+ ```
204
+
205
+ その他の情報は [Wiki:設定ファイルの書式について](https://github.com/baban/flextures/wiki/%E8%A8%AD%E5%AE%9A%E3%83%95%E3%82%A1%E3%82%A4%E3%83%AB%E3%81%AE%E6%9B%B8%E5%BC%8F%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6)を参照して下さい
206
+
207
+ <a name="contributing"></a>
208
+ ## 貢献
209
+
210
+ https://github.com/baban/flextures/graphs/contributors
211
+
212
+ <a name="licence"></a>
213
+ ## ライセンス
214
+
215
+ このソフトウェアは [MIT ライセンス](http://www.opensource.org/licenses/MIT)によってライセンスされています。