Class: ActiveValidation::Internal::Models::Check
- Inherits:
-
Object
- Object
- ActiveValidation::Internal::Models::Check
- Defined in:
- lib/active_validation/internal/models/check.rb
Instance Attribute Summary collapse
-
#argument ⇒ Object
readonly
Returns the value of attribute argument.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#method_name ⇒ Object
readonly
Returns the value of attribute method_name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
Instance Method Summary collapse
- #==(other) ⇒ Object
- #as_json(only: %i[method_name argument options],, **_options) ⇒ Object
-
#initialize(method_name:, argument:, options: {}, created_at: nil, **_other) ⇒ Check
constructor
A new instance of Check.
- #normalized_argument ⇒ Object
- #to_hash ⇒ Object
- #to_internal_check ⇒ Object
- #to_validation_arguments(context: nil) ⇒ Object
Constructor Details
#initialize(method_name:, argument:, options: {}, created_at: nil, **_other) ⇒ Check
Returns a new instance of Check.
8 9 10 11 12 13 |
# File 'lib/active_validation/internal/models/check.rb', line 8 def initialize(method_name:, argument:, options: {}, created_at: nil, **_other) @method_name = registry.find_or_add method_name @argument = argument @options = .to_h.deep_symbolize_keys @created_at = created_at end |
Instance Attribute Details
#argument ⇒ Object (readonly)
Returns the value of attribute argument.
7 8 9 |
# File 'lib/active_validation/internal/models/check.rb', line 7 def argument @argument end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
7 8 9 |
# File 'lib/active_validation/internal/models/check.rb', line 7 def created_at @created_at end |
#method_name ⇒ Object (readonly)
Returns the value of attribute method_name.
7 8 9 |
# File 'lib/active_validation/internal/models/check.rb', line 7 def method_name @method_name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
7 8 9 |
# File 'lib/active_validation/internal/models/check.rb', line 7 def @options end |
Instance Method Details
#==(other) ⇒ Object
15 16 17 18 19 |
# File 'lib/active_validation/internal/models/check.rb', line 15 def ==(other) method_name == other.method_name && argument == other.argument && == other. end |
#as_json(only: %i[method_name argument options],, **_options) ⇒ Object
25 26 27 |
# File 'lib/active_validation/internal/models/check.rb', line 25 def as_json(only: %i[method_name argument options], **) only.each_with_object({}) { |el, acc| acc[el.to_sym] = public_send(el).as_json } end |
#normalized_argument ⇒ Object
33 34 35 |
# File 'lib/active_validation/internal/models/check.rb', line 33 def normalized_argument method_name.to_sym == :validates_with ? argument.to_s.constantize : argument.to_sym end |
#to_hash ⇒ Object
21 22 23 |
# File 'lib/active_validation/internal/models/check.rb', line 21 def to_hash as_json end |
#to_internal_check ⇒ Object
29 30 31 |
# File 'lib/active_validation/internal/models/check.rb', line 29 def to_internal_check self end |
#to_validation_arguments(context: nil) ⇒ Object
37 38 39 40 41 |
# File 'lib/active_validation/internal/models/check.rb', line 37 def to_validation_arguments(context: nil) [method_name.to_sym, normalized_argument, .merge(on: context) { |_, old, new| Array(new) + Array(old) }] end |