Class: ActiveValidation::Internal::Models::Check

Inherits:
Object
  • Object
show all
Defined in:
lib/active_validation/internal/models/check.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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 = options.to_h.deep_symbolize_keys
  @created_at = created_at
end

Instance Attribute Details

#argumentObject (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_atObject (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_nameObject (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

#optionsObject (readonly)

Returns the value of attribute options.



7
8
9
# File 'lib/active_validation/internal/models/check.rb', line 7

def options
  @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 &&
    options     == other.options
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], **_options)
  only.each_with_object({}) { |el, acc| acc[el.to_sym] = public_send(el).as_json }
end

#normalized_argumentObject



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_hashObject



21
22
23
# File 'lib/active_validation/internal/models/check.rb', line 21

def to_hash
  as_json
end

#to_internal_checkObject



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,
   options.merge(on: context) { |_, old, new| Array(new) + Array(old) }]
end