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
Extension to validate? #300
Comments
What types of things would you want to validate? Type "validations" can be done using the property translation mixin (i.e. the behavior that Trash adds to Dash). |
Specifically, I'd like the hash classes to provide a mechanism for validating semantics (values). Using the above example: def title_valid?(value)
value.length < 16
end
def property_valid?(name, value)
false if value.nil?
value =~ /email_regex/ if name.start_with?('email-')
...
end It'd be great to know that (e.g.) Dash refuses to accept (whether silently or with error - depending on what the user wants) entries that have a value of nil :). |
I have been doing this to get validations: include ActiveModel::Validations |
I think @martinstreicher is onto something, ActiveModel is the "golden standard" and just works out of the box. Any reason why we would still want this here? |
This is a code snippet from a class derived from Hashie. require 'hashie/dash'
module DSL
module Keywords
class Base < Hashie::Dash
include ActiveModel::Validations I can then do things like |
I wonder whether we should add this to the docs, what do you think @martinstreicher ? |
I think it worthwhile. In my recent use cases, I am using Hashie::Dash as a stand-in for ActiveModel where I don’t require persistence. I use the other features of Hashie like coercion and dot access and mix in ActiveModel components to do validation, etc. On Aug 22, 2015, at 3:43 PM, Daniel Doubrovkine (dB.) @dblockdotorg notifications@github.com wrote:
|
I'm looking forward to a PR from @martinstreicher :) |
Would there be an easy way to add validations to certain declared properties or hash keys?
For example:
Perhaps even:
The text was updated successfully, but these errors were encountered: