Class: ActiveValidation::Internal::Models::Manifest
- Inherits:
-
Object
- Object
- ActiveValidation::Internal::Models::Manifest
- Defined in:
- lib/active_validation/internal/models/manifest.rb,
lib/active_validation/internal/models/manifest/installer.rb
Defined Under Namespace
Classes: Installer
Instance Attribute Summary collapse
-
#base_klass ⇒ Object
readonly
Returns the value of attribute base_klass.
-
#checks ⇒ Object
readonly
Returns the value of attribute checks.
-
#created_at ⇒ Object
readonly
Returns the value of attribute created_at.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#other ⇒ Object
readonly
Returns the value of attribute other.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #==(other) ⇒ Object
-
#as_json(only: %i[version base_klass checks name id],, **options) ⇒ Hash
ActiveSupport#as_json interface Supported options: :only [Array<Symbol>, Symbol] select only listed elements.
- #base_class ⇒ Object
-
#context ⇒ String
Formatted context, as it will be stored on ‘on` option with the validations.
-
#initialize(version:, base_klass:, checks: [], options: {}, **other) ⇒ Manifest
constructor
A new instance of Manifest.
-
#install ⇒ Object
rubocop:disable Naming/MemoizedInstanceVariableName.
-
#installed? ⇒ TrueClass, FalseClass
Are the callbacks installed to the ‘base_class`?.
- #to_hash ⇒ Object
- #to_internal_manifest ⇒ Object
-
#uninstall ⇒ Object
rubocop:enable Naming/MemoizedInstanceVariableName.
Constructor Details
#initialize(version:, base_klass:, checks: [], options: {}, **other) ⇒ Manifest
Returns a new instance of Manifest.
28 29 30 31 32 33 34 35 36 37 38 |
# 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 = .to_h. end |
Instance Attribute Details
#base_klass ⇒ Object (readonly)
Returns the value of attribute base_klass.
9 10 11 |
# File 'lib/active_validation/internal/models/manifest.rb', line 9 def base_klass @base_klass end |
#checks ⇒ Object (readonly)
Returns the value of attribute checks.
9 10 11 |
# File 'lib/active_validation/internal/models/manifest.rb', line 9 def checks @checks end |
#created_at ⇒ Object (readonly)
Returns the value of attribute created_at.
9 10 11 |
# File 'lib/active_validation/internal/models/manifest.rb', line 9 def created_at @created_at end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/active_validation/internal/models/manifest.rb', line 9 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
9 10 11 |
# File 'lib/active_validation/internal/models/manifest.rb', line 9 def name @name end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
9 10 11 |
# File 'lib/active_validation/internal/models/manifest.rb', line 9 def @options end |
#other ⇒ Object (readonly)
Returns the value of attribute other.
9 10 11 |
# File 'lib/active_validation/internal/models/manifest.rb', line 9 def other @other end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
9 10 11 |
# File 'lib/active_validation/internal/models/manifest.rb', line 9 def version @version end |
Instance Method Details
#==(other) ⇒ Object
40 41 42 43 44 45 46 47 |
# 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 && == other. && checks == other.checks end |
#as_json(only: %i[version base_klass checks name id],, **options) ⇒ Hash
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
89 90 91 92 93 94 95 96 97 98 99 100 |
# File 'lib/active_validation/internal/models/manifest.rb', line 89 def as_json(only: %i[version base_klass checks name id], **) only = Array(only) {}.tap do |acc| .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 ⇒ Object
49 50 51 |
# File 'lib/active_validation/internal/models/manifest.rb', line 49 def base_class base_klass.constantize end |
#context ⇒ String
Formatted context, as it will be stored on ‘on` option with the validations
110 111 112 |
# File 'lib/active_validation/internal/models/manifest.rb', line 110 def context @context ||= ActiveValidation.config.validation_context_formatter.call self end |
#install ⇒ Object
rubocop:disable Naming/MemoizedInstanceVariableName
58 59 60 |
# File 'lib/active_validation/internal/models/manifest.rb', line 58 def install @installed ||= installer.install end |
#installed? ⇒ TrueClass, FalseClass
Are the callbacks installed to the ‘base_class`?
72 73 74 |
# File 'lib/active_validation/internal/models/manifest.rb', line 72 def installed? !!@installed end |
#to_hash ⇒ Object
53 54 55 |
# File 'lib/active_validation/internal/models/manifest.rb', line 53 def to_hash as_json end |
#to_internal_manifest ⇒ Object
102 103 104 |
# File 'lib/active_validation/internal/models/manifest.rb', line 102 def to_internal_manifest self end |
#uninstall ⇒ Object
rubocop:enable Naming/MemoizedInstanceVariableName
63 64 65 66 67 |
# File 'lib/active_validation/internal/models/manifest.rb', line 63 def uninstall return false unless installed? @installed = installer.uninstall end |