class StrongerParameters::HashConstraint

Attributes

constraints[R]

Public Class Methods

new(constraints) click to toggle source
# File lib/stronger_parameters/constraints/hash_constraint.rb, line 8
def initialize(constraints)
  @constraints = constraints.with_indifferent_access unless constraints.nil?
end

Public Instance Methods

==(other) click to toggle source
Calls superclass method StrongerParameters::Constraint#==
# File lib/stronger_parameters/constraints/hash_constraint.rb, line 28
def ==(other)
  super && constraints == other.constraints
end
merge(other) click to toggle source
# File lib/stronger_parameters/constraints/hash_constraint.rb, line 23
def merge(other)
  other_constraints = other.is_a?(HashConstraint) ? other.constraints : other
  self.class.new(constraints.merge(other_constraints))
end
value(v) click to toggle source
# File lib/stronger_parameters/constraints/hash_constraint.rb, line 12
def value(v)
  return InvalidValue.new(v, "must be a hash") if !v.is_a?(Hash) && !v.is_a?(ActionController::Parameters)

  v = ActionController::Parameters.new(v) if v.is_a?(Hash)
  if constraints.nil?
    v.permit!
  else
    v.permit(constraints)
  end
end