Class: Rosebud::ParamsScope
- Inherits:
-
Object
- Object
- Rosebud::ParamsScope
- Defined in:
- lib/rosebud/params_scope.rb
Instance Method Summary collapse
-
#initialize(controller, params, &block) ⇒ ParamsScope
constructor
A new instance of ParamsScope.
- #optional(name, options = {}) ⇒ Object
- #requires(name, validations = {}) ⇒ Object
Constructor Details
#initialize(controller, params, &block) ⇒ ParamsScope
Returns a new instance of ParamsScope.
3 4 5 6 7 8 9 |
# File 'lib/rosebud/params_scope.rb', line 3 def initialize(controller, params, &block) @controller = controller @params = params @declared_params = [] instance_eval(&block) end |
Instance Method Details
#optional(name, options = {}) ⇒ Object
18 19 20 21 22 23 24 |
# File 'lib/rosebud/params_scope.rb', line 18 def optional(name, = {}) name = name.to_sym if (@params[name].nil? || @params[name] == '') && .has_key?(:default) @params[name] = .delete(:default) end validate(name, @params[name], ) end |
#requires(name, validations = {}) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/rosebud/params_scope.rb', line 11 def requires(name, validations = {}) name = name.to_sym validations.merge!({ presence: true }) validate(name, @params[name], validations) end |