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

Possible to assign multiple filters with the same name #106

Closed
tfausak opened this issue Jan 16, 2014 · 2 comments
Closed

Possible to assign multiple filters with the same name #106

tfausak opened this issue Jan 16, 2014 · 2 comments
Assignees
Labels
Milestone

Comments

@tfausak
Copy link
Collaborator

tfausak commented Jan 16, 2014

It's possible to define an interaction with any number of filters sharing a name.

class Interaction < ActiveInteraction::Base
  boolean :thing
  boolean :thing, default: nil
  boolean :thing, default: false
  def execute; inputs end
end

This usually doesn't matter too much because the last one will take precedence.

Interaction.run!
# => {:thing=>false}

However, they're all still there.

Interaction.filters.instance_variable_get(:@filters)
# => [#<ActiveInteraction::BooleanFilter:0x... @name=:thing, @options={}, ...>, 
#     #<ActiveInteraction::BooleanFilter:0x... @name=:thing, @options={:default=>nil}, ...>, 
#     #<ActiveInteraction::BooleanFilter:0x... @name=:thing, @options={:default=>false}, ...>]

The way I see it, we have a couple options for what to do when someone redefines an existing filter:

  • Merge it into the existing filter.
  • Replace the existing filter.
  • Raise an error.
  • Generate a warning.
@tfausak
Copy link
Collaborator Author

tfausak commented Jan 16, 2014

I discovered this because of the workaround for #104. I imported filters from two separate interactions and they happened to overlap. It ended up causing a hard-to-find bug.

@tfausak
Copy link
Collaborator Author

tfausak commented Jan 16, 2014

After talking it over in person, I think we should replace the existing filter. That way including filters will behave like including modules — the last one wins.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant