temping 2.0.4 → 3.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. data/lib/temping.rb +26 -34
  2. metadata +55 -19
  3. data/lib/version.rb +0 -3
@@ -2,54 +2,46 @@ require "active_record"
2
2
  require "active_support/core_ext/string"
3
3
 
4
4
  class Temping
5
- class << self
6
- def create(model_name, &block)
7
- connect unless ActiveRecord::Base.connected?
5
+ VERSION = "3.0.1"
8
6
 
9
- model_class_name = model_name.to_s.classify
10
-
11
- if eval("defined?(#{model_class_name})")
12
- model_class_name.constantize
13
- else
14
- factory = ModelFactory.new(model_class_name, &block)
15
- factory.klass
16
- end
7
+ def self.create(model_name, &block)
8
+ unless ActiveRecord::Base.connected?
9
+ ActiveRecord::Base.establish_connection("sqlite3:///:memory:")
17
10
  end
18
11
 
19
- private
20
-
21
- def connect
22
- ActiveRecord::Base.configurations["temping"] = database_options
23
- ActiveRecord::Base.establish_connection("temping")
24
- end
25
-
26
- def database_options
27
- { :adapter => "sqlite3", :database => ":memory:" }
28
- end
12
+ factory = ModelFactory.new(model_name.to_s.classify, &block)
13
+ factory.klass
29
14
  end
30
15
 
31
16
  class ModelFactory
32
- attr_reader :klass
33
-
34
17
  def initialize(model_name, &block)
35
- @klass = Class.new(ActiveRecord::Base)
18
+ @model_name = model_name
19
+ klass.class_eval(&block) if block_given?
20
+ end
36
21
 
37
- Object.const_set(model_name, @klass)
38
- create_table
39
- add_methods
40
- @klass.class_eval(&block) if block_given?
22
+ def klass
23
+ @klass ||= Object.const_get(@model_name)
24
+ rescue NameError
25
+ @klass = build
41
26
  end
42
27
 
43
28
  private
44
29
 
45
- def create_table
46
- connection.create_table(table_name, :temporary => true) do |table|
47
- table.integer :id
30
+ def build
31
+ Class.new(ActiveRecord::Base).tap do |klass|
32
+ Object.const_set(@model_name, klass)
33
+
34
+ create_table
35
+ add_methods
48
36
  end
49
37
  end
50
38
 
39
+ def create_table
40
+ connection.create_table(table_name, :temporary => true)
41
+ end
42
+
51
43
  def add_methods
52
- class << @klass
44
+ class << klass
53
45
  def with_columns
54
46
  connection.change_table(table_name) do |table|
55
47
  yield(table)
@@ -63,11 +55,11 @@ class Temping
63
55
  end
64
56
 
65
57
  def connection
66
- @klass.connection
58
+ klass.connection
67
59
  end
68
60
 
69
61
  def table_name
70
- @klass.table_name
62
+ klass.table_name
71
63
  end
72
64
  end
73
65
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: temping
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.4
4
+ version: 3.0.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,52 +9,88 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-11-14 00:00:00.000000000Z
12
+ date: 2013-04-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord
16
- requirement: &70232219712840 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
- - - ~>
19
+ - - ! '>='
20
20
  - !ruby/object:Gem::Version
21
- version: 3.1.1
21
+ version: '3.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70232219712840
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '3.1'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: activesupport
27
- requirement: &70232219712060 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
- - - ~>
35
+ - - ! '>='
31
36
  - !ruby/object:Gem::Version
32
- version: 3.1.1
37
+ version: '3.1'
33
38
  type: :runtime
34
39
  prerelease: false
35
- version_requirements: *70232219712060
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '3.1'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: sqlite3
38
- requirement: &70232219711460 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ~>
42
52
  - !ruby/object:Gem::Version
43
- version: 1.3.4
53
+ version: 1.3.7
44
54
  type: :runtime
45
55
  prerelease: false
46
- version_requirements: *70232219711460
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: 1.3.7
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: rspec
49
- requirement: &70232219710760 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
- - - ~>
67
+ - - ! '>='
53
68
  - !ruby/object:Gem::Version
54
- version: 2.7.0
69
+ version: 2.13.0
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70232219710760
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: 2.13.0
78
+ - !ruby/object:Gem::Dependency
79
+ name: rake
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: 10.0.4
86
+ type: :development
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: 10.0.4
58
94
  description:
59
95
  email: john@pignata.com
60
96
  executables: []
@@ -62,7 +98,6 @@ extensions: []
62
98
  extra_rdoc_files: []
63
99
  files:
64
100
  - lib/temping.rb
65
- - lib/version.rb
66
101
  homepage: http://github.com/jpignata/temping
67
102
  licenses: []
68
103
  post_install_message:
@@ -83,8 +118,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
83
118
  version: '0'
84
119
  requirements: []
85
120
  rubyforge_project:
86
- rubygems_version: 1.8.10
121
+ rubygems_version: 1.8.24
87
122
  signing_key:
88
123
  specification_version: 3
89
124
  summary: Create temporary table-backed ActiveRecord models for use in tests
90
125
  test_files: []
126
+ has_rdoc:
@@ -1,3 +0,0 @@
1
- class Temping
2
- VERSION = "2.0.4"
3
- end