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

Enum filter #561

Open
casiodk opened this issue Apr 18, 2023 · 2 comments
Open

Enum filter #561

casiodk opened this issue Apr 18, 2023 · 2 comments

Comments

@casiodk
Copy link

casiodk commented Apr 18, 2023

I think something like dry types enums would be a great addition to the library!!

class Book < ActiveInteraction::Base
  enum :state, values: ["open", "closed"]
end
@AaronLasseigne
Copy link
Owner

I'm not sure how I feel about adding enum. The other filters cast/convert incoming values to a particular type. With enum I guess we'd have to force the type to String. Alternately, it could avoid casting and only check exact values but I feel like that'd be a problem. People expect the casting of inputs.

It's longer but you can do this now with a validation:

class Book < ActiveInteraction::Base
  string :state

  validates :string, inclusion: { in: %w[open closed] }
end

@casiodk
Copy link
Author

casiodk commented Apr 19, 2023

what about

class Book < ActiveInteraction::Base
  enum :state, values: ["open", "closed"] do
    string
  end
end

Similar to arrays ?

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

No branches or pull requests

2 participants