Class: StrongerParameters::HashConstraint
- Inherits:
-
Constraint
- Object
- Constraint
- StrongerParameters::HashConstraint
- Defined in:
- lib/stronger_parameters/constraints/hash_constraint.rb
Instance Attribute Summary collapse
-
#constraints ⇒ Object
readonly
Returns the value of attribute constraints.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(constraints) ⇒ HashConstraint
constructor
A new instance of HashConstraint.
- #merge(other) ⇒ Object
- #value(v) ⇒ Object
Methods inherited from Constraint
Constructor Details
#initialize(constraints) ⇒ HashConstraint
Returns a new instance of HashConstraint.
7 8 9 |
# File 'lib/stronger_parameters/constraints/hash_constraint.rb', line 7 def initialize(constraints) @constraints = constraints.with_indifferent_access end |
Instance Attribute Details
#constraints ⇒ Object (readonly)
Returns the value of attribute constraints.
5 6 7 |
# File 'lib/stronger_parameters/constraints/hash_constraint.rb', line 5 def constraints @constraints end |
Instance Method Details
#==(other) ⇒ Object
24 25 26 |
# File 'lib/stronger_parameters/constraints/hash_constraint.rb', line 24 def ==(other) super && constraints == other.constraints end |
#merge(other) ⇒ Object
19 20 21 22 |
# File 'lib/stronger_parameters/constraints/hash_constraint.rb', line 19 def merge(other) other_constraints = other.is_a?(HashConstraint) ? other.constraints : other self.class.new(constraints.merge(other_constraints)) end |
#value(v) ⇒ Object
11 12 13 14 15 16 17 |
# File 'lib/stronger_parameters/constraints/hash_constraint.rb', line 11 def value(v) if v.is_a?(Hash) return ActionController::Parameters.new(v).permit(constraints) end raise InvalidParameter.new(v, "must be a hash") end |