module RubyPocket::TagsQueryHelper

Private Instance Methods

find_all_tags(names) click to toggle source
# File lib/ruby_pocket/tags_query_helper.rb, line 7
def find_all_tags(names)
  names.map { |name| find_tag_match(name) }
end
find_exact_tag_match(name) click to toggle source
# File lib/ruby_pocket/tags_query_helper.rb, line 19
def find_exact_tag_match(name)
  found_tag = Tag.find(name: name).tap do |tag|
    fail ArgumentError, "Tag #{name} not found" unless tag
  end

  { tags: found_tag }
end
find_partial_tag_match(name) click to toggle source
# File lib/ruby_pocket/tags_query_helper.rb, line 27
def find_partial_tag_match(name)
  tags = Tag.where(Sequel.like(:name, name.gsub(?/, ?%))).all
  Sequel.or(tags: tags)
end
find_tag_match(name) click to toggle source
# File lib/ruby_pocket/tags_query_helper.rb, line 11
def find_tag_match(name)
  if name.start_with?(?/) && name.end_with?(?/)
    find_partial_tag_match(name)
  else
    find_exact_tag_match(name)
  end
end