Module: ActsAsTaggable::ActiveRecordExtension::InstanceMethods
- Defined in:
- lib/acts_as_taggable/active_record_extension.rb
Instance Method Summary collapse
-
#reload_with_tag_list(*args) ⇒ Object
:nodoc:.
- #save_cached_tag_list ⇒ Object
- #save_tags ⇒ Object
-
#tag_counts(options = {}) ⇒ Object
Calculate the tag counts for the tags used by this model.
- #tag_list ⇒ Object
- #tag_list=(value) ⇒ Object
Instance Method Details
#reload_with_tag_list(*args) ⇒ Object
:nodoc:
239 240 241 242 |
# File 'lib/acts_as_taggable/active_record_extension.rb', line 239 def reload_with_tag_list(*args) #:nodoc: @tag_list = nil reload_without_tag_list(*args) end |
#save_cached_tag_list ⇒ Object
206 207 208 209 210 |
# File 'lib/acts_as_taggable/active_record_extension.rb', line 206 def save_cached_tag_list if self.class.caching_tag_list? self[self.class.cached_tag_list_column_name] = tag_list.to_s end end |
#save_tags ⇒ Object
212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/acts_as_taggable/active_record_extension.rb', line 212 def return unless @tag_list new_tag_names = @tag_list - .map(&:name) = .reject { |tag| @tag_list.include?(tag.name) } self.class.transaction do if .any? taggings.where(:tag_id => .map(&:id)).each(&:destroy) taggings.reset end new_tag_names.each do |new_tag_name| << Tag.find_or_create_with_like_by_name(new_tag_name) end end true end |
#tag_counts(options = {}) ⇒ Object
Calculate the tag counts for the tags used by this model. See Tag.counts
for available options.
234 235 236 237 |
# File 'lib/acts_as_taggable/active_record_extension.rb', line 234 def tag_counts( = {}) return [] if tag_list.blank? self.class.tag_counts(.merge(:tags => tag_list)) end |
#tag_list ⇒ Object
192 193 194 195 196 197 198 199 200 |
# File 'lib/acts_as_taggable/active_record_extension.rb', line 192 def tag_list return @tag_list if @tag_list if self.class.caching_tag_list? and !(cached_value = send(self.class.cached_tag_list_column_name)).nil? @tag_list = TagList.from(cached_value) else @tag_list = TagList.new(*.map(&:name)) end end |