Module: RecursiveTreeScopes::ModelMixin
- Defined in:
- lib/activerecord-recursive_tree_scopes.rb
Instance Method Summary collapse
- #has_ancestors(ancestors_name = :ancestors, options = {}) ⇒ Object
- #has_descendants(descendants_name = :descendants, options = {}) ⇒ Object
Instance Method Details
#has_ancestors(ancestors_name = :ancestors, options = {}) ⇒ Object
3 4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/activerecord-recursive_tree_scopes.rb', line 3 def has_ancestors(ancestors_name = :ancestors, = {}) [:key] ||= :parent_id scope ancestors_name, lambda{ |record| RecursiveTreeScopes::Scopes.ancestors_for(record, [:key]) } class_eval <<-EOF def #{ancestors_name} self.class.#{ancestors_name}(self) end EOF end |
#has_descendants(descendants_name = :descendants, options = {}) ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/activerecord-recursive_tree_scopes.rb', line 17 def has_descendants(descendants_name = :descendants, = {}) [:key] ||= :parent_id scope descendants_name, lambda{ |record| RecursiveTreeScopes::Scopes.descendants_for(record, [:key]) } class_eval <<-EOF def #{descendants_name} self.class.#{descendants_name}(self) end EOF end |