Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow the use of matchers in Taggable.tagged_with() #2208

Closed
robinboening opened this issue Nov 5, 2021 · 0 comments · Fixed by #2211
Closed

Allow the use of matchers in Taggable.tagged_with() #2208

robinboening opened this issue Nov 5, 2021 · 0 comments · Fixed by #2211

Comments

@robinboening
Copy link
Contributor

robinboening commented Nov 5, 2021

After the switch from ActsAsTaggableOn to Gutentag a new Taggable module was introduced. It overrides the tagged_with class method both libraries are offering. Both libraries allow to choose the tag matching mechanism when using this method. Currently, the module does not allow this at all but hard codes match: :all when delegating to the original method.

Describe the solution you'd like
I'd like to change the tagged_with interface, but keep it backwards compatible. The benefit is we can fully support the underlying interface gutentag has to offer.

The implementation looks like this

def tagged_with(names=[], **args)
  if names.is_a? String
    names = names.split(/,\s*/)
  end

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

  super(args)
end

still supporting the current way of using it, without any behaviour change.

Alchemy::Attachment.tagged_with("foo, bar")

but allowing us to take advantage of other matchers than just all.

Alchemy::Attachment.tagged_with(["foo", "bar"], match: :any)

But it also allows for more...

Alchemy::Attachment.tagged_with(:ids => [tag_id], match: :any)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant