module StewEucen::Acts::FertileForest::Entity

Instance methods to include into derived class by ActiveRecord.

@author StewEucen @example Include into ActiveRecord class.

ActiveRecord::Base.send :include, StewEucen::Acts::FertileForest::Entity

@since Release 1.0.0

Public Instance Methods

ancestors(columns = nil) click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 155
def ancestors(columns = nil)
  self.class.ancestors(self, columns)
end
children(columns = nil) click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 179
def children(columns = nil)
  self.class.children(self, columns)
end
cousins(columns = nil) click to toggle source

@since 1.1.0

# File lib/fertile_forest/modules/entities.rb, line 205
def cousins(columns = nil)
  self.class.cousins(self, columns)
end
descendants(columns = nil) click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 175
def descendants(columns = nil)
  self.class.descendants(self, columns)
end
elder_sibling(columns = nil) click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 223
def elder_sibling(columns = nil)
  self.class.elder_sibling(self, columns)
end
genitor(columns = nil) click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 159
def genitor(columns = nil)
  self.class.genitor(self, columns)
end
grandchildren(columns = nil) click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 187
def grandchildren(columns = nil)
  self.class.grandchildren(self, columns)
end
grandparent(columns = nil) click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 167
def grandparent(columns = nil)
  self.class.grandparent(self, columns)
end
height() click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 243
def height
  self.class.height(self)
end
internals(columns = nil) click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 239
def internals(columns = nil)
  self.class.internals(self, columns)
end
kinships( next_branch = KINSHIPS_AS_SIBLING, level_offset = KINSHIPS_SAME_LEVEL, columns = nil ) click to toggle source

@since 1.1.0

# File lib/fertile_forest/modules/entities.rb, line 192
def kinships(
  next_branch = KINSHIPS_AS_SIBLING,
  level_offset = KINSHIPS_SAME_LEVEL,
  columns = nil
)
  self.class.kinships(self, next_branch, level_offset, columns)
end
leaves(columns = nil) click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 235
def leaves(columns = nil)
  self.class.leaves(self, columns)
end
nest_child_ids() click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 109
def nest_child_ids
  ff_get_options[:children].keys
end
nest_child_nodes() click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 101
def nest_child_nodes
  ff_get_options[:children]
end
Also aliased as: nest_children
nest_children()
Alias for: nest_child_nodes
nest_genitor()
Alias for: nest_parent_node
nest_leaf?() click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 141
def nest_leaf?
  ff_get_options[:children].blank?
end
nest_parent()
Alias for: nest_parent_node
nest_parent?() click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 145
def nest_parent?
  !nest_leaf?
end
nest_parent_id() click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 105
def nest_parent_id
  ff_get_options[:parent].keys.first
end
nest_parent_node() click to toggle source

accessors

# File lib/fertile_forest/modules/entities.rb, line 97
def nest_parent_node
  ff_get_options[:parent].values.first
end
Also aliased as: nest_parent, nest_genitor
nest_set_child_id(aim_id) click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 123
def nest_set_child_id(aim_id)
  ff_get_options[:children][aim_id] = nil
end
nest_set_child_node(aim_id, node) click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 134
def nest_set_child_node(aim_id, node)
  ff_get_options[:children][aim_id] = node \
      if aim_id.present? && node.present?
end
nest_set_parent_id(aim_id) click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 119
def nest_set_parent_id(aim_id)
  ff_get_options[:parent] = {aim_id => nil}  # always overwrite
end
nest_set_parent_node(aim_id, node) click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 129
def nest_set_parent_node(aim_id, node)
  ff_get_options[:parent] = {aim_id => node} \
      if aim_id.present? && node.present?
end
nest_unset_children(id = nil) click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 82
def nest_unset_children(id = nil)
  if id.blank?
    ff_get_options[:children] = {}
  else
    ff_get_options[:children][id] = nil
  end
end
nest_unset_parent() click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 78
def nest_unset_parent
  ff_get_options[:parent] = {0 => nil}
end
niblings(columns = nil) click to toggle source

@since 1.1.0

# File lib/fertile_forest/modules/entities.rb, line 210
def niblings(columns = nil)
  self.class.niblings(self, columns)
end
nth_child(nth = 0, columns = nil) click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 183
def nth_child(nth = 0, columns = nil)
  self.class.nth_child(self, nth, columns)
end
nth_sibling(nth = 0, columns = nil) click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 219
def nth_sibling(nth = 0, columns = nil)
  self.class.nth_sibling(self, nth, columns)
end
offset_sibling(offset, columns = nil) click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 231
def offset_sibling(offset, columns = nil)
  self.class.offset_sibling(self, offset, columns)
end
piblings(columns = nil) click to toggle source

@since 1.1.0

# File lib/fertile_forest/modules/entities.rb, line 215
def piblings(columns = nil)
  self.class.piblings(self, columns)
end
root(columns = nil) click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 163
def root(columns = nil)
  self.class.root(self, columns)
end
siblings(columns = nil) click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 200
def siblings(columns = nil)
  self.class.siblings(self, columns)
end
size() click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 247
def size
  self.class.size(self)
end
subtree(range = DESCENDANTS_ALL, with_top = true, columns = nil) click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 171
def subtree(range = DESCENDANTS_ALL, with_top = true, columns = nil)
  self.class.subtree(self, range, with_top, columns)
end
trunk(range = ANCESTOR_ALL, columns = nil) click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 151
def trunk(range = ANCESTOR_ALL, columns = nil)
  self.class.trunk(self, range, columns)
end
younger_sibling(columns = nil) click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 227
def younger_sibling(columns = nil)
  self.class.younger_sibling(self, columns)
end

Protected Instance Methods

ff_after_save() click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 54
def ff_after_save
end
ff_before_create() click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 51
def ff_before_create
end
ff_before_destroy() click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 57
def ff_before_destroy
end
ff_before_save() click to toggle source

Before save listener (must be an instance methoed). Transparently manages setting the required fields for FertileForestBehavior if the parent field is included in the parameters to be saved.

@return boolean true:Continue to save./false:Abort to save.

# File lib/fertile_forest/modules/entities.rb, line 34
def ff_before_save
  # when not new record, to update.
  # no need to set ff_columns (id, grove, queue, depth)
  return true unless new_record?

  if self.class.has_grove?
    posted_grove = self.ff_grove
    if posted_grove.blank?
      # TODO: set_error
      return false
    end
  end

  # return value
  self.class.fill_required_columns_to_append!(self)
end
ff_get_options() click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 74
def ff_get_options
  @fertile_forest ||= ff_reset_values
end
ff_reset_values() click to toggle source
# File lib/fertile_forest/modules/entities.rb, line 67
def ff_reset_values
  {
      parent: {0 => nil},
    children: {},
  }
end