module Oid::Relationships(T)

Direct including types

Defined in:

oid/core/relationships.cr

Instance Method Summary

Instance Method Detail

def _parent=(parent : T) #

Set the parent


[View source]
def add_child(child : T) #

Add provided object as a child and set self as parent to object


[View source]
def child_of?(parent : T) : Bool #

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.


[View source]
def children? : Bool #

Check if children are present


[View source]
def children_count #

Returns the total count of children


[View source]
def clear_on_child_added_hooks #

[View source]
def clear_parent! #

Removes parent from self


[View source]
def delete_child(child : T) #

Removes child from self


[View source]
def each_child(&block : T -> Nil) #

Yields each T child to provided block


[View source]
def get_child(kind) #

[View source]
def has_child?(child : T) : Bool #

Returns a Bool value that indicates whether the object is a direct child of self.


[View source]
def has_parent?(parent : T) : Bool #

Returns a Bool value that indicates whether the object is a direct parent of self.


[View source]
def on_child_added(&block : T, T -> Nil) #

[View source]
def parent : T #

[View source]
def parent? : Bool #

Check if parent is set


[View source]
def parent_of?(child : T) : Bool #

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.


[View source]
def related?(other : T) #

[View source]
def relationship_to(other : T) #

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

[View source]
def remove_on_child_added_hook(hook : Proc(T, T, Nil)) #

[View source]
def root : T #

Returns the top-most parent of the objects relationships


[View source]