Module: Zena::Use::Kpath::InstanceMethods
- Included in:
- Node
- Defined in:
- lib/zena/use/kpath.rb
Overview
ClassMethods
Class Method Summary collapse
Class Method Details
.included(base) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/zena/use/kpath.rb', line 17 def self.included(base) base.class_eval do extend ClassMethods before_validation :set_kpath end class << base # The kpath must be set in the class's metaclass so that each sub-class has its own # @kpath. # kpath is a class shortcut to avoid tons of 'OR type = Page OR type = Document' # we build this path with the first letter of each class. The example bellow # shows how the kpath is built: # class hierarchy # Node --> N # Note --> NN Page --> NP # Document Form Section # NPD NPF NPP # So now, to get all Pages, your sql becomes : WHERE kpath LIKE 'NP%' # to get all Documents : WHERE kpath LIKE 'NPD%' # all pages without Documents : WHERE kpath LIKE 'NP%' AND NOT LIKE 'NPD%' attr_accessor :kpath def kpath @kpath ||= make_kpath end private def make_kpath superclass.respond_to?(:kpath) ? (superclass.kpath + ksel) : ksel end end end |