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.



66
67
68
# File 'lib/stark_parameters.rb', line 66

def aliases
  @aliases
end

#permitted_paramsObject

Returns the value of attribute permitted_params.



66
67
68
# File 'lib/stark_parameters.rb', line 66

def permitted_params
  @permitted_params
end

#presence_optional_paramsObject

Returns the value of attribute presence_optional_params.



66
67
68
# File 'lib/stark_parameters.rb', line 66

def presence_optional_params
  @presence_optional_params
end

#presence_required_paramsObject

Returns the value of attribute presence_required_params.



66
67
68
# File 'lib/stark_parameters.rb', line 66

def presence_required_params
  @presence_required_params
end

Instance Method Details

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



80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/stark_parameters.rb', line 80

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



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/stark_parameters.rb', line 68

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