class Sharkey::Link

Represents a single HyperLink specified by the user.

Public Class Methods

by_category(category_id) click to toggle source

Returns all Links that have a Category with ‘category_id`

# File lib/sharkey/models.rb, line 138
def self.by_category(category_id)

  # RANT: I don't know why I couldn't simply do something like
  #       `Sharkey::Link.all(:category => Sharkey::Category.get(category_id))`
  #       it seems so strange!
  #       DataMapper's docs imply that we actually _can_,
  #       so why...?

  categorizations = Sharkey::Categorization.all(:category_id => category_id)

  Sharkey::Link.all(:categorization => categorizations)
end
by_tag(tag_id) click to toggle source

Returns all Links that have a Tag with ‘tag_id`

# File lib/sharkey/models.rb, line 124
def self.by_tag(tag_id)

  # RANT: I don't know why I couldn't simply do something like
  #       `Sharkey::Link.all(:tag => Sharkey::Tag.get(tag_id))`
  #       it seems so strange!
  #       DataMapper's docs imply that we actually _can_,
  #       so why...?

  taggings = Sharkey::Tagging.all(:tag_id => tag_id)

  Sharkey::Link.all(:taggings => taggings)
end

Public Instance Methods

toggle_favorite() click to toggle source
# File lib/sharkey/models.rb, line 151
def toggle_favorite
  self.update(favorite: (not self.favorite));
end
visit() click to toggle source

Increases the visit count by one

# File lib/sharkey/models.rb, line 161
def visit
  self.update(last_visit: DateTime.now);
  self.update(visit_count: (self.visit_count + 1));
end
visited?() click to toggle source

Tells if this link was ever visited

# File lib/sharkey/models.rb, line 156
def visited?
  self.visit_count != 0
end