class ActiveValidation::Internal::Models::Manifest

Attributes

base_klass[R]
checks[R]
created_at[R]
id[R]
name[R]
options[R]
other[R]
version[R]

Public Class Methods

new(version:, base_klass:, checks: [], options: {}, **other) click to toggle source

@param [Hash] Manifest options hash @option manifest_hash [String] :name Human readable name, by default build with selected

formatter for current manifest

@option manifest_hash [String, to_s] :base_klass (base_klass) Base klass for the Manifest @option manifest_hash [String, Symbol, Integer, Values::Version] :version (:current) Version

of the current manifest

@option manifest_hash [Internal::Check] :checks ([])

@example Add new manifest:

new({  name: 'Cool Manifest',
   version: 42,
   base_klass: 'Bar',
   checks: [
      { method_name: "validates", argument: "name", options: { presence: true } }
   ]})
# File lib/active_validation/internal/models/manifest.rb, line 28
def initialize(version:, base_klass:, checks: [], options: {}, **other)
  @version = ActiveValidation::Values::Version.new version
  @base_klass = base_klass.to_s
  @checks = Array(checks).map(&:to_internal_check)
  @other = ActiveSupport::OrderedOptions.new other

  @id = other[:id]
  @name = other[:name]
  @created_at = other[:created_at]
  @options = options.to_h.to_options!
end

Public Instance Methods

==(other) click to toggle source
# File lib/active_validation/internal/models/manifest.rb, line 40
def ==(other)
  return true if id == other.id

  version == other.version &&
    base_klass == other.base_klass &&
    options     == other.options &&
    checks      == other.checks
end
as_json(only: %i[version base_klass checks name id], **options) click to toggle source

ActiveSupport#as_json interface Supported options:

:only [Array<Symbol>, Symbol] select only listed elements

Nested elements accept options:

:only [Array<Symbol>, Symbol] select only listed elements
:as   [Symbol, String] in place rename for the column

@example

as_json(only: :version, checks: { as: :checks_attributes,
                                  only: [:argument] })

@return [Hash]

# File lib/active_validation/internal/models/manifest.rb, line 89
def as_json(only: %i[version base_klass checks name id], **options)
  only = Array(only)
  {}.tap do |acc|
    options.each_pair do |k, v|
      only.delete(k)
      as = v.delete(:as)
      key_name = (as || k).to_sym
      acc[key_name] = public_send(k).as_json(v)
    end
    only.each { |el| acc[el.to_sym] = public_send(el).as_json }
  end
end
base_class() click to toggle source
# File lib/active_validation/internal/models/manifest.rb, line 49
def base_class
  base_klass.constantize
end
context() click to toggle source

Formatted context, as it will be stored on `on` option with the validations

@return [String]

# File lib/active_validation/internal/models/manifest.rb, line 110
def context
  @context ||= ActiveValidation.config.validation_context_formatter.call self
end
install() click to toggle source

rubocop:disable Naming/MemoizedInstanceVariableName

# File lib/active_validation/internal/models/manifest.rb, line 58
def install
  @installed ||= installer.install
end
installed?() click to toggle source

Are the callbacks installed to the `base_class`?

@return [TrueClass, FalseClass]

# File lib/active_validation/internal/models/manifest.rb, line 72
def installed?
  !!@installed
end
to_hash() click to toggle source
# File lib/active_validation/internal/models/manifest.rb, line 53
def to_hash
  as_json
end
to_internal_manifest() click to toggle source
# File lib/active_validation/internal/models/manifest.rb, line 102
def to_internal_manifest
  self
end
uninstall() click to toggle source

rubocop:enable Naming/MemoizedInstanceVariableName

# File lib/active_validation/internal/models/manifest.rb, line 63
def uninstall
  return false unless installed?

  @installed = installer.uninstall
end

Private Instance Methods

installer() click to toggle source
# File lib/active_validation/internal/models/manifest.rb, line 116
def installer
  @installer ||= Installer.new(base_class: base_class, checks: checks, context: context)
end