flagpole_sitta 0.8.0 → 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -2
- data/app/helpers/flagpole_sitta_helper.rb +9 -11
- data/lib/flagpole_sitta/cache_sitta.rb +50 -5
- data/lib/flagpole_sitta/existence_hash.rb +31 -12
- data/lib/flagpole_sitta/version.rb +1 -1
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -12,7 +12,7 @@ The rottenness and evil in me.
|
|
12
12
|
|
13
13
|
== Preface
|
14
14
|
|
15
|
-
===This gem should be considered in
|
15
|
+
===This gem should be considered in beta.
|
16
16
|
|
17
17
|
This gem was inspired in part by the song Flagpole Sitta by Harvey Danger. So if you like the gem and are wanting to help out please either donate your time and submit some patches, or donate to the band who wrote the song. They put there last two albums out there all open source like, only asking that those that could donate after downloading. While your donating, if you choose to do so, don't be afraid to download their albums, its good stuff!
|
18
18
|
|
@@ -221,7 +221,7 @@ Also if for what ever reason you have made your app multi threaded this gem will
|
|
221
221
|
|
222
222
|
http://stackoverflow.com/a/1390978/1436131
|
223
223
|
|
224
|
-
===This gem should be considered in
|
224
|
+
===This gem should be considered in beta.
|
225
225
|
|
226
226
|
MIT License
|
227
227
|
|
@@ -108,18 +108,14 @@ module FlagpoleSittaHelper
|
|
108
108
|
"@" + (options[:section] ? options[:section] : 'body') + "_calls"
|
109
109
|
)
|
110
110
|
|
111
|
-
if
|
112
|
-
|
111
|
+
if hash = Rails.cache.read(key)
|
112
|
+
content = hash[:content]
|
113
113
|
else
|
114
114
|
#NOTE This is not safe for .builder xml files, and using capture here is why.
|
115
115
|
#Its either this or a really complicated hack, from the rails source code, which
|
116
116
|
#at the moment I don't feel comfortable using. Waiting for an official solution for
|
117
117
|
#the ability to use capture with .builders.
|
118
118
|
content = capture do
|
119
|
-
#AR - If call_path is an array render each one, other
|
120
|
-
#wise just render call_path, because it must
|
121
|
-
#be a string or array by this point or something went
|
122
|
-
#terribly terribly wrong.
|
123
119
|
|
124
120
|
if calls
|
125
121
|
calls.each do |c|
|
@@ -141,6 +137,8 @@ module FlagpoleSittaHelper
|
|
141
137
|
#that while its not an index, there isn't a clear way expect to nuke it when
|
142
138
|
#any of the model types involved are updated.
|
143
139
|
|
140
|
+
associated = Array.new
|
141
|
+
|
144
142
|
if options[:models_in_index].class.eql?(Array)
|
145
143
|
options[:models_in_index].each_index do |i|
|
146
144
|
m = options[:models_in_index][i]
|
@@ -148,11 +146,11 @@ module FlagpoleSittaHelper
|
|
148
146
|
scope = options[:scope][i]
|
149
147
|
end
|
150
148
|
processed_model = m.respond_to?(:constantize) ? m.constantize : m
|
151
|
-
update_index_array_cache(processed_model, key, scope)
|
149
|
+
associated << update_index_array_cache(processed_model, key, scope)
|
152
150
|
end
|
153
151
|
elsif options[:models_in_index]
|
154
152
|
processed_model = options[:models_in_index].respond_to?(:constantize) ? options[:models_in_index].constantize : options[:models_in_index]
|
155
|
-
update_index_array_cache(processed_model, key, options[:scope])
|
153
|
+
associated << update_index_array_cache(processed_model, key, options[:scope])
|
156
154
|
end
|
157
155
|
|
158
156
|
#AR - Create a link between each declared object and the cache.
|
@@ -160,14 +158,14 @@ module FlagpoleSittaHelper
|
|
160
158
|
if !options[:index_only] && options[:route_id]
|
161
159
|
if options[:route_id].class.eql?(Array) && options[:model].class.eql?(Array)
|
162
160
|
options[:model].each_index do |i|
|
163
|
-
update_show_array_cache(options[:model][i], key, options[:route_id][i])
|
161
|
+
associated << update_show_array_cache(options[:model][i], key, options[:route_id][i])
|
164
162
|
end
|
165
163
|
else
|
166
|
-
update_show_array_cache(main_model, key, main_route_id)
|
164
|
+
associated << update_show_array_cache(main_model, key, main_route_id)
|
167
165
|
end
|
168
166
|
end
|
169
167
|
|
170
|
-
Rails.cache.write(key, content)
|
168
|
+
Rails.cache.write(key, {:content => content, :associated => associated})
|
171
169
|
|
172
170
|
end
|
173
171
|
|
@@ -32,7 +32,7 @@ module FlagpoleSitta
|
|
32
32
|
|
33
33
|
clazz = self
|
34
34
|
|
35
|
-
flag = {:space => - 1}
|
35
|
+
flag = {:space => -1, :empty => -1}
|
36
36
|
|
37
37
|
Rails.cache.write("#{clazz}/#{mid_key}/Flag", flag)
|
38
38
|
|
@@ -54,15 +54,27 @@ module FlagpoleSitta
|
|
54
54
|
flag = initialize_array_cache options[:route_id]
|
55
55
|
end
|
56
56
|
|
57
|
-
|
58
|
-
|
57
|
+
if flag[:empty] > -1
|
58
|
+
#Find any empty container to use by popping it off of the top of the "stack".
|
59
|
+
i = Rails.cache.read("#{clazz}/#{mid_key}/EmptyStack/#{flag[:empty]}")
|
60
|
+
#Sense its going to be used remove its reference from the Stack.
|
61
|
+
Rails.cache.delete("#{clazz}/#{mid_key}/EmptyStack/#{flag[:empty]}")
|
62
|
+
#Update the empty on flag to now hit the newest none used container on the stack.
|
63
|
+
flag[:empty] = flag[:empty] - 1
|
64
|
+
else
|
65
|
+
#AR - update the array's end point
|
66
|
+
flag[:space] = flag[:space] + 1
|
67
|
+
i = flag[:space]
|
68
|
+
end
|
59
69
|
|
60
70
|
#AR - write out the new index at the end of the array
|
61
|
-
Rails.cache.write("#{clazz}/#{mid_key}/#{
|
71
|
+
Rails.cache.write("#{clazz}/#{mid_key}/#{i}", {:key => key, :scope => options[:scope]})
|
62
72
|
|
63
73
|
#AR - update flag in the cache
|
64
74
|
Rails.cache.write("#{clazz}/#{mid_key}/Flag", flag)
|
65
75
|
|
76
|
+
"#{clazz}/#{mid_key}/#{i}"
|
77
|
+
|
66
78
|
end
|
67
79
|
|
68
80
|
#Loops through the array in the cache.
|
@@ -100,9 +112,37 @@ module FlagpoleSitta
|
|
100
112
|
i = 0
|
101
113
|
|
102
114
|
each_cache options[:route_id] do |hash|
|
115
|
+
#A Check in Case there is some type of cache failure
|
103
116
|
if hash.present?
|
117
|
+
#If it has no scope, or it falls in scope
|
104
118
|
if hash[:scope].nil? || options[:obj].in_scope(hash[:scope])
|
119
|
+
#Get all the associated.
|
120
|
+
associated = Rails.cache.read(hash[:key])[:associated]
|
121
|
+
#Destroy the actually cache
|
105
122
|
Rails.cache.delete(hash[:key])
|
123
|
+
associated.each do |a|
|
124
|
+
#Get the base key
|
125
|
+
base_key = a.gsub(/\/[^\/]*\z/, "")
|
126
|
+
#Get the flag. Capture the god damn flag!
|
127
|
+
flag_key = base_key + "/Flag"
|
128
|
+
#Get its location in the 'Array'
|
129
|
+
n = a.split("/").last
|
130
|
+
# Check in case of cache failure
|
131
|
+
if flag = Rails.cache.read(flag_key)
|
132
|
+
#Add an empty spot to the 'Array'
|
133
|
+
flag[:empty] = flag[:empty] + 1
|
134
|
+
empty_stack_key = base_key + "/EmptyStack/" + flag[:empty].to_s
|
135
|
+
#Save the empty spot location to the 'Stack'
|
136
|
+
Rails.cache.write(empty_stack_key, n)
|
137
|
+
#Update the flag
|
138
|
+
Rails.cache.write(flag_key, flag)
|
139
|
+
end
|
140
|
+
|
141
|
+
#Finally get rid of the associated cache object.
|
142
|
+
Rails.cache.delete(a)
|
143
|
+
|
144
|
+
end
|
145
|
+
#Else It is not in scope so the cache lives to fight another day!
|
106
146
|
else
|
107
147
|
Rails.cache.write("#{clazz}/#{mid_key}/#{i}", hash)
|
108
148
|
i = i + 1
|
@@ -110,11 +150,16 @@ module FlagpoleSitta
|
|
110
150
|
end
|
111
151
|
end
|
112
152
|
|
153
|
+
#If everything was deleted destroy the flag.
|
113
154
|
if i == 0
|
114
155
|
Rails.cache.delete("#{clazz}/#{mid_key}/Flag")
|
156
|
+
#Else update the flag
|
115
157
|
else
|
116
158
|
flag = Rails.cache.read("#{clazz}/#{mid_key}/Flag")
|
117
|
-
flag[:space
|
159
|
+
flag[:space] = (i - 1)
|
160
|
+
#Sense we moved through every object and moved all the remaining objects down
|
161
|
+
#there should be no empty spaces.
|
162
|
+
flag[:empty] = -1
|
118
163
|
Rails.cache.write("#{clazz}/#{mid_key}/Flag", flag)
|
119
164
|
end
|
120
165
|
end
|
@@ -21,13 +21,13 @@ module FlagpoleSitta
|
|
21
21
|
#the 'container' goes, it starts at 0, so thats why 1 is subtracted. The count is well the count. They should start out the same.
|
22
22
|
count = superclazz.count
|
23
23
|
|
24
|
-
flag = {:space => (count - 1), :count => count}
|
24
|
+
flag = {:space => (count - 1), :count => count, :empty => -1}
|
25
25
|
|
26
26
|
Rails.cache.write("#{superclazz}/ExistenceHash/Flag", flag)
|
27
27
|
i = 0
|
28
28
|
superclazz.find_each do |m|
|
29
29
|
#Route ID is the key. The POS is used to emulate an array, along with the length stored in the flag.
|
30
|
-
Rails.cache.write("#{superclazz}/ExistenceHash/#{m.class}/#{m.send(m.class.route_id).to_s}", {:type => m.has_attribute?('type') ? m.type : m.class, :pos => i, :num => 0})
|
30
|
+
Rails.cache.write("#{superclazz}/ExistenceHash/#{m.class}/#{m.send(m.class.route_id).to_s}", {:type => m.has_attribute?('type') ? m.type : m.class, :pos => i, :num => m.has_attribute?('num') ? m.num : 0})
|
31
31
|
Rails.cache.write("#{superclazz}/ExistenceHash/#{i}", {:key => m.send(m.class.route_id).to_s, :type => m.class})
|
32
32
|
i = i + 1
|
33
33
|
end
|
@@ -135,7 +135,11 @@ module FlagpoleSitta
|
|
135
135
|
|
136
136
|
#Updates the 'hash' on save of any of its records.
|
137
137
|
def update_existence_hash alive
|
138
|
-
|
138
|
+
#Get the Current Class and the Old Class in case the object changed classes.
|
139
|
+
#If its the base object, ie type is nil, then return class as the old_clazz.
|
140
|
+
#If the object doesn't have the type field assume it can't change classes.
|
141
|
+
new_clazz = self.has_attribute?('type') ? (self.type || self.class) : self.class
|
142
|
+
old_clazz = self.has_attribute?('type') ? (self.type_was || self.class) : self.class
|
139
143
|
superclazz = self.class.get_super_with_existence_hash
|
140
144
|
|
141
145
|
#Old key is where it was, and new is where it is going.
|
@@ -147,28 +151,43 @@ module FlagpoleSitta
|
|
147
151
|
if flag.nil?
|
148
152
|
flag = self.class.initialize_existence_hash
|
149
153
|
end
|
150
|
-
|
151
|
-
#If it had a route_id before it most of existed. So get its old values from the existence hash.
|
152
|
-
#If there was nothing it didn't exist so create a new one. Also it only creates a new one if alive is set to true.
|
153
|
-
#This check is overkill really, but its just to be safe.
|
154
154
|
|
155
|
+
#If its a new record add it to the 'hash'
|
155
156
|
if self.new_record?
|
156
157
|
flag[:count] = flag[:count] + 1
|
157
|
-
|
158
|
-
|
158
|
+
#if there are empty containers use them
|
159
|
+
if flag[:empty] > -1
|
160
|
+
#Find any empty container to use by popping it off of the top of the "stack".
|
161
|
+
i = Rails.cache.read("#{superclazz}/ExistenceHash/EmptyStack/#{flag[:empty]}")
|
162
|
+
#Sense its going to be used remove its reference from the Stack.
|
163
|
+
Rails.cache.delete("#{superclazz}/ExistenceHash/EmptyStack/#{flag[:empty]}")
|
164
|
+
#Update the empty on flag to now hit the newest none used container on the stack.
|
165
|
+
flag[:empty] = flag[:empty] - 1
|
166
|
+
#Else add a space to the end.
|
167
|
+
else
|
168
|
+
#AR - update the array's end point
|
169
|
+
flag[:space] = flag[:space] + 1
|
170
|
+
i = flag[:space]
|
171
|
+
end
|
172
|
+
hash = {:type => self.has_attribute?('type') ? self.type : self.class, :num => self.has_attribute?('num') ? self.num : 0, :pos => i}
|
173
|
+
#If its an already existing record them get its existence hash, and then remove it from the cache.
|
159
174
|
else
|
160
175
|
hash = self.class.get_existence_hash(self.send("#{self.class.route_id}_was"))
|
161
|
-
|
176
|
+
hash[:type] = new_clazz
|
177
|
+
Rails.cache.delete("#{superclazz}/ExistenceHash/#{old_clazz}/#{old_key}")
|
162
178
|
end
|
163
179
|
|
164
180
|
#If the record is not being destroyed add new route_id to existence hash
|
165
181
|
if alive
|
166
|
-
Rails.cache.write("#{superclazz}/ExistenceHash/#{
|
167
|
-
Rails.cache.write("#{superclazz}/ExistenceHash/#{hash[:pos]}", {:key => new_key, :type =>
|
182
|
+
Rails.cache.write("#{superclazz}/ExistenceHash/#{new_clazz}/#{new_key}", hash)
|
183
|
+
Rails.cache.write("#{superclazz}/ExistenceHash/#{hash[:pos]}", {:key => new_key, :type => new_clazz})
|
168
184
|
#The following check is needed if for some reason someone does destroy on a none saved record.
|
169
185
|
elsif !self.new_record?
|
170
186
|
if hash[:pos] == flag[:space]
|
171
187
|
flag[:space] = flag[:space] - 1
|
188
|
+
else
|
189
|
+
flag[:empty] = flag[:empty] + 1
|
190
|
+
Rails.cache.write("#{superclazz}/ExistenceHash/EmptyStack/#{flag[:empty]}", hash[:pos])
|
172
191
|
end
|
173
192
|
flag[:count] = flag[:count] - 1
|
174
193
|
Rails.cache.delete("#{superclazz}/ExistenceHash/#{hash[:pos]}")
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: flagpole_sitta
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.9.0
|
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-
|
12
|
+
date: 2012-08-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: dalli
|