Module: Hanami::Action::Validatable::ClassMethods Private
- Defined in:
- lib/hanami/action/validatable.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Validatable API class methods
Instance Method Summary collapse
-
#params(klass = nil, &blk) ⇒ Object
private
Whitelist valid parameters to be passed to Hanami::Action#call.
Instance Method Details
#params(klass = nil, &blk) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Whitelist valid parameters to be passed to Hanami::Action#call.
This feature isn’t mandatory, but higly recommended for security reasons.
Because params come into your application from untrusted sources, it’s a good practice to filter only the wanted keys that serve for your specific use case.
Once whitelisted, the params are available as an Hash with symbols as keys.
It accepts an anonymous block where all the params can be listed. It internally creates an inner class which inherits from Hanami::Action::Params.
Alternatively, it accepts an concrete class that should inherit from Hanami::Action::Params.
97 98 99 100 101 102 103 104 |
# File 'lib/hanami/action/validatable.rb', line 97 def params(klass = nil, &blk) if klass.nil? klass = const_set(PARAMS_CLASS_NAME, Class.new(Params)) klass.class_eval { params(&blk) } end @params_class = klass end |