Module: StarkParameters::ClassMethods

Defined in:
lib/stark_parameters.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#aliasesObject

Returns the value of attribute aliases.



50
51
52
# File 'lib/stark_parameters.rb', line 50

def aliases
  @aliases
end

#permitted_paramsObject

Returns the value of attribute permitted_params.



50
51
52
# File 'lib/stark_parameters.rb', line 50

def permitted_params
  @permitted_params
end

#required_paramsObject

Returns the value of attribute required_params.



50
51
52
# File 'lib/stark_parameters.rb', line 50

def required_params
  @required_params
end

Instance Method Details

#permit(permitted_param, options = {}) ⇒ Object



60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/stark_parameters.rb', line 60

def permit(permitted_param, options = {})
  if new_name = options[:as]
    param_key = if permitted_param.is_a? Hash
      permitted_param.keys.first
    else
      permitted_param
    end

    @aliases[param_key] = new_name
  end
  @permitted_params.push permitted_param
end

#require(required_params, options = {}) ⇒ Object



52
53
54
55
56
57
58
# File 'lib/stark_parameters.rb', line 52

def require(required_params, options = {})
  required_params = Array(required_params)
  if new_name = options[:as]
    required_params.each { |rp| @aliases[rp] = new_name }
  end
  @required_params.push required_params
end