module ActsAsTaggableOn::Taggable::Core
Public Class Methods
included(base)
click to toggle source
# File lib/acts_as_taggable_on/taggable/core.rb, line 5 def self.included(base) base.extend ActsAsTaggableOn::Taggable::Core::ClassMethods base.class_eval do attr_writer :custom_contexts after_save :save_tags end base.initialize_acts_as_taggable_on_core end
Public Instance Methods
add_custom_context(value)
click to toggle source
# File lib/acts_as_taggable_on/taggable/core.rb, line 118 def add_custom_context(value) custom_contexts << value.to_s unless custom_contexts.include?(value.to_s) or self.class.tag_types.map(&:to_s).include?(value.to_s) end
cached_tag_list_on(context)
click to toggle source
# File lib/acts_as_taggable_on/taggable/core.rb, line 122 def cached_tag_list_on(context) self["cached_#{context.to_s.singularize}_list"] end
custom_contexts()
click to toggle source
# File lib/acts_as_taggable_on/taggable/core.rb, line 110 def custom_contexts @custom_contexts ||= taggings.map(&:context).uniq end
grouped_column_names_for(object)
click to toggle source
all column names are necessary for PostgreSQL group clause
# File lib/acts_as_taggable_on/taggable/core.rb, line 106 def grouped_column_names_for(object) self.class.grouped_column_names_for(object) end
is_taggable?()
click to toggle source
# File lib/acts_as_taggable_on/taggable/core.rb, line 114 def is_taggable? self.class.is_taggable? end
process_dirty_object(context, new_list)
click to toggle source
# File lib/acts_as_taggable_on/taggable/core.rb, line 193 def process_dirty_object(context, new_list) value = new_list.is_a?(Array) ? ActsAsTaggableOn::TagList.new(new_list) : new_list attrib = "#{context.to_s.singularize}_list" if changed_attributes.include?(attrib) # The attribute already has an unsaved change. old = changed_attributes[attrib] @changed_attributes.delete(attrib) if old.to_s == value.to_s else old = tag_list_on(context) if self.class.preserve_tag_order @changed_attributes[attrib] = old if old.to_s != value.to_s else @changed_attributes[attrib] = old.to_s if old.sort != ActsAsTaggableOn.default_parser.new(value).parse.sort end end end
reload(*args)
click to toggle source
Calls superclass method
# File lib/acts_as_taggable_on/taggable/core.rb, line 211 def reload(*args) self.class.tag_types.each do |context| instance_variable_set("@#{context.to_s.singularize}_list", nil) instance_variable_set("@all_#{context.to_s.singularize}_list", nil) end super(*args) end
set_tag_list_on(context, new_list)
click to toggle source
# File lib/acts_as_taggable_on/taggable/core.rb, line 180 def set_tag_list_on(context, new_list) add_custom_context(context) variable_name = "@#{context.to_s.singularize}_list" process_dirty_object(context, new_list) unless custom_contexts.include?(context.to_s) instance_variable_set(variable_name, ActsAsTaggableOn.default_parser.new(new_list).parse) end
tag_list_cache_on(context)
click to toggle source
# File lib/acts_as_taggable_on/taggable/core.rb, line 131 def tag_list_cache_on(context) variable_name = "@#{context.to_s.singularize}_list" if instance_variable_get(variable_name) instance_variable_get(variable_name) elsif cached_tag_list_on(context) && ensure_included_cache_methods! && self.class.caching_tag_list_on?(context) instance_variable_set(variable_name, ActsAsTaggableOn.default_parser.new(cached_tag_list_on(context)).parse) else instance_variable_set(variable_name, ActsAsTaggableOn::TagList.new(tags_on(context).map(&:name))) end end
tag_list_cache_set_on(context)
click to toggle source
# File lib/acts_as_taggable_on/taggable/core.rb, line 126 def tag_list_cache_set_on(context) variable_name = "@#{context.to_s.singularize}_list" instance_variable_defined?(variable_name) && instance_variable_get(variable_name) end
tag_list_on(context)
click to toggle source
# File lib/acts_as_taggable_on/taggable/core.rb, line 142 def tag_list_on(context) add_custom_context(context) tag_list_cache_on(context) end
tagging_contexts()
click to toggle source
# File lib/acts_as_taggable_on/taggable/core.rb, line 189 def tagging_contexts self.class.tag_types.map(&:to_s) + custom_contexts end
Private Instance Methods
attributes_for_create(attribute_names)
click to toggle source
Filters the tag lists from the attribute names.
Calls superclass method
# File lib/acts_as_taggable_on/taggable/core.rb, line 289 def attributes_for_create(attribute_names) tag_lists = tag_types.map {|tags_type| "#{tags_type.to_s.singularize}_list"} super.delete_if {|attr| tag_lists.include? attr } end
attributes_for_update(attribute_names)
click to toggle source
Filters the tag lists from the attribute names.
Calls superclass method
# File lib/acts_as_taggable_on/taggable/core.rb, line 283 def attributes_for_update(attribute_names) tag_lists = tag_types.map {|tags_type| "#{tags_type.to_s.singularize}_list"} super.delete_if {|attr| tag_lists.include? attr } end
ensure_included_cache_methods!()
click to toggle source
# File lib/acts_as_taggable_on/taggable/core.rb, line 278 def ensure_included_cache_methods! self.class.columns end