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.



63
64
65
# File 'lib/stark_parameters.rb', line 63

def aliases
  @aliases
end

#permitted_paramsObject

Returns the value of attribute permitted_params.



63
64
65
# File 'lib/stark_parameters.rb', line 63

def permitted_params
  @permitted_params
end

#presence_optional_paramsObject

Returns the value of attribute presence_optional_params.



63
64
65
# File 'lib/stark_parameters.rb', line 63

def presence_optional_params
  @presence_optional_params
end

#presence_required_paramsObject

Returns the value of attribute presence_required_params.



63
64
65
# File 'lib/stark_parameters.rb', line 63

def presence_required_params
  @presence_required_params
end

Instance Method Details

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



77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/stark_parameters.rb', line 77

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



65
66
67
68
69
70
71
72
73
74
75
# File 'lib/stark_parameters.rb', line 65

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