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
Extend Dash to accept only predefined values #61
Comments
That sounds like a good custom subclass. Would you be interested in trying to implement it and submit a pull request? |
I'll take a peek into it. |
Bump. |
I think this can be a new feature for Dash
|
Should this be implemented as a validation instead? It would serve the 2 examples above, but also open to other validations in the future. property :gender, validate: { within: [:male, :female, :meat_popsicle] }
property :age, validate: { within: age_range }
property :hair_color, validate: { with: ->(colour) { hex_color? } } |
Feel like an overkill because property :gender, values: [:male, :female, :meat_popsicle]
property :age, values: 1..150 # a Range I think a PR for the above would be super valuable and solve 99% of the scenarios. The other half of this problem is that you don't always want values, but types. So I'd want property :possible, type: Boolean
property :offset, type: Integer The third, class Color
attr_reader :value
def initialize(color)
@value = color
end
def self.parse(value)
fail 'Invalid color' unless hex_color?(value)
new(value)
end
def hex_color?(value)
# ...
end
end
property :hair_color, type: Color Thinking out loud we would really want the entire coercion, types, checks system that is implemented in Grape using dry-types. Maybe as a separate gem even. Thoughts? |
Starting with
💯 |
Extends a Dash with the ability to accept only predefined values on a property. hashie#61
Extends a Dash with the ability to accept only predefined values on a property. hashie#61
Extends a Dash with the ability to accept only predefined values on a property. hashie#61
Extends a Dash with the ability to accept only predefined values on a property. hashie#61
Extends a Dash with the ability to accept only predefined values on a property. hashie#61
Extends a Dash with the ability to accept only predefined values on a property. hashie#61
Extends a Dash with the ability to accept only predefined values on a property. hashie#61
Hey,
I was wanting the ability to pass a method, collection, or lambda/proc to a hashie property. What it should do is limit the options that the property can take.
Or something similar.
The text was updated successfully, but these errors were encountered: