empty_eye 0.4.1 → 0.4.2
Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,13 @@
|
|
1
1
|
# 0.4.1 / 2012-03-11 / Grady Griffin
|
2
2
|
|
3
|
+
* reorganized some methods
|
4
|
+
* added logic to free up complex data structures once they are not needed
|
5
|
+
* fixed some comment typos
|
6
|
+
* added comments
|
7
|
+
* updated reflect\_on\_multiple\_associations to work as intended
|
8
|
+
|
9
|
+
# 0.4.1 / 2012-03-11 / Grady Griffin
|
10
|
+
|
3
11
|
* added homepage to gemspec
|
4
12
|
|
5
13
|
# 0.4.0 / 2012-03-11 / Grady Griffin
|
@@ -3,7 +3,7 @@ module ActiveRecord
|
|
3
3
|
|
4
4
|
class << self
|
5
5
|
|
6
|
-
#am i
|
6
|
+
#am i a mti class? easier than making a new class type ... i tried
|
7
7
|
def mti_class?
|
8
8
|
extended_with.any?
|
9
9
|
end
|
@@ -11,7 +11,7 @@ module ActiveRecord
|
|
11
11
|
#interface for building mti_class
|
12
12
|
#primary table is not necessary if the table named correctly (Bar => bars_core)
|
13
13
|
#OR if the class inherits a primary table
|
14
|
-
#simply wrap your greasy
|
14
|
+
#simply wrap your greasy associations in this block
|
15
15
|
def mti_class(primary_table = nil)
|
16
16
|
self.primary_key = "id"
|
17
17
|
raise(EmptyEye::AlreadyExtended, "MTI class method already invoked") if mti_class?
|
@@ -36,7 +36,7 @@ module ActiveRecord
|
|
36
36
|
extended_with.primary.shard
|
37
37
|
end
|
38
38
|
|
39
|
-
#we dont need no freakin'
|
39
|
+
#we dont need no freakin' type condition
|
40
40
|
#the view handles this
|
41
41
|
def finder_needs_type_condition?
|
42
42
|
!mti_class? and super
|
@@ -62,9 +62,9 @@ module ActiveRecord
|
|
62
62
|
end
|
63
63
|
|
64
64
|
#determine the primary table
|
65
|
-
#first
|
65
|
+
#first determine if our view name exists; this will need to change one day
|
66
66
|
#if they didnt specify try using the core convention else the superclass
|
67
|
-
#if they specified use what
|
67
|
+
#if they specified use what they set
|
68
68
|
def set_mti_primary_table(primary_table_name)
|
69
69
|
@mti_primary_table = if ordinary_table_exists?
|
70
70
|
raise(EmptyEye::ViewNameError, "MTI view cannot be created because a table named '#{compute_view_name}' already exists")
|
@@ -83,7 +83,7 @@ module ActiveRecord
|
|
83
83
|
#we could use the baked in version for now
|
84
84
|
def reflect_on_multiple_associations(*assoc_types)
|
85
85
|
assoc_types.collect do |assoc_type|
|
86
|
-
reflect_on_all_associations
|
86
|
+
reflect_on_all_associations(assoc_type)
|
87
87
|
end.flatten.uniq
|
88
88
|
end
|
89
89
|
|
@@ -92,7 +92,7 @@ module ActiveRecord
|
|
92
92
|
connection.tables_without_views.include?(compute_view_name)
|
93
93
|
end
|
94
94
|
|
95
|
-
#drop the view; dont check if we can just rescue any errors
|
95
|
+
#drop the view; dont check if we can, just rescue any errors
|
96
96
|
#create the view
|
97
97
|
def create_view
|
98
98
|
connection.execute("DROP VIEW #{table_name}") rescue nil
|
@@ -105,15 +105,17 @@ module ActiveRecord
|
|
105
105
|
end
|
106
106
|
|
107
107
|
#we know how to rebuild the validations from the shards
|
108
|
-
#lets call our inherited
|
108
|
+
#lets call our inherited validations here
|
109
109
|
def inherit_mti_validations
|
110
110
|
extended_with.validations.each {|args| send(*args)}
|
111
|
+
#no need to keep these in memory
|
112
|
+
extended_with.free_validations
|
111
113
|
end
|
112
114
|
end
|
113
115
|
|
114
116
|
private
|
115
117
|
|
116
|
-
#a pseudo association method back to instances primary shard
|
118
|
+
#a pseudo association method mapping us back to instances primary shard
|
117
119
|
def mti_primary_shard
|
118
120
|
@mti_primary_shard ||= if new_record?
|
119
121
|
self.class.mti_primary_shard.new(:mti_instance => self)
|
data/lib/empty_eye/errors.rb
CHANGED
data/lib/empty_eye/shard.rb
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
module EmptyEye
|
2
2
|
module Shard
|
3
3
|
|
4
|
-
#
|
5
|
-
#when there is a superclass the will inherit from that else it will inherit from ActiveRecord
|
4
|
+
#module which extends the class that serves as a pointer to the primary table
|
5
|
+
#when there is a superclass the shard will inherit from that, else it will inherit from ActiveRecord
|
6
6
|
#the primary shard manages all the MTI associated tables for the master class
|
7
7
|
|
8
8
|
def self.included(base)
|
@@ -10,8 +10,11 @@ module EmptyEye
|
|
10
10
|
end
|
11
11
|
|
12
12
|
#the instance that owns this primary shard
|
13
|
+
#we usually know the master instance ahead of time
|
14
|
+
#so we should take care to set this manually
|
15
|
+
#we want to avoid the lookup
|
13
16
|
def mti_instance
|
14
|
-
@mti_instance
|
17
|
+
@mti_instance || mti_master_class.find_by_id(id)
|
15
18
|
end
|
16
19
|
|
17
20
|
#setter used to associate the primary shard with the master instance
|
@@ -72,7 +75,7 @@ module EmptyEye
|
|
72
75
|
reflection
|
73
76
|
end
|
74
77
|
|
75
|
-
#finder methods should use the master
|
78
|
+
#finder methods should use the master class's type not the shard's
|
76
79
|
def type_condition(table = arel_table)
|
77
80
|
sti_column = table[inheritance_column.to_sym]
|
78
81
|
|
data/lib/empty_eye/version.rb
CHANGED
@@ -79,7 +79,7 @@ module EmptyEye
|
|
79
79
|
query.where(primary.type_column.eq(primary.type_value))
|
80
80
|
end
|
81
81
|
|
82
|
-
#build
|
82
|
+
#build view creation statement
|
83
83
|
"CREATE VIEW #{parent.table_name} AS\n#{query.to_sql}"
|
84
84
|
end
|
85
85
|
|
@@ -123,6 +123,11 @@ module EmptyEye
|
|
123
123
|
super
|
124
124
|
end
|
125
125
|
end
|
126
|
+
|
127
|
+
#we dont need to keep this data
|
128
|
+
def free_validations
|
129
|
+
@validations = nil
|
130
|
+
end
|
126
131
|
|
127
132
|
private
|
128
133
|
|
metadata
CHANGED