Module: YeshuaCrm::ActsAsTaggable::Taggable::InstanceMethods

Defined in:
lib/yeshua_crm/acts_as_taggable/rcrm_acts_as_taggable.rb

Instance Method Summary collapse

Instance Method Details

#all_tags_listObject

build list from related tags



303
304
305
# File 'lib/yeshua_crm/acts_as_taggable/rcrm_acts_as_taggable.rb', line 303

def all_tags_list
  tags.pluck(:name)
end

#reload_with_tag_list(*args) ⇒ Object

:nodoc:



336
337
338
339
# File 'lib/yeshua_crm/acts_as_taggable/rcrm_acts_as_taggable.rb', line 336

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

#save_cached_tag_listObject



296
297
298
299
300
# File 'lib/yeshua_crm/acts_as_taggable/rcrm_acts_as_taggable.rb', line 296

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



307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
# File 'lib/yeshua_crm/acts_as_taggable/rcrm_acts_as_taggable.rb', line 307

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.where("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.



329
330
331
332
333
334
# File 'lib/yeshua_crm/acts_as_taggable/rcrm_acts_as_taggable.rb', line 329

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



282
283
284
285
286
287
288
289
290
# File 'lib/yeshua_crm/acts_as_taggable/rcrm_acts_as_taggable.rb', line 282

def tag_list
  return @tag_list if @tag_list ||= nil

  if self.class.caching_tag_list? && !(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



292
293
294
# File 'lib/yeshua_crm/acts_as_taggable/rcrm_acts_as_taggable.rb', line 292

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