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

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

Modules: Factory Classes: Chain, Result, Single

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(invariant_chains, invariants) ⇒ 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:

Since:

  • 0.2.0



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

def initialize(invariant_chains, invariants)
  @invariant_chains = invariant_chains
  @invariants = invariants
end

Class Method Details

.create(invariant_chains, invariants) ⇒ SmartCore::Types::Primitive::InvariantControl

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:

  • invariant_chains (Hash<String,Array<Proc>>)
  • invariants (Hash<String,Proc>)

Returns:

Since:

  • 0.2.0



19
20
21
# File 'lib/smart_core/types/primitive/invariant_control.rb', line 19

def create(invariant_chains, invariants)
  Factory.create(invariant_chains, invariants)
end

Instance Method Details

#check(value, runtime_attributes) ⇒ SmartCore::Types::Primitive::InvariantControl::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



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

def check(value, runtime_attributes)
  Result.new(self, value).tap do |result|
    invariant_chains.each do |chain|
      result.add_chain_result(chain.check(value, runtime_attributes))
    end

    invariants.each do |invariant|
      result.add_single_result(invariant.check(value, runtime_attributes))
    end
  end
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
65
66
67
68
69
70
# File 'lib/smart_core/types/primitive/invariant_control.rb', line 60

def simply_check(value, runtime_attributes)
  return false if invariant_chains.any? do |chain|
    chain.simply_check(value, runtime_attributes) == false
  end

  return false if invariants.any? do |invariant|
    invariant.simply_check(value, runtime_attributes) == false
  end

  true
end