active_table 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +30 -0
- data/lib/active_table/base.rb +9 -0
- data/lib/active_table/version.rb +1 -1
- metadata +5 -25
data/README.md
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
# ActiveTable
|
2
|
+
|
3
|
+
ActiveTable is a thin layer on top of ActiveRecord that uses temporary tables to meet
|
4
|
+
all of your static data needs.
|
5
|
+
|
6
|
+
## Installation
|
7
|
+
|
8
|
+
gem install active_table
|
9
|
+
|
10
|
+
## Usage
|
11
|
+
|
12
|
+
Everything you need to set up ActiveTable lives within your model. It should be placed
|
13
|
+
above any other code so that it can initialize the table and tell ActiveRecord to
|
14
|
+
reload the attributes from the table. A sample model is as follows:
|
15
|
+
|
16
|
+
class Color < ActiveTable::Base
|
17
|
+
active_table do
|
18
|
+
create_table :colors do |t|
|
19
|
+
t.string :name
|
20
|
+
end
|
21
|
+
|
22
|
+
insert :id => 1, :name => "Chartreuse"
|
23
|
+
insert :id => 2, :name => "Cerulean"
|
24
|
+
insert :id => 3, :name => "Taupe"
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
ActiveTable will handle all of the CREATE/INSERT operations for every database
|
29
|
+
connections that is opened. You get to use your new model just like an ActiveRecord
|
30
|
+
model and stop worrying about everything else.
|
data/lib/active_table/base.rb
CHANGED
@@ -22,6 +22,13 @@ module ActiveTable
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def self.create_tables(connection)
|
25
|
+
started_inside_a_transaction = !connection.outside_transaction?
|
26
|
+
begin
|
27
|
+
connection.execute("COMMIT") if started_inside_a_transaction
|
28
|
+
rescue ActiveRecord::StatementInvalid
|
29
|
+
started_inside_a_transaction = false
|
30
|
+
end
|
31
|
+
|
25
32
|
@@tables.each_value do |table|
|
26
33
|
next if connection.active_table_loaded_for?(table[:name])
|
27
34
|
connection.create_table table[:name], table[:options].merge(:temporary => true) do |t|
|
@@ -33,6 +40,8 @@ module ActiveTable
|
|
33
40
|
end
|
34
41
|
connection.mark_active_table_as_loaded(table[:name])
|
35
42
|
end
|
43
|
+
|
44
|
+
connection.execute("BEGIN") if started_inside_a_transaction
|
36
45
|
end
|
37
46
|
|
38
47
|
def self.generate_insert_sql_for_hash(connection, table_name, params)
|
data/lib/active_table/version.rb
CHANGED
metadata
CHANGED
@@ -1,13 +1,8 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_table
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
5
|
-
|
6
|
-
segments:
|
7
|
-
- 0
|
8
|
-
- 0
|
9
|
-
- 3
|
10
|
-
version: 0.0.3
|
4
|
+
prerelease:
|
5
|
+
version: 0.0.4
|
11
6
|
platform: ruby
|
12
7
|
authors:
|
13
8
|
- Case Commons LLC
|
@@ -15,7 +10,7 @@ autorequire:
|
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
12
|
|
18
|
-
date: 2011-
|
13
|
+
date: 2011-07-01 00:00:00 -04:00
|
19
14
|
default_executable:
|
20
15
|
dependencies:
|
21
16
|
- !ruby/object:Gem::Dependency
|
@@ -26,19 +21,9 @@ dependencies:
|
|
26
21
|
requirements:
|
27
22
|
- - ">="
|
28
23
|
- !ruby/object:Gem::Version
|
29
|
-
hash: 9
|
30
|
-
segments:
|
31
|
-
- 2
|
32
|
-
- 3
|
33
|
-
- 5
|
34
24
|
version: 2.3.5
|
35
25
|
- - <
|
36
26
|
- !ruby/object:Gem::Version
|
37
|
-
hash: 63
|
38
|
-
segments:
|
39
|
-
- 4
|
40
|
-
- 0
|
41
|
-
- 0
|
42
27
|
version: 4.0.0
|
43
28
|
type: :runtime
|
44
29
|
version_requirements: *id001
|
@@ -54,6 +39,7 @@ extra_rdoc_files: []
|
|
54
39
|
files:
|
55
40
|
- .gitignore
|
56
41
|
- Gemfile
|
42
|
+
- README.md
|
57
43
|
- Rakefile
|
58
44
|
- active_table.gemspec
|
59
45
|
- gemfiles/Gemfile.common
|
@@ -81,23 +67,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
81
67
|
requirements:
|
82
68
|
- - ">="
|
83
69
|
- !ruby/object:Gem::Version
|
84
|
-
hash: 3
|
85
|
-
segments:
|
86
|
-
- 0
|
87
70
|
version: "0"
|
88
71
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
72
|
none: false
|
90
73
|
requirements:
|
91
74
|
- - ">="
|
92
75
|
- !ruby/object:Gem::Version
|
93
|
-
hash: 3
|
94
|
-
segments:
|
95
|
-
- 0
|
96
76
|
version: "0"
|
97
77
|
requirements: []
|
98
78
|
|
99
79
|
rubyforge_project: active_table
|
100
|
-
rubygems_version: 1.
|
80
|
+
rubygems_version: 1.6.2
|
101
81
|
signing_key:
|
102
82
|
specification_version: 3
|
103
83
|
summary: Dynamically-populated ActiveRecord models based on static data
|