Module: ActiveRecord::Acts::Taggable::InstanceMethods

Defined in:
lib/acts_as_taggable.rb

Instance Method Summary collapse

Instance Method Details

#reload_with_tag_list(*args) ⇒ Object

:nodoc:



221
222
223
224
# File 'lib/acts_as_taggable.rb', line 221

def reload_with_tag_list(*args) #:nodoc:
  @tag_list = nil
  reload_without_tag_list(*args)
end

#save_cached_tag_listObject



185
186
187
188
189
# File 'lib/acts_as_taggable.rb', line 185

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_tagsObject



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/acts_as_taggable.rb', line 191

def save_tags
  return unless @tag_list
  
  new_tag_names = @tag_list - tags.map(&:name)
  old_tags = tags.reject { |tag| @tag_list.include?(tag.name) }
  
  self.class.transaction do
    if old_tags.any?
      taggings.find(:all, :conditions => ["tag_id IN (?)", old_tags.map(&:id)]).each(&:destroy)
      taggings.reset
    end
    
    new_tag_names.each do |new_tag_name|
      tags << 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.

The possible options are the same as the tag_counts class method.



214
215
216
217
218
219
# File 'lib/acts_as_taggable.rb', line 214

def tag_counts(options = {})
  return [] if tag_list.blank?
  
  options[:conditions] = self.class.send(:merge_conditions, options[:conditions], self.class.send(:tags_condition, tag_list))
  self.class.tag_counts(options)
end

#tag_listObject



171
172
173
174
175
176
177
178
179
# File 'lib/acts_as_taggable.rb', line 171

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(*tags.map(&:name))
  end
end

#tag_list=(value) ⇒ Object



181
182
183
# File 'lib/acts_as_taggable.rb', line 181

def tag_list=(value)
  @tag_list = TagList.from(value)
end