Class: SmartCore::Validator Private

Inherits:
Object
  • Object
show all
Extended by:
DSL
Defined in:
lib/smart_core/validator.rb,
lib/smart_core/validator/dsl.rb,
lib/smart_core/validator/invoker.rb,
lib/smart_core/validator/error_set.rb,
lib/smart_core/validator/exceptions.rb,
lib/smart_core/validator/instance_builder.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Since:

  • 0.2.0

Defined Under Namespace

Modules: Commands, DSL Classes: Attribute, AttributeSet, CommandSet, ErrorSet, InstanceBuilder, Invoker

Constant Summary collapse

Error =

Since:

  • 0.1.0

Class.new(SmartCore::Error)
IncorrectErrorCodeError =

Since:

  • 0.1.0

Class.new(Error)
IncorrectAttributeNameError =

Since:

  • 0.1.0

Class.new(Error)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from DSL

attribute, attributes, clear_commands, commands, extended, validate, validate_with

Constructor Details

#initialize(&block) ⇒ void

Since:

  • 0.1.0



44
# File 'lib/smart_core/validator.rb', line 44

def initialize(*, **, &block); end

Instance Attribute Details

#__validation_errors__SmartCore::Validator::ErrorSet (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

Since:

  • 0.1.0



38
39
40
# File 'lib/smart_core/validator.rb', line 38

def __validation_errors__
  @__validation_errors__
end

Class Method Details

.new(*arguments, **options, &block) ⇒ void

This method returns an undefined value.

Parameters:

  • arguments (Any)
  • options (Hash<Symbol,Object>)
  • block (Proc)

Since:

  • 0.1.0



27
28
29
30
31
# File 'lib/smart_core/validator.rb', line 27

def new(*arguments, **options, &block)
  allocate.tap do |object|
    InstanceBuilder.call(object, self, arguments, options, block)
  end
end

Instance Method Details

#__append_errors__(error_set) ⇒ void

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

This method returns an undefined value.

Parameters:

Since:

  • 0.1.0



73
74
75
76
77
# File 'lib/smart_core/validator.rb', line 73

def __append_errors__(error_set)
  __thread_safe_access__ do
    __validation_errors__.concat(error_set)
  end
end

#__attributes__Hash<Symbol,Object>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Hash<Symbol,Object>)

Since:

  • 0.1.0



83
84
85
86
87
88
89
# File 'lib/smart_core/validator.rb', line 83

def __attributes__
  __thread_safe_access__ do
    self.class.attributes.each_with_object({}) do |attribute, accumulator|
      accumulator[attribute.name] = instance_variable_get("@#{attribute.name}")
    end
  end
end

#errorsArray<Symbol>

Returns:

  • (Array<Symbol>)

Since:

  • 0.1.0



62
63
64
65
66
# File 'lib/smart_core/validator.rb', line 62

def errors
  __thread_safe_access__ do
    __validation_errors__.codes
  end
end

#valid?Boolean

Returns:

  • (Boolean)

Since:

  • 0.1.0



50
51
52
53
54
55
56
# File 'lib/smart_core/validator.rb', line 50

def valid?
  __thread_safe_invokation__ do
    __validation_errors__.clear
    self.class.commands.each { |command| command.call(self) }
    __validation_errors__.empty?
  end
end