Class: ParameterSets::Schema
- Inherits:
-
Object
- Object
- ParameterSets::Schema
- Defined in:
- lib/parameter_sets/schema.rb
Instance Method Summary collapse
-
#base_param_name ⇒ Object
Return the base parameter name to get from the request’s parameters.
-
#initialize(name, options = {}, &block) ⇒ Schema
constructor
A new instance of Schema.
-
#parameters(controller, object = nil, options = {}) ⇒ Object
Return a suitablely scoped ActionController::Parameters object based on the rules defined for this param set.
Constructor Details
#initialize(name, options = {}, &block) ⇒ Schema
7 8 9 10 11 |
# File 'lib/parameter_sets/schema.rb', line 7 def initialize(name, = {}, &block) @name = name @options = @block = block end |
Instance Method Details
#base_param_name ⇒ Object
Return the base parameter name to get from the request’s parameters.
14 15 16 |
# File 'lib/parameter_sets/schema.rb', line 14 def base_param_name @options[:param_name] || @name end |
#parameters(controller, object = nil, options = {}) ⇒ Object
Return a suitablely scoped ActionController::Parameters object based on the rules defined for this param set.
23 24 25 26 27 28 29 30 31 |
# File 'lib/parameter_sets/schema.rb', line 23 def parameters(controller, object = nil, = {}) dsl = SchemaDSL.new controller.instance_exec(dsl, object, , &@block) if @block if dsl.fields.empty? raise NoParametersPermittedError, "No fields were permitted" else controller.params.require(base_param_name).permit(*dsl.fields) end end |