Class: Tag
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Tag
- Defined in:
- app/models/tag.rb
Class Method Summary collapse
-
.counts(options = {}) ⇒ Object
Calculate the tag counts for all tags.
- .find_or_create_with_like_by_name(name) ⇒ Object
Instance Method Summary collapse
Class Method Details
.counts(options = {}) ⇒ Object
Calculate the tag counts for all tags.
-
:start_at
- restrict the tags to those created after a certain time -
:end_at
- restrict the tags to those created before a certain time -
:at_least
- exclude tags with a frequency less than the given value -
:at_most
- exclude tags with a frequency greater than the given value
Deprecated:
-
:conditions
-
:limit
-
:order
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'app/models/tag.rb', line 42 def counts( = {}) .assert_valid_keys :start_at, :end_at, :at_least, :at_most, :conditions, :limit, :order, :joins = joins(:taggings) = .having(['count >= ?', [:at_least]]) if [:at_least] = .having(['count <= ?', [:at_most]]) if [:at_most] = .where("#{Tagging.quoted_table_name}.created_at >= ?", [:start_at]) if [:start_at] = .where("#{Tagging.quoted_table_name}.created_at <= ?", [:end_at]) if [:end_at] # TODO: deprecation warning = .where([:conditions]) if [:conditions] = .limit([:limit]) if [:limit] = .order([:order]) if [:order] if joins = .delete(:joins) = .joins(joins) end .select("#{quoted_table_name}.id, #{quoted_table_name}.name, COUNT(#{quoted_table_name}.id) AS count").group('tags.id, tags.name') end |
.find_or_create_with_like_by_name(name) ⇒ Object
25 26 27 |
# File 'app/models/tag.rb', line 25 def find_or_create_with_like_by_name(name) where(arel_table[:name].matches(name)).first || create(:name => name) end |
Instance Method Details
#==(object) ⇒ Object
12 13 14 |
# File 'app/models/tag.rb', line 12 def ==(object) super || (object.is_a?(Tag) && name == object.name) end |
#count ⇒ Object
20 21 22 |
# File 'app/models/tag.rb', line 20 def count read_attribute(:count).to_i end |
#to_s ⇒ Object
16 17 18 |
# File 'app/models/tag.rb', line 16 def to_s name end |