Class: Rosebud::ParamsScope

Inherits:
Object
  • Object
show all
Defined in:
lib/rosebud/params_scope.rb

Instance Method Summary collapse

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, options = {})
  name = name.to_sym
  if (@params[name].nil? || @params[name] == '') && options.has_key?(:default)
    @params[name] = options.delete(:default)
  end
  validate(name, @params[name], options)
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