flextures 1.0.3 → 1.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/README.rdoc +2 -0
- data/VERSION +1 -1
- data/flextures.gemspec +2 -2
- data/lib/flextures/flextures.rb +18 -14
- metadata +11 -11
data/README.rdoc
CHANGED
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.0.
|
1
|
+
1.0.4
|
data/flextures.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{flextures}
|
8
|
-
s.version = "1.0.
|
8
|
+
s.version = "1.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 = %q{2011-
|
12
|
+
s.date = %q{2011-12-04}
|
13
13
|
s.description = %q{load and dump fixtures}
|
14
14
|
s.email = %q{babanba.n@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/flextures/flextures.rb
CHANGED
@@ -40,21 +40,28 @@ module Flextures
|
|
40
40
|
table_names = ENV["M"].constantize.table_name.split(",") if ENV["M"]
|
41
41
|
table_names = ActiveRecord::Base.connection.tables if ""==table_names
|
42
42
|
table_names = table_names.map{ |name| { table: name } }
|
43
|
+
# ENV["FIXTURES"]の中身を解析
|
44
|
+
fixtures_args_parser =->(s){
|
45
|
+
names = s.split(',')
|
46
|
+
( names.size==1 and ENV.values_at("M", "MODEL", "T", "TABLE").first ) ?
|
47
|
+
[ table_names.first.merge( file: names.first ) ] :
|
48
|
+
names.map{ |name| { table: name, file: name } }
|
49
|
+
}
|
50
|
+
table_names = fixtures_args_parser.call ENV["FIXTURES"] if ENV["FIXTURES"]
|
51
|
+
table_names = fixtures_args_parser.call ENV["F"] if ENV["F"]
|
43
52
|
table_names = table_names.map{ |option| option.merge dir: ENV["DIR"] } if ENV["DIR"]
|
44
|
-
table_names = ENV["FIXTURES"].split(',').map{ |name| { table: name } } if ENV["FIXTURES"]
|
45
|
-
table_names = ENV["F"].split(',').map{ |name| { table: name } } if ENV["F"]
|
46
53
|
# read mode だとcsvもyaml存在しないファイルは返さない
|
47
|
-
table_names.select! &exist if option[:mode] && option[:mode].to_sym == :read
|
54
|
+
table_names.select! &exist if option[:mode] && option[:mode].to_sym == :read
|
48
55
|
table_names
|
49
56
|
end
|
50
57
|
|
51
|
-
# 存在しているファイルで絞り込む
|
58
|
+
# 存在しているファイルで絞り込む
|
52
59
|
def self.exist
|
53
60
|
return->(name){ File.exists?("#{LOAD_DIR}#{name}.csv") or File.exists?("#{LOAD_DIR}#{name}.yml") }
|
54
61
|
end
|
55
62
|
end
|
56
63
|
|
57
|
-
# データを吐き出す処理をまとめる
|
64
|
+
# データを吐き出す処理をまとめる
|
58
65
|
module Dumper
|
59
66
|
PARENT = Flextures
|
60
67
|
|
@@ -67,7 +74,7 @@ module Flextures
|
|
67
74
|
end
|
68
75
|
end
|
69
76
|
|
70
|
-
# csv で fixtures を dump
|
77
|
+
# csv で fixtures を dump
|
71
78
|
def self.csv format
|
72
79
|
table_name = format[:table]
|
73
80
|
file_name = format[:file] || table_name
|
@@ -84,7 +91,7 @@ module Flextures
|
|
84
91
|
end
|
85
92
|
end
|
86
93
|
|
87
|
-
# yaml で fixtures を dump
|
94
|
+
# yaml で fixtures を dump
|
88
95
|
def self.yml format
|
89
96
|
table_name = format[:table]
|
90
97
|
file_name = format[:file] || table_name
|
@@ -92,14 +99,13 @@ module Flextures
|
|
92
99
|
outfile = "#{dir_name}#{file_name}.yml"
|
93
100
|
klass = PARENT::create_model(table_name)
|
94
101
|
attributes = klass.columns.map { |colum| colum.name }
|
95
|
-
|
96
102
|
File.open(outfile,"w") do |f|
|
97
|
-
klass.all.each_with_index do |row,idx|
|
103
|
+
klass.all.each_with_index do |row,idx|
|
98
104
|
f<< "#{table_name}_#{idx}:\n" +
|
99
105
|
attributes.map { |column|
|
100
106
|
v = trans row.send(column)
|
101
107
|
" #{column}: #{v}\n"
|
102
|
-
}
|
108
|
+
}.join
|
103
109
|
end
|
104
110
|
end
|
105
111
|
end
|
@@ -149,12 +155,12 @@ module Flextures
|
|
149
155
|
self::send(method, format) if method
|
150
156
|
end
|
151
157
|
|
152
|
-
# fixturesをまとめてロード、主にテストtest/unit, rspec で使用する
|
158
|
+
# fixturesをまとめてロード、主にテストtest/unit, rspec で使用する
|
153
159
|
def self.flextures *fixtures
|
154
160
|
PARENT::init_load
|
155
161
|
# :allですべてのfixtureを反映
|
156
162
|
fixtures = ActiveRecord::Base.connection.tables if fixtures.size== 1 and :all == fixtures.first
|
157
|
-
|
163
|
+
|
158
164
|
fixtures_hash = fixtures.pop if fixtures.last and fixtures.last.is_a? Hash # ハッシュ取り出し
|
159
165
|
fixtures.each{ |table_name| Loader::load table: table_name }
|
160
166
|
fixtures_hash.each{ |k,v| Loader::load table: k, file: v } if fixtures_hash
|
@@ -167,7 +173,6 @@ module Flextures
|
|
167
173
|
file_name = format[:file] || table_name
|
168
174
|
dir_name = format[:dir] || LOAD_DIR
|
169
175
|
inpfile = "#{dir_name}#{file_name}.csv"
|
170
|
-
|
171
176
|
klass = PARENT::create_model table_name
|
172
177
|
attributes = klass.columns.map &:name
|
173
178
|
filter = create_filter klass.columns, Factory[table_name]
|
@@ -191,7 +196,6 @@ module Flextures
|
|
191
196
|
file_name = format[:file] || table_name
|
192
197
|
dir_name = format[:dir] || LOAD_DIR
|
193
198
|
inpfile = "#{dir_name}#{file_name}.yml"
|
194
|
-
|
195
199
|
klass = PARENT::create_model table_name
|
196
200
|
attributes = klass.columns.map &:name
|
197
201
|
filter = create_filter klass.columns, Factory[table_name]
|
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.0.
|
4
|
+
version: 1.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,12 +9,12 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2011-
|
12
|
+
date: 2011-12-04 00:00:00.000000000 +09:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: shoulda
|
17
|
-
requirement: &
|
17
|
+
requirement: &75392980 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :development
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *75392980
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: bundler
|
28
|
-
requirement: &
|
28
|
+
requirement: &75392680 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ~>
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: 1.0.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *75392680
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: jeweler
|
39
|
-
requirement: &
|
39
|
+
requirement: &75392380 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ~>
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
version: 1.6.4
|
45
45
|
type: :development
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
47
|
+
version_requirements: *75392380
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: rcov
|
50
|
-
requirement: &
|
50
|
+
requirement: &75392080 !ruby/object:Gem::Requirement
|
51
51
|
none: false
|
52
52
|
requirements:
|
53
53
|
- - ! '>='
|
@@ -55,7 +55,7 @@ dependencies:
|
|
55
55
|
version: '0'
|
56
56
|
type: :development
|
57
57
|
prerelease: false
|
58
|
-
version_requirements: *
|
58
|
+
version_requirements: *75392080
|
59
59
|
description: load and dump fixtures
|
60
60
|
email: babanba.n@gmail.com
|
61
61
|
executables: []
|
@@ -101,7 +101,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
101
101
|
version: '0'
|
102
102
|
segments:
|
103
103
|
- 0
|
104
|
-
hash:
|
104
|
+
hash: 876332047
|
105
105
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
106
106
|
none: false
|
107
107
|
requirements:
|