module ActsAsTaggableOn::Taggable::Core
Public Class Methods
included(base)
click to toggle source
# File lib/acts_as_taggable_on/taggable/core.rb, line 7 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 139 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 143 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 131 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 127 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 135 def is_taggable? self.class.is_taggable? end
reload(*args)
click to toggle source
Calls superclass method
# File lib/acts_as_taggable_on/taggable/core.rb, line 215 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 201 def set_tag_list_on(context, new_list) add_custom_context(context) variable_name = "@#{context.to_s.singularize}_list" parsed_new_list = ActsAsTaggableOn.default_parser.new(new_list).parse instance_variable_set(variable_name, parsed_new_list) end
tag_list_cache_on(context)
click to toggle source
# File lib/acts_as_taggable_on/taggable/core.rb, line 152 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 147 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 163 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 211 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 293 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 287 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 282 def ensure_included_cache_methods! self.class.columns end