class ActiveValidation::Verifier
Attributes
@note The corresponding model class
Main switch for this class. After switch, all installed validators remain in place, while new installations will be turned off.
@return [TrueClass, FalseClass]
If something go wrong or there is no any Manifests for selected class yet, to prevent DB flooding we just until the situation resolves. Here we can specify the period between the attempts
Stick manifest to specific version @return [Internal::Manifest]
@note Custom name formatter for Manifests
Contains Internal::Observers::Manifest
, which store everything about used manifests
@return [Internal::Observers::Manifest]
@note Orm adapter for exactly this verifier instance
Name of the folder, where all validations method should be scoped. Inside, in corresponding sub-folder with version name shall be stored validation related methods
Public Class Methods
# File lib/active_validation/verifier.rb, line 55 def initialize(base_klass) config.verifier_defaults.call self @base_klass = base_klass.to_s @orm_adapter ||= config.orm_adapter @manifest_name_formatter ||= config.manifest_name_formatter @validations_module_name ||= "Validations" @enabled ||= true @failed_attempt_retry_time ||= 1.day yield self if block_given? @observer = Internal::Observers::Manifest.new self self.class.registry.register base_klass, self end
Shortcut for the global verifiers registry instance @return [Registry]
# File lib/active_validation/verifier.rb, line 8 def registry ActiveValidation.config.verifiers_registry end
Public Instance Methods
Forward the normalized request to ORM mapper For the name field we calculate default value
param [Hash] @return [Internal::Manifest, Array<Internal::Manifest>]
# File lib/active_validation/verifier.rb, line 126 def add_manifest(**hash) add_defaults_for_orm_adapter(hash) do |**h| h[:name] ||= manifest_name_formatter.call(base_klass) orm_adapter.public_send :add_manifest, h end end
@return [Class]
# File lib/active_validation/verifier.rb, line 96 def base_class base_klass.is_a?(Class) ? base_klass : base_klass.constantize end
@return [Internal::Manifest]
# File lib/active_validation/verifier.rb, line 91 def current_manifest manifest or find_manifests.first end
Return the list af parents with active_validation @return [Array]
# File lib/active_validation/verifier.rb, line 102 def descendants_with_active_validation [].tap do |descendants| k = base_class.superclass while k.respond_to?(:active_validation) && k.instance_methods.include?(:manifest) descendants << k k = k.superclass end end end
# File lib/active_validation/verifier.rb, line 45 def enabled?; !!enabled; end
Install parent models and self
Return Symbol Installation status
# File lib/active_validation/verifier.rb, line 115 def install!(*args) descendants_with_active_validation.each { |klass| klass.active_validation.install } install(*args) end
@!group Manual version lock
# File lib/active_validation/verifier.rb, line 79 def version @version ||= versions.last end
# File lib/active_validation/verifier.rb, line 83 def version=(other) @version = versions.detect { |a| a == ActiveValidation::Values::Version.new(other) } or raise ArgumentError, "Version #{other} not found" end
@return [Array<Value::Version>] Sorted list of versions.
# File lib/active_validation/verifier.rb, line 71 def versions base_class.const_get(validations_module_name) .constants.map { |k| ActiveValidation::Values::Version.new(k) }.sort rescue NameError [] end
Private Instance Methods
# File lib/active_validation/verifier.rb, line 144 def add_defaults_for_orm_adapter(**hash) hash[:base_klass] ||= base_klass hash[:version] ||= version if version block_given? ? yield(hash) : hash end