Module: Zena::Use::ScopeIndex::ModelMethods
- Included in:
- Node
- Defined in:
- lib/zena/use/scope_index.rb
Overview
IndexMethods
Class Method Summary collapse
Instance Method Summary collapse
-
#rebuild_index_with_scope_index! ⇒ Object
Rebuild ‘remote’ indexes based on changes in this node.
-
#rebuild_scope_index! ⇒ Object
Trigger ‘rebuild_index!’ in all elements that could affect this model’s scope index.
-
#scope_index ⇒ Object
Access the index model inside the Project or Section.
Class Method Details
.included(base) ⇒ Object
167 168 169 170 171 172 |
# File 'lib/zena/use/scope_index.rb', line 167 def self.included(base) base.after_save :update_scope_indices base.after_destroy :update_scope_indices_on_destroy base.safe_context :scope_index => scope_index_proc base.alias_method_chain :rebuild_index!, :scope_index end |
.scope_index_proc ⇒ Object
174 175 176 177 178 179 180 181 182 |
# File 'lib/zena/use/scope_index.rb', line 174 def self.scope_index_proc Proc.new do |helper, receiver, signature| if receiver.respond_to?('idx_class') && receiver.idx_class && klass = Zena.resolve_const(receiver.idx_class) rescue nil {:method => 'scope_index', :nil => true, :class => klass} else raise RubyLess::NoMethodError.new(receiver, receiver, signature) end end end |
Instance Method Details
#rebuild_index_with_scope_index! ⇒ Object
Rebuild ‘remote’ indexes based on changes in this node.
185 186 187 188 |
# File 'lib/zena/use/scope_index.rb', line 185 def rebuild_index_with_scope_index! rebuild_index_without_scope_index! update_scope_indices end |
#rebuild_scope_index! ⇒ Object
Trigger ‘rebuild_index!’ in all elements that could affect this model’s scope index.
208 209 210 211 212 213 214 215 216 217 218 219 |
# File 'lib/zena/use/scope_index.rb', line 208 def rebuild_scope_index! if vclass && query = vclass.idx_reverse_scope if nodes = find(:all, query) nodes.each do |node| node.rebuild_index! end end else nil end end |
#scope_index ⇒ Object
Access the index model inside the Project or Section.
191 192 193 194 195 196 197 198 199 200 201 202 203 204 |
# File 'lib/zena/use/scope_index.rb', line 191 def scope_index @scope_index ||= begin vclass = virtual_class if vclass && klass = vclass.idx_class if klass = Zena.resolve_const(klass) rescue nil klass.find(:first, :conditions => {:node_id => self.id, :site_id => current_site.id}) || klass.new(:node_id => self.id) else nil end else nil end end end |