Module: HasHierarchy::Path
- Extended by:
- ActiveSupport::Concern
- Defined in:
- lib/has_hierarchy/path.rb
Defined Under Namespace
Modules: ClassMethods
Instance Method Summary collapse
- #ancestor_of?(node) ⇒ Boolean
- #depth ⇒ Object
- #descendant_of?(node) ⇒ Boolean
- #full_path ⇒ Object
- #path ⇒ Object
- #path=(path) ⇒ Object
- #root ⇒ Object
- #root_of?(node) ⇒ Boolean
Instance Method Details
#ancestor_of?(node) ⇒ Boolean
34 35 36 |
# File 'lib/has_hierarchy/path.rb', line 34 def ancestor_of?(node) node.path_parts.include?(path_part) end |
#depth ⇒ Object
42 43 44 |
# File 'lib/has_hierarchy/path.rb', line 42 def depth path_parts.size end |
#descendant_of?(node) ⇒ Boolean
38 39 40 |
# File 'lib/has_hierarchy/path.rb', line 38 def descendant_of?(node) path_parts.include?(node.path_part) end |
#full_path ⇒ Object
54 55 56 |
# File 'lib/has_hierarchy/path.rb', line 54 def full_path path + path_part end |
#path ⇒ Object
46 47 48 |
# File 'lib/has_hierarchy/path.rb', line 46 def path self[path_column] end |
#path=(path) ⇒ Object
50 51 52 |
# File 'lib/has_hierarchy/path.rb', line 50 def path=(path) self[path_column] = path end |
#root ⇒ Object
24 25 26 27 28 |
# File 'lib/has_hierarchy/path.rb', line 24 def root if root_part = path_parts.first self.class.find_by(path_part_column => root_part) end end |
#root_of?(node) ⇒ Boolean
30 31 32 |
# File 'lib/has_hierarchy/path.rb', line 30 def root_of?(node) node.path_parts.first == path_part if path_part.present? end |