Class: ActiveRecord::Relation
- Inherits:
-
Object
- Object
- ActiveRecord::Relation
- Defined in:
- lib/cached_enumeration/cached_enumeration.rb
Instance Method Summary collapse
Instance Method Details
#take_with_cache_enumeration ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 |
# File 'lib/cached_enumeration/cached_enumeration.rb', line 213 def take_with_cache_enumeration if cache_enumeration? && cache_enumeration.cached? case #when just_modified?(:limit) # cache_enumeration.first #tsk the first value of the default order when just_modified?(:where) && where_is_cached? get_by_where else take_without_cache_enumeration end else cache_enumeration.cache! if cache_enumeration? take_without_cache_enumeration end end |
#to_a_with_cache_enumeration ⇒ Object
176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 |
# File 'lib/cached_enumeration/cached_enumeration.rb', line 176 def to_a_with_cache_enumeration res=nil if cache_enumeration? && cache_enumeration.cached? && order_is_cached? res=case when just_modified?(:order) #all and the order is cached? cache_enumeration.all when just_modified?(:limit, :order, :where) case when limit_value == 1 && where_values.blank? # usually the #first case [cache_enumeration.first] when limit_value == 1 && where_values.present? && where_is_cached? # usually "= 1" or "= ?" .first or find or find_by [get_by_where] when limit_value.blank? && where_values.present? && where_is_cached? # usually the association case (where id in (1,2,56,6)) get_by_where else to_a_without_cache_enumeration #where is to complicated for us end end end if res #got a result the return it res else cache_enumeration.cache! if cache_enumeration? to_a_without_cache_enumeration end end |