class Sharkey::Category

Category for Links.

While a Link can have several Tags, it can only have a single Category.

Think of it as a folder on your Bookmarks browser.

A category can have one parent and many children.

Public Class Methods

orphans() click to toggle source
# File lib/sharkey/models.rb, line 254
def self.orphans
  all.select { |me| me.parent.nil? }
end

Public Instance Methods

add_child(child) click to toggle source
# File lib/sharkey/models.rb, line 220
def add_child child
  return if (child.nil?) or (child == self) or (has_child? child)
  return if (child.parent) and (child.parent == self)

  self.childs << child
  child.parent = self

  self.save
  self
end
has_child?(child) click to toggle source
# File lib/sharkey/models.rb, line 231
def has_child? child
  self.childs.member? child
end
remove_child(child) click to toggle source

Removes the parent/children relationship @note Does not remove any Categories!

# File lib/sharkey/models.rb, line 237
def remove_child child
  throw 'Removing self as child' if child == self

  if self.categoryChilds
    self.categoryChilds.all(target_id: child.id).destroy
  end

  if child.categoryParent
    if child.categoryParent.source_id == self.id
      child.categoryParent.destroy
    end
  end

  self.reload
  self
end