Class: Thoth::Tag

Inherits:
Sequel::Model show all
Defined in:
lib/thoth/model/tag.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.suggest(query, limit = 1000) ⇒ Object

Gets an array of tag names and post counts for tags with names that begin with the specified query string.



43
44
45
46
47
48
49
50
51
52
# File 'lib/thoth/model/tag.rb', line 43

def self.suggest(query, limit = 1000)
  tags = []

  self.dataset.grep(:name, "#{query}%").all do |tag|
    tags << [tag.name, tag.posts.count]
  end

  tags.sort!{|a, b| b[1] <=> a[1]}
  tags[0, limit]
end

Instance Method Details

#atom_urlObject

Gets the Atom feed URL for this tag.



59
60
61
# File 'lib/thoth/model/tag.rb', line 59

def atom_url
  Config.site['url'].chomp('/') + TagController.r(:atom, name).to_s
end

#postsObject

Gets published posts with this tag.



64
65
66
67
# File 'lib/thoth/model/tag.rb', line 64

def posts
  @posts ||= posts_dataset.filter(:is_draft => false).reverse_order(
      :created_at)
end

#urlObject

URL for this tag.



70
71
72
# File 'lib/thoth/model/tag.rb', line 70

def url
  Config.site['url'].chomp('/') + TagController.r(:/, name).to_s
end

#validateObject



74
75
76
77
# File 'lib/thoth/model/tag.rb', line 74

def validate
  validates_presence(:name)
  validates_max_length(64, :name)
end