class ActsAsTaggableOnMongoid::Taggable::TaggedWithQuery
A class finding all Taggable
objects for the passed in tags based on the passed in parameters. Details for how the query will work are in the TaggedWith
module.
Attributes
options[R]
tag_definition[R]
taggable_class[R]
Public Class Methods
new(taggable_class, *tags)
click to toggle source
# File lib/acts_as_taggable_on_mongoid/taggable/tagged_with_query.rb, line 13 def initialize(taggable_class, *tags) new_tags = tags.dup @taggable_class = taggable_class @options = new_tags.extract_options!.dup @tags = new_tags cleanup_options context = on_context(*options[:on]) @tag_definition = taggable_class.tag_types[context] end
Public Instance Methods
build()
click to toggle source
# File lib/acts_as_taggable_on_mongoid/taggable/tagged_with_query.rb, line 25 def build klass = if options[:exclude].present? ExcludeTagsQuery elsif options[:any].present? AnyTagsQuery elsif options[:match_all] MatchAllTagsQuery else AllTagsQuery end klass.new(tag_definition, tag_list, options).build end
Private Instance Methods
build_tag_list()
click to toggle source
# File lib/acts_as_taggable_on_mongoid/taggable/tagged_with_query.rb, line 86 def build_tag_list return [] if tag_definition.blank? tag_list = ActsAsTaggableOnMongoid::TagList.new(tag_definition, *tags, options.slice(:parse, :parser)) tag_list = tag_list.map { |tag| /#{tag}/ } if options[:wild] tag_list end
cleanup_options()
click to toggle source
# File lib/acts_as_taggable_on_mongoid/taggable/tagged_with_query.rb, line 41 def cleanup_options options[:on] = Array.wrap(options[:on] || options.delete(:context)) options[:parse] = options.fetch(:parse) { true } || options.key?(:parser) validate_options end
conflicting_context?(left, right)
click to toggle source
:reek: FeatureEnvy
# File lib/acts_as_taggable_on_mongoid/taggable/tagged_with_query.rb, line 74 def conflicting_context?(left, right) return false if left == right tag_types = taggable_class.tag_types tag_types[left].conflicts_with? tag_types[right] end
on_context(*contexts)
click to toggle source
# File lib/acts_as_taggable_on_mongoid/taggable/tagged_with_query.rb, line 61 def on_context(*contexts) test_contexts = (contexts.presence || taggable_class.tag_types.keys).flatten primary_context = test_contexts.first test_contexts.each do |context| raise "conflicting context definitions" if conflicting_context?(primary_context, context) end primary_context end
tag_list()
click to toggle source
# File lib/acts_as_taggable_on_mongoid/taggable/tagged_with_query.rb, line 82 def tag_list @tag_list ||= build_tag_list end
validate_options()
click to toggle source
# File lib/acts_as_taggable_on_mongoid/taggable/tagged_with_query.rb, line 48 def validate_options options.assert_valid_keys :parse, :parser, :wild, :exclude, :match_all, :all, :any, :on, :start_at, :end_at end