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

#cousins(columns = nil) ⇒ Object

Since:

  • 1.1.0



205
206
207
# File 'lib/fertile_forest/modules/entities.rb', line 205

def cousins(columns = nil)
  self.class.cousins(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



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

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



243
244
245
# File 'lib/fertile_forest/modules/entities.rb', line 243

def height
  self.class.height(self)
end

#internals(columns = nil) ⇒ Object

Since:

  • Release 1.0.0



239
240
241
# 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) ⇒ Object

Since:

  • 1.1.0



192
193
194
195
196
197
198
# 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) ⇒ Object

Since:

  • Release 1.0.0



235
236
237
# File 'lib/fertile_forest/modules/entities.rb', line 235

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

#niblings(columns = nil) ⇒ Object

Since:

  • 1.1.0



210
211
212
# 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) ⇒ 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



219
220
221
# 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) ⇒ Object

Since:

  • Release 1.0.0



231
232
233
# 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) ⇒ Object

Since:

  • 1.1.0



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

def piblings(columns = nil)
  self.class.piblings(self, 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



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

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

#sizeObject

Since:

  • Release 1.0.0



247
248
249
# 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) ⇒ 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



227
228
229
# File 'lib/fertile_forest/modules/entities.rb', line 227

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