Class: SmartCore::Types::Primitive::InvariantControl::Chain Private

Inherits:
Object
  • Object
show all
Defined in:
lib/smart_core/types/primitive/invariant_control/chain.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

Version:

  • 0.8.0

Defined Under Namespace

Classes: Result

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name) ⇒ 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.

Parameters:

  • name (String)

Since:

  • 0.1.0



20
21
22
23
# File 'lib/smart_core/types/primitive/invariant_control/chain.rb', line 20

def initialize(name)
  @name = name.dup.tap(&:freeze)
  @invariants = []
end

Instance Attribute Details

#nameString (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:

  • (String)

Since:

  • 0.2.0



13
14
15
# File 'lib/smart_core/types/primitive/invariant_control/chain.rb', line 13

def name
  @name
end

Instance Method Details

#add_invariant(invariant) ⇒ 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.2.0



30
31
32
# File 'lib/smart_core/types/primitive/invariant_control/chain.rb', line 30

def add_invariant(invariant)
  invariants << invariant
end

#check(value, runtime_attributes) ⇒ SmartCore::Types::Primitive::InvariantControl::Chain::Result

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.

Parameters:

  • value (Any)
  • runtime_attributes (Array<Any>)

Returns:

Since:

  • 0.2.0

Version:

  • 0.3.0



41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/smart_core/types/primitive/invariant_control/chain.rb', line 41

def check(value, runtime_attributes)
  invariant_results = [].tap do |results|
    invariants.each do |invariant|
      result = invariant.check(value, runtime_attributes).tap { |res| results << res }
      break if result.failure?
    end
  end

  SmartCore::Types::Primitive::InvariantControl::Chain::Result.new(
    self, value, invariant_results
  )
end

#simply_check(value, runtime_attributes) ⇒ Boolean

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.

Parameters:

  • value (Any)
  • runtime_attributes (Array<Any>)

Returns:

  • (Boolean)

Since:

  • 0.8.0



60
61
62
63
64
# File 'lib/smart_core/types/primitive/invariant_control/chain.rb', line 60

def simply_check(value, runtime_attributes)
  (invariants.any? do |invariant|
    invariant.simply_check(value, runtime_attributes) == false
  end) ? false : true
end