Class: StrongerParameters::RegexpConstraint
- Inherits:
-
Constraint
- Object
- Constraint
- StrongerParameters::RegexpConstraint
- Defined in:
- lib/stronger_parameters/constraints/regexp_constraint.rb
Instance Attribute Summary collapse
-
#regexp ⇒ Object
readonly
Returns the value of attribute regexp.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#initialize(regexp) ⇒ RegexpConstraint
constructor
A new instance of RegexpConstraint.
- #value(v) ⇒ Object
Methods inherited from Constraint
Constructor Details
#initialize(regexp) ⇒ RegexpConstraint
Returns a new instance of RegexpConstraint.
8 9 10 11 |
# File 'lib/stronger_parameters/constraints/regexp_constraint.rb', line 8 def initialize(regexp) @regexp = regexp @string = StringConstraint.new end |
Instance Attribute Details
#regexp ⇒ Object (readonly)
Returns the value of attribute regexp.
6 7 8 |
# File 'lib/stronger_parameters/constraints/regexp_constraint.rb', line 6 def regexp @regexp end |
Instance Method Details
#==(other) ⇒ Object
23 24 25 |
# File 'lib/stronger_parameters/constraints/regexp_constraint.rb', line 23 def ==(other) super && regexp == other.regexp end |
#value(v) ⇒ Object
13 14 15 16 17 18 19 20 21 |
# File 'lib/stronger_parameters/constraints/regexp_constraint.rb', line 13 def value(v) v = @string.value(v) return v if v.is_a?(InvalidValue) if v =~ regexp v else InvalidValue.new(v, "must match #{regexp.source}") end end |