drysql 0.1.0 → 0.1.1
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/lib/base.rb +12 -0
- data/lib/dependencies.rb +12 -5
- metadata +2 -2
data/lib/base.rb
CHANGED
@@ -89,6 +89,14 @@ module ActiveRecord
|
|
89
89
|
def associations
|
90
90
|
@associations ? @associations : {}
|
91
91
|
end
|
92
|
+
|
93
|
+
def table_exists?(table_name=nil)
|
94
|
+
if connection.respond_to?(:tables)
|
95
|
+
connection.tables.include? construct_table_name_from_class_name(table_name)
|
96
|
+
else
|
97
|
+
false
|
98
|
+
end
|
99
|
+
end
|
92
100
|
|
93
101
|
|
94
102
|
private
|
@@ -113,6 +121,10 @@ module ActiveRecord
|
|
113
121
|
def pluralized_symbolized_class_name_from_table_name(table_name)
|
114
122
|
(class_name(table_name)).downcaseFirstLetter.pluralize.to_sym
|
115
123
|
end
|
124
|
+
|
125
|
+
def construct_table_name_from_class_name(class_name)
|
126
|
+
name = "#{table_name_prefix}#{undecorated_table_name(class_name)}#{table_name_suffix}"
|
127
|
+
end
|
116
128
|
|
117
129
|
end #end class << self (Class Methods)
|
118
130
|
|
data/lib/dependencies.rb
CHANGED
@@ -3,20 +3,27 @@ class Module #:nodoc:
|
|
3
3
|
alias :base_const_missing :const_missing
|
4
4
|
|
5
5
|
# If a non-existant class is specified, define it as a subclass of ActiveRecord::Base here
|
6
|
-
#
|
7
6
|
# This idea was inspired by the Magic Models project: http://magicmodels.rubyforge.org/
|
8
7
|
#
|
9
|
-
# I
|
10
|
-
#
|
8
|
+
# I added the modifications of on-demand generation and simple ActiveRecord::Base subclassing
|
9
|
+
#
|
10
|
+
# If a table can be found that matches the class_id, the class is defined in memory.
|
11
|
+
# If no matching table can be found, a NameError is thrown
|
11
12
|
def const_missing(class_id)
|
12
13
|
begin
|
13
14
|
base_const_missing(class_id)
|
14
15
|
rescue NameError
|
15
16
|
class_def = <<-end_class_def
|
16
|
-
class #{class_id} < ActiveRecord::Base
|
17
|
+
class #{class_id} < ActiveRecord::Base
|
17
18
|
end
|
18
19
|
end_class_def
|
19
|
-
|
20
|
+
if ActiveRecord::Base.table_exists?(class_id)
|
21
|
+
eval(class_def, TOPLEVEL_BINDING)
|
22
|
+
ActiveRecord::Base.logger.info("GENERATED CLASS: #{class_id} < ActiveRecord::Base")
|
23
|
+
else
|
24
|
+
ActiveRecord::Base.logger.error("No matching table could be found for class: #{class_id}")
|
25
|
+
raise NameError
|
26
|
+
end
|
20
27
|
end
|
21
28
|
const_get(class_id)
|
22
29
|
end
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.8.11
|
|
3
3
|
specification_version: 1
|
4
4
|
name: drysql
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2006-
|
6
|
+
version: 0.1.1
|
7
|
+
date: 2006-11-06 00:00:00 -05:00
|
8
8
|
summary: Extends ActiveRecord to provide automatic identification of keys, and automatic generation of associations and validations
|
9
9
|
require_paths:
|
10
10
|
- lib
|