Module: StewEucen::Acts::FertileForest::Entity

Defined in:
lib/fertile_forest/modules/entities.rb

Overview

Instance methods to include into derived class by ActiveRecord.

Examples:

Include into ActiveRecord class.

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

Author:

  • StewEucen

Since:

  • Release 1.0.0

Instance Method Summary collapse

Instance Method Details

#ancestors(columns = nil) ⇒ Object

Since:

  • Release 1.0.0



155
156
157
# File 'lib/fertile_forest/modules/entities.rb', line 155

def ancestors(columns = nil)
  self.class.ancestors(self, columns)
end

#children(columns = nil) ⇒ Object

Since:

  • Release 1.0.0



179
180
181
# File 'lib/fertile_forest/modules/entities.rb', line 179

def children(columns = nil)
  self.class.children(self, columns)
end

#descendants(columns = nil) ⇒ Object

Since:

  • Release 1.0.0



175
176
177
# File 'lib/fertile_forest/modules/entities.rb', line 175

def descendants(columns = nil)
  self.class.descendants(self, columns)
end

#elder_sibling(columns = nil) ⇒ Object

Since:

  • Release 1.0.0



199
200
201
# File 'lib/fertile_forest/modules/entities.rb', line 199

def elder_sibling(columns = nil)
  self.class.elder_sibling(self, columns)
end

#genitor(columns = nil) ⇒ Object

Since:

  • Release 1.0.0



159
160
161
# File 'lib/fertile_forest/modules/entities.rb', line 159

def genitor(columns = nil)
  self.class.genitor(self, columns)
end

#grandchildren(columns = nil) ⇒ Object

Since:

  • Release 1.0.0



187
188
189
# File 'lib/fertile_forest/modules/entities.rb', line 187

def grandchildren(columns = nil)
  self.class.grandchildren(self, columns)
end

#grandparent(columns = nil) ⇒ Object

Since:

  • Release 1.0.0



167
168
169
# File 'lib/fertile_forest/modules/entities.rb', line 167

def grandparent(columns = nil)
  self.class.grandparent(self, columns)
end

#heightObject

Since:

  • Release 1.0.0



219
220
221
# File 'lib/fertile_forest/modules/entities.rb', line 219

def height
  self.class.height(self)
end

#internals(columns = nil) ⇒ Object

Since:

  • Release 1.0.0



215
216
217
# File 'lib/fertile_forest/modules/entities.rb', line 215

def internals(columns = nil)
  self.class.internals(self, columns)
end

#leaves(columns = nil) ⇒ Object

Since:

  • Release 1.0.0



211
212
213
# File 'lib/fertile_forest/modules/entities.rb', line 211

def leaves(columns = nil)
  self.class.leaves(self, columns)
end

#nest_child_idsObject

Since:

  • Release 1.0.0



109
110
111
# File 'lib/fertile_forest/modules/entities.rb', line 109

def nest_child_ids
  ff_get_options[:children].keys
end

#nest_child_nodesObject Also known as: nest_children

Since:

  • Release 1.0.0



101
102
103
# File 'lib/fertile_forest/modules/entities.rb', line 101

def nest_child_nodes
  ff_get_options[:children]
end

#nest_leaf?Boolean

Returns:

  • (Boolean)

Since:

  • Release 1.0.0



141
142
143
# File 'lib/fertile_forest/modules/entities.rb', line 141

def nest_leaf?
  ff_get_options[:children].blank?
end

#nest_parent?Boolean

Returns:

  • (Boolean)

Since:

  • Release 1.0.0



145
146
147
# File 'lib/fertile_forest/modules/entities.rb', line 145

def nest_parent?
  !nest_leaf?
end

#nest_parent_idObject

Since:

  • Release 1.0.0



105
106
107
# File 'lib/fertile_forest/modules/entities.rb', line 105

def nest_parent_id
  ff_get_options[:parent].keys.first
end

#nest_parent_nodeObject Also known as: nest_parent, nest_genitor

accessors

Since:

  • Release 1.0.0



97
98
99
# File 'lib/fertile_forest/modules/entities.rb', line 97

def nest_parent_node
  ff_get_options[:parent].values.first
end

#nest_set_child_id(aim_id) ⇒ Object

Since:

  • Release 1.0.0



123
124
125
# 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) ⇒ Object

Since:

  • Release 1.0.0



134
135
136
137
# 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) ⇒ Object

Since:

  • Release 1.0.0



119
120
121
# 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) ⇒ Object

Since:

  • Release 1.0.0



129
130
131
132
# 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) ⇒ Object

Since:

  • Release 1.0.0



82
83
84
85
86
87
88
# 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_parentObject

Since:

  • Release 1.0.0



78
79
80
# File 'lib/fertile_forest/modules/entities.rb', line 78

def nest_unset_parent
  ff_get_options[:parent] = {0 => nil}
end

#nth_child(nth = 0, columns = nil) ⇒ Object

Since:

  • Release 1.0.0



183
184
185
# 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) ⇒ Object

Since:

  • Release 1.0.0



195
196
197
# File 'lib/fertile_forest/modules/entities.rb', line 195

def nth_sibling(nth = 0, columns = nil)
  self.class.nth_sibling(self, nth, columns)
end

#offset_sibling(offset, columns = nil) ⇒ Object

Since:

  • Release 1.0.0



207
208
209
# File 'lib/fertile_forest/modules/entities.rb', line 207

def offset_sibling(offset, columns = nil)
  self.class.offset_sibling(self, offset, columns)
end

#root(columns = nil) ⇒ Object

Since:

  • Release 1.0.0



163
164
165
# File 'lib/fertile_forest/modules/entities.rb', line 163

def root(columns = nil)
  self.class.root(self, columns)
end

#siblings(columns = nil) ⇒ Object

Since:

  • Release 1.0.0



191
192
193
# File 'lib/fertile_forest/modules/entities.rb', line 191

def siblings(columns = nil)
  self.class.siblings(self, columns)
end

#sizeObject

Since:

  • Release 1.0.0



223
224
225
# File 'lib/fertile_forest/modules/entities.rb', line 223

def size
  self.class.size(self)
end

#subtree(range = DESCENDANTS_ALL, with_top = true, columns = nil) ⇒ Object

Since:

  • Release 1.0.0



171
172
173
# 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) ⇒ Object

Since:

  • Release 1.0.0



151
152
153
# 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) ⇒ Object

Since:

  • Release 1.0.0



203
204
205
# File 'lib/fertile_forest/modules/entities.rb', line 203

def younger_sibling(columns = nil)
  self.class.younger_sibling(self, columns)
end