flextures 1.9.7 → 1.9.8

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,7 +7,7 @@ GEM
7
7
  git (>= 1.2.5)
8
8
  rake
9
9
  rdoc
10
- json (1.6.5)
10
+ json (1.6.6)
11
11
  rake (0.9.2.2)
12
12
  rdoc (3.12)
13
13
  json (~> 1.4)
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.9.7
1
+ 1.9.8
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "flextures"
8
- s.version = "1.9.7"
8
+ s.version = "1.9.8"
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"
12
+ s.date = "2012-04-20"
13
13
  s.description = "load and dump fixtures"
14
14
  s.email = "babanba.n@gmail.com"
15
15
  s.extra_rdoc_files = [
@@ -44,16 +44,35 @@ module Flextures
44
44
  end
45
45
 
46
46
  # テーブル情報の初期化
47
- def self.init_tables
47
+ def self.init_tables(ignore_tables=[])
48
48
  tables = ActiveRecord::Base.connection.tables
49
49
  tables.delete "schema_migrations"
50
- tables.each{ |name|
50
+ tables.delete ignore_tables
51
+ tables.each do |name|
51
52
  # テーブルではなくviewを拾って止まる場合があるのでrescueしてしまう
52
53
  begin
53
- Class.new(ActiveRecord::Base){ |o| o.table_name= name }.delete_all
54
+ klass = Class.new(ActiveRecord::Base){ |o| o.table_name= name }
55
+ klass.delete_all
54
56
  rescue => e
57
+ p :init_table_error
58
+ p klass.table_name
55
59
  end
56
- }
60
+ end
61
+ end
62
+
63
+ # デバッグ用のメソッド、渡されたブロックを実行する
64
+ # 主にテーブルの今の中身を覗きたい時に使う
65
+ def self.table_tap &dumper
66
+ tables = ActiveRecord::Base.connection.tables
67
+ tables.delete "schema_migrations"
68
+ tables.each do |name|
69
+ # テーブルではなくviewを拾って止まる場合があるのでrescueしてしまう
70
+ begin
71
+ klass = Class.new(ActiveRecord::Base){ |o| o.table_name= name; }
72
+ dumper.call klass
73
+ rescue => e
74
+ end
75
+ end
57
76
  end
58
77
 
59
78
  # 引数解析
@@ -6,69 +6,107 @@ module Flextures
6
6
  PARENT = Flextures
7
7
 
8
8
  TRANSLATER = {
9
- binary:->(d, format ){
9
+ binary:->( d, format ){
10
+ if format == :yml
11
+ return "null" if d.nil?
12
+ end
10
13
  d.to_s
11
14
  },
12
- boolean:->(d, format ){
15
+ boolean:->( d, format ){
16
+ if format == :yml
17
+ return "null" if d.nil?
18
+ end
13
19
  (0==d || ""==d || !d) ? false : true
14
20
  },
15
- date:->(d, format ){
21
+ date:->( d, format ){
16
22
  if format == :yml
17
23
  return "null" if d.nil?
24
+ return "null" if d==""
25
+ return "null" if d==false
18
26
  end
19
- Time.parse(d.to_s).to_s
27
+ d.to_s
20
28
  },
21
- datetime:->(d, format ){
22
- Time.parse(d.to_s).to_s
29
+ datetime:->( d, format ){
30
+ if format == :yml
31
+ return "null" if d.nil?
32
+ return "null" if d==""
33
+ return "null" if d==false
34
+ end
35
+ d.to_s
23
36
  },
24
- decimal:->(d, format ){
37
+ decimal:->( d, format ){
38
+ if format == :yml
39
+ return "null" if d.nil?
40
+ end
41
+ return 0 if d==""
42
+ return 0 if d==false
25
43
  d.to_i
26
44
  },
27
45
  float:->(d, format){
46
+ if format == :yml
47
+ return "null" if d.nil?
48
+ end
49
+ return 0 if d==""
50
+ return 0 if d==false
28
51
  d.to_f
29
52
  },
30
- integer:->(d, format){
53
+ integer:->( d, format){
54
+ if format == :yml
55
+ return "null" if d.nil?
56
+ end
57
+ return 0 if d==""
58
+ return 0 if d==false
31
59
  d.to_i
32
60
  },
33
- string:->(s, format ){
61
+ string:->( s, format ){
34
62
  if format == :yml
35
- return "null" if s.nil?
36
- s = s.to_s
37
- s = s.gsub(/\t/," ") if s["\t"]
38
- s = s.sub(/ +/, "") if s[0]==' '
39
- s = "|-\n " + s.gsub(/\n/,"\n ") if s["\n"]
63
+ return "null" if s.nil?
64
+ if s.kind_of?(String)
65
+ s = s.gsub(/\t/," ") if s["\t"]
66
+ s = s.sub(/ +/, "") if s[0]==' '
67
+ s = s.gsub(/\r\n/,"\n").gsub(/\r/,"\n") # 改行方法統一
68
+ s = "|-\n " + s.gsub(/\n/,"\n ") if s["\n"]
69
+ end
40
70
  end
41
- if format == :yml
71
+ if format == :csv
42
72
  return nil if s.nil? # nil は空白文字
43
73
  s = s.to_s
74
+ s = s.gsub(/\r\n/,"\n").gsub(/\r/,"\n")
44
75
  end
45
76
  s
46
77
  },
47
- text:->(s, format){
78
+ text:->( s, format ){
48
79
  if format == :yml
49
- return "null" if s.nil?
50
- s = s.to_s
51
- s = s.gsub(/\t/," ") if s["\t"]
52
- s = s.sub(/ +/, "") if s[0]==' '
53
- s = "|-\n " + s.gsub(/\n/,"\n ") if s["\n"]
80
+ return "null" if s.nil?
81
+ if s.kind_of?(String)
82
+ s = s.gsub(/\t/," ") if s["\t"]
83
+ s = s.sub(/ +/, "") if s[0]==' '
84
+ s = s.gsub(/\r\n/,"\n").gsub(/\r/,"\n") # 改行方法統一
85
+ s = "|-\n " + s.gsub(/\n/,"\n ") if s["\n"]
86
+ end
54
87
  end
55
88
  if format == :csv
56
89
  return nil if s.nil? # nil は空白文字
57
90
  s = s.to_s
91
+ s = s.gsub(/\r\n/,"\n").gsub(/\r/,"\n")
58
92
  end
59
93
  s
60
94
  },
61
- time:->(d, format ){
95
+ time:->( d, format ){
62
96
  if format == :yml
63
97
  return "null" if d.nil?
98
+ return "null" if d==""
99
+ return "null" if d==false
64
100
  end
65
- Time.parse(d.to_s).to_s
101
+ d.to_s
66
102
  },
67
- timestamp:->(d, format ){
103
+ timestamp:->( d, format ){
68
104
  if format == :yml
69
105
  return "null" if d.nil?
106
+ return "null" if d==""
107
+ return "null" if d==false
70
108
  end
71
- Time.parse(d.to_s).to_s
109
+ d.to_s
72
110
  },
73
111
  }
74
112
 
@@ -30,17 +30,53 @@ module Flextures
30
30
 
31
31
  # 型の変換を行う
32
32
  TRANSLATER = {
33
- binary:->(d){ d.to_i },
34
- boolean:->(d){ (0==d || ""==d || !d) ? false : true },
35
- date:->(d){ Date.parse(d.to_s) },
36
- datetime:->(d){ DateTime.parse(d.to_s) },
37
- decimal:->(d){ d.to_i },
38
- float:->(d){ d.to_f },
39
- integer:->(d){ d.to_i },
40
- string:->(d){ d.to_s },
41
- text:->(d){ d.to_s },
42
- time:->(d){ DateTime.parse(d.to_s) },
43
- timestamp:->(d){ DateTime.parse(d.to_s) },
33
+ binary:->(d){
34
+ d.to_i
35
+ },
36
+ boolean:->(d){
37
+ return d if d.nil?
38
+ (0==d || ""==d || !d) ? false : true
39
+ },
40
+ date:->(d){
41
+ return d if d.nil?
42
+ return nil if d==""
43
+ Date.parse(d.to_s)
44
+ },
45
+ datetime:->(d){
46
+ return d if d.nil?
47
+ return nil if d==""
48
+ DateTime.parse(d.to_s)
49
+ },
50
+ decimal:->(d){
51
+ return d if d.nil?
52
+ d.to_i
53
+ },
54
+ float:->(d){
55
+ return d if d.nil?
56
+ d.to_f
57
+ },
58
+ integer:->(d){
59
+ return d if d.nil?
60
+ d.to_i
61
+ },
62
+ string:->(d){
63
+ return d if d.nil?
64
+ d.to_s
65
+ },
66
+ text:->(d){
67
+ return d if d.nil?
68
+ d.to_s
69
+ },
70
+ time:->(d){
71
+ return d if d.nil?
72
+ return nil if d==""
73
+ DateTime.parse(d.to_s)
74
+ },
75
+ timestamp:->(d){
76
+ return d if d.nil?
77
+ return nil if d==""
78
+ DateTime.parse(d.to_s)
79
+ },
44
80
  }
45
81
 
46
82
  # csv 優先で存在している fixtures をロード
@@ -78,7 +114,7 @@ module Flextures
78
114
  inpfile = "#{dir_name}#{file_name}.csv"
79
115
  klass = PARENT::create_model table_name
80
116
  attributes = klass.columns.map &:name
81
- filter = create_filter klass, Factory[table_name], file_name, :csv
117
+ filter = create_filter klass, Factory[table_name], file_name, :csv
82
118
  klass.delete_all
83
119
  CSV.open( inpfile ) do |csv|
84
120
  keys = csv.shift # keyの設定
@@ -14,9 +14,7 @@ module RSpec
14
14
  module FlextureSupport
15
15
  @@configs={ load_count: 0 }
16
16
  def self.included(m)
17
- # 一番外側のdescribeにだけ追加
18
- #m.after { Flextures::init_tables } if @@configs[:load_count]==0
19
- @@configs[:load_count] += 1
17
+ Flextures::init_tables
20
18
  end
21
19
  end
22
20
  end
@@ -29,21 +27,15 @@ end
29
27
  # 既存のsetup_fixturesの機能を上書きする必要があったのでこちらを作成
30
28
  module ActiveRecord
31
29
  module TestFixtures
32
- @@flextures_config = { count: 0 }
33
-
34
- alias :flextures_backup_setup_fixtures :setup_fixtures
30
+ alias :setup_fixtures_bkup :setup_fixtures
35
31
  def setup_fixtures
36
32
  Flextures::init_load
37
- Flextures::init_tables if @@flextures_config[:count] == 0
38
- @@flextures_config[:count] += 1
39
-
40
- flextures_backup_setup_fixtures
33
+ setup_fixtures_bkup
41
34
  end
42
35
 
43
- alias :flextures_backup_teardown_fixtures :teardown_fixtures
36
+ alias :teardown_fixtures_bkup :teardown_fixtures
44
37
  def teardown_fixtures
45
- Flextures::init_tables if Flextures::Config.init_all_tables
46
- flextures_backup_teardown_fixtures
38
+ teardown_fixtures_bkup
47
39
  end
48
40
  end
49
41
  end
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.7
4
+ version: 1.9.8
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 00:00:00.000000000 Z
12
+ date: 2012-04-20 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -89,7 +89,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
89
89
  version: '0'
90
90
  segments:
91
91
  - 0
92
- hash: -377856707
92
+ hash: 294980813
93
93
  required_rubygems_version: !ruby/object:Gem::Requirement
94
94
  none: false
95
95
  requirements: