Class: RestMyCase::Validator

Inherits:
Base
  • Object
show all
Extended by:
AccusationAttorneys::HelperMethods, ClassMethods
Defined in:
lib/rest_my_case/validator.rb

Defined Under Namespace

Modules: ClassMethods

Instance Attribute Summary

Attributes included from ClassMethods

#validators

Attributes inherited from Base

#context, #options

Attributes included from Config::Base

#parent_dependencies_first, #silence_dependencies_abort

Instance Method Summary collapse

Methods included from ClassMethods

validate, validates_with

Methods included from AccusationAttorneys::HelperMethods

_merge_attributes, validates_format_of, validates_length_of, validates_numericality_of, validates_presence_of

Methods inherited from Base

#abort, #abort!, context_accessor, context_reader, context_writer, dependencies, depends, #error, #error!, #final, #initialize, #invoke, #invoke!, perform, required_context, required_context_schema, #rollback, #setup, #skip, #skip!, trial_court, #validate_context, #validate_context!

Constructor Details

This class inherits a constructor from RestMyCase::Base

Instance Method Details

#parent_targetObject



67
68
69
70
# File 'lib/rest_my_case/validator.rb', line 67

def parent_target
  @parent_target ||=
    target_options[:in] ? get_target(target_options[:in]) : nil
end

#performObject



86
87
88
89
90
91
92
93
94
# File 'lib/rest_my_case/validator.rb', line 86

def perform
  targets = [*target]

  return if Helpers.blank?(targets) || all_validations_green?(targets)

  parent_target.errors.add(target_options[:name], :invalid) if parent_target

  error('unprocessable_entity')
end

#targetObject



72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/rest_my_case/validator.rb', line 72

def target
  return nil if target_options[:name].nil?

  target_content = get_target(target_options[:name])

  if parent_target
    extend_errors_if_necessary(parent_target)

    target_content ||= parent_target.send(target_options[:name])
  end

  target_content
end

#target_optionsObject



63
64
65
# File 'lib/rest_my_case/validator.rb', line 63

def target_options
  self.class.target_options || {}
end