Skip to content

Commit

Permalink
Allow all possible args in tagged_with method
Browse files Browse the repository at this point in the history
Previously, we only allowed tag names to be passed into the `tagged_with` method. This commit allows to take advantage of the interface gutentag has to offer, while being backwards compatible.
  • Loading branch information
robinboening committed Nov 18, 2021
1 parent eb50acb commit eafb1cd
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions lib/alchemy/taggable.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,20 @@ def tag_list=(tags)
end

module ClassMethods
# Find all records matching all of the given tags.
# Separate multiple tags by comma.
def tagged_with(names)
def tagged_with(names = [], **args)
if names.is_a? String
names = names.split(/,\s*/)
end
super(names: names, match: :all)

unless args[:match]
args.merge!(match: :all)
end

if names.any?
args.merge!(names: names)
end

super(args)
end

# Returns all unique tags
Expand Down

0 comments on commit eafb1cd

Please sign in to comment.