Class: Thoth::Tag
- Inherits:
-
Sequel::Model
- Object
- Sequel::Model
- Thoth::Tag
- Defined in:
- lib/thoth/model/tag.rb
Class Method Summary collapse
-
.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.
Instance Method Summary collapse
-
#atom_url ⇒ Object
Gets the Atom feed URL for this tag.
-
#posts ⇒ Object
Gets published posts with this tag.
-
#url ⇒ Object
URL for this tag.
- #validate ⇒ Object
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) = [] self.dataset.grep(:name, "#{query}%").all do |tag| << [tag.name, tag.posts.count] end .sort!{|a, b| b[1] <=> a[1]} [0, limit] end |
Instance Method Details
#atom_url ⇒ Object
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 |
#posts ⇒ Object
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 |
#url ⇒ Object
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 |
#validate ⇒ Object
74 75 76 77 |
# File 'lib/thoth/model/tag.rb', line 74 def validate validates_presence(:name) validates_max_length(64, :name) end |