Class: ZodRails::Introspection::ValidationInfo
- Inherits:
-
Object
- Object
- ZodRails::Introspection::ValidationInfo
- Defined in:
- lib/zod_rails/introspection/validation_info.rb
Constant Summary collapse
- CONDITIONAL_KEYS =
%i[if unless on].freeze
Instance Attribute Summary collapse
-
#attribute ⇒ Object
readonly
Returns the value of attribute attribute.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
- #conditional? ⇒ Boolean
- #hash ⇒ Object
-
#initialize(kind:, attribute:, options:, conditional:) ⇒ ValidationInfo
constructor
A new instance of ValidationInfo.
Constructor Details
#initialize(kind:, attribute:, options:, conditional:) ⇒ ValidationInfo
Returns a new instance of ValidationInfo.
10 11 12 13 14 15 16 |
# File 'lib/zod_rails/introspection/validation_info.rb', line 10 def initialize(kind:, attribute:, options:, conditional:) @kind = kind @attribute = attribute @options = @conditional = conditional freeze end |
Instance Attribute Details
#attribute ⇒ Object (readonly)
Returns the value of attribute attribute.
8 9 10 |
# File 'lib/zod_rails/introspection/validation_info.rb', line 8 def attribute @attribute end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind.
8 9 10 |
# File 'lib/zod_rails/introspection/validation_info.rb', line 8 def kind @kind end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
8 9 10 |
# File 'lib/zod_rails/introspection/validation_info.rb', line 8 def @options end |
Class Method Details
.from_validator(validator, attribute) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/zod_rails/introspection/validation_info.rb', line 18 def self.from_validator(validator, attribute) opts = validator..dup conditional = CONDITIONAL_KEYS.any? { |key| opts.key?(key) } new( kind: validator.kind, attribute: attribute, options: opts.except(*CONDITIONAL_KEYS), conditional: conditional ) end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
34 35 36 37 38 39 40 |
# File 'lib/zod_rails/introspection/validation_info.rb', line 34 def ==(other) other.is_a?(self.class) && kind == other.kind && attribute == other.attribute && == other. && conditional? == other.conditional? end |
#conditional? ⇒ Boolean
30 31 32 |
# File 'lib/zod_rails/introspection/validation_info.rb', line 30 def conditional? @conditional end |
#hash ⇒ Object
43 44 45 |
# File 'lib/zod_rails/introspection/validation_info.rb', line 43 def hash [self.class, kind, attribute, , @conditional].hash end |