Class: Brut::FrontEnd::Forms::ConstraintViolation
- Inherits:
-
Object
- Object
- Brut::FrontEnd::Forms::ConstraintViolation
- Defined in:
- lib/brut/front_end/forms/constraint_violation.rb
Overview
Represents a specific error with a field. Essentially wraps an i18n key fragment and interpolated values for use with other form-related classes.
Instance Attribute Summary collapse
-
#context ⇒ Hash
readonly
Interpolated values useful in rendering the actual message.
-
#key ⇒ String
readonly
The key fragment representing the violation.
Instance Method Summary collapse
-
#client_side? ⇒ true|false
True if this violation is a client-side violation.
-
#initialize(key:, context:, server_side: :based_on_key) ⇒ ConstraintViolation
constructor
Create a constraint violations.
-
#to_s ⇒ Object
Constructor Details
#initialize(key:, context:, server_side: :based_on_key) ⇒ ConstraintViolation
Create a constraint violations
If true
, #client_side? will return false no matter what.
16 17 18 19 20 21 22 23 |
# File 'lib/brut/front_end/forms/constraint_violation.rb', line 16 def initialize(key:,context:, server_side: :based_on_key) @key = key.to_s @client_side = Brut::FrontEnd::Forms::ValidityState::KEYS.include?(@key) && server_side != true @context = context || {} if !@context.kind_of?(Hash) raise "#{self.class} created for key #{key} with an invalid context: '#{context}/#{context.class}'. Context must be nil or a hash" end end |
Instance Attribute Details
#context ⇒ Hash (readonly)
Returns interpolated values useful in rendering the actual message.
8 9 10 |
# File 'lib/brut/front_end/forms/constraint_violation.rb', line 8 def context @context end |
#key ⇒ String (readonly)
Returns the key fragment representing the violation.
6 7 8 |
# File 'lib/brut/front_end/forms/constraint_violation.rb', line 6 def key @key end |
Instance Method Details
#client_side? ⇒ true|false
Returns true if this violation is a client-side violation.
26 |
# File 'lib/brut/front_end/forms/constraint_violation.rb', line 26 def client_side? = @client_side |
#to_s ⇒ Object
27 |
# File 'lib/brut/front_end/forms/constraint_violation.rb', line 27 def to_s = @key |