Class UsedTag
In: app/models/used_tag.rb
Parent: ActiveRecord::Base

Tags are never created or deleted directly by users.

Methods

Included Modules

Comparable

Public Class methods

Same as or_new_from_tag, but raises an error if it does not exist.

[Source]

    # File app/models/used_tag.rb, line 71
71:   def self.from_tag(tag)
72:     u_t = UsedTag.or_nil_from_tag(tag)
73:     if u_t.nil?
74:       raise ExistenceError.new(tag), t('m.used_tag.error_not_found')
75:     else
76:       return u_t
77:     end
78:   end

Parses an UsedTag from a string. Creates a new one if it does not exist yet.

See Tag.hash_from_s for the syntax of the string.

[Source]

    # File app/models/used_tag.rb, line 60
60:   def self.or_new_from_tag(tag)
61:     u_t = UsedTag.or_nil_from_tag(tag)
62:     if u_t.nil?
63:       return UsedTag.new(:tag => tag)
64:     else
65:       return u_t
66:     end
67:   end

Same as or_new_from_tag, but returns nil if it does not exist.

[Source]

    # File app/models/used_tag.rb, line 82
82:   def self.or_nil_from_tag(tag)
83:     u_t = UsedTag.find_by_string(tag.to_s)
84:     return u_t
85:   end

Finds and decrements the UsedTag use_count for this tag.

[Source]

     # File app/models/used_tag.rb, line 103
103:   def self.release(tag)
104:     u_t = UsedTag.from_tag(tag)
105:     if u_t # check here, cause from_tag can be overloaded
106:       u_t.decrement
107:       if !u_t.destroy
108:         u_t.save
109:       end
110:     end
111:   end

Returns the most used UsedTags for the tag-cloud.

Arguments:

  • limit = the max amount of tags returned

[Source]

    # File app/models/used_tag.rb, line 42
42:   def self.top_used_tags(options = {})
43:     if options.delete(:no_special)
44:       if !options[:conditions]
45:         options[:conditions] = []
46:       end
47:       options[:conditions].push('cloud_visibility = true')
48:     end
49:     return UsedTag.find(:all, options.merge(
50:         :order => "use_count DESC")).sort_by {|used_tag| used_tag.tag}
51:   end

Finds and increments the UsedTag use_count for this tag.

If needed, creates a UsedTag for it.

[Source]

    # File app/models/used_tag.rb, line 91
91:   def self.use(tag)
92:     u_t = UsedTag.or_new_from_tag(tag)
93:     # TODO make more efficient
94:     if tag.name? or tag.home_page? or tag.system?
95:       u_t.cloud_visibility = false
96:     end
97:     u_t.increment
98:     u_t.save
99:   end

Public Instance methods

Compares two tags and/or strings, based on to_s.

[Source]

     # File app/models/used_tag.rb, line 119
119:   def <=>(other)
120:     return (self.tag <=> other.tag)
121:   end

Decrements the use_counter.

[Source]

     # File app/models/used_tag.rb, line 133
133:   def decrement
134:     self.use_count -= 1
135:   end

Increments the use_counter.

[Source]

     # File app/models/used_tag.rb, line 127
127:   def increment
128:     self.use_count += 1
129:   end

Protected Instance methods

Checks that this Tag is unused.

[Source]

     # File app/models/used_tag.rb, line 143
143:   def check_destroyability
144:     return self.use_count == 0
145:   end

[Validate]