module Oid::Relationships(T)
Direct including types
Defined in:
oid/core/relationships.crInstance Method Summary
-
#_parent=(parent : T)
Set the parent
-
#add_child(child : T)
Add provided object as a child and set
self
as parent to object -
#child_of?(parent : T) : Bool
Is this object a child of parent?
-
#children? : Bool
Check if children are present
-
#children_count
Returns the total count of children
- #clear_on_child_added_hooks
-
#clear_parent!
Removes parent from
self
-
#delete_child(child : T)
Removes child from
self
-
#each_child(&block : T -> Nil)
Yields each
T
child to provided block - #get_child(kind)
-
#has_child?(child : T) : Bool
Returns a
Bool
value that indicates whether the object is a direct child ofself
. -
#has_parent?(parent : T) : Bool
Returns a
Bool
value that indicates whether the object is a direct parent ofself
. - #on_child_added(&block : T, T -> Nil)
- #parent : T
-
#parent? : Bool
Check if parent is set
-
#parent_of?(child : T) : Bool
Is this object a parent of child?
- #related?(other : T)
-
#relationship_to(other : T)
Will return a symbol of the relationship of
self
toother
. - #remove_on_child_added_hook(hook : Proc(T, T, Nil))
-
#root : T
Returns the top-most parent of the objects relationships
Instance Method Detail
Is this object a child of parent?
Returns a Bool
value that indicates whether the object is a child of a given object.
true if this object is a child, deep child (child of a child) or identical to self
,
otherwise false.
Returns a Bool
value that indicates whether the object is a direct child of self
.
Returns a Bool
value that indicates whether the object is a direct parent of self
.
Is this object a parent of child?
Returns a Bool
value that indicates whether the object is a parent of a given object.
true if this object is a parent, deep parent (parent of a parent) or identical to self
,
otherwise false.
Will return a symbol of the relationship of self
to other
.
Will return :parent
if other
is a child of self.
Will return :child
if other
is a parent of self.
Will return :none
if there is no relationship.
class RelTestObj
include Oid::Helpers::Relationships(RelTestObj)
end
parent = RelTestObj.new
child = RelTestObj.new
orphan = RelTestObj.new
parent.add_child(child)
parent.relationship_to(child) # => :parent
child.relationship_to(parent) # => :child
parent.relationship_to(orphan) # => :none
child.relationship_to(orphan) # => :none