Module: Ruflow::TypeChecker

Defined in:
lib/ruflow/type_checker.rb

Class Method Summary collapse

Class Method Details

.compatible_types?(type, compare_type) ⇒ Boolean

Returns:

  • (Boolean)


7
8
9
10
11
12
13
# File 'lib/ruflow/type_checker.rb', line 7

def self.compatible_types?(type, compare_type)
  return true if compare_type.include? '*'

  compare_types = compare_type.split('|')

  type.split('|').any? { |t| compare_types.include?(t) }
end

.incompatible_types?(type, compare_type) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
# File 'lib/ruflow/type_checker.rb', line 3

def self.incompatible_types?(type, compare_type)
  !compatible_types?(type, compare_type)
end

.is_invalid?(value, type:) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'lib/ruflow/type_checker.rb', line 15

def self.is_invalid?(value, type:)
  !is_valid?(value, type: type)
end

.is_valid?(value, type:) ⇒ Boolean

Returns:

  • (Boolean)


19
20
21
22
23
24
25
# File 'lib/ruflow/type_checker.rb', line 19

def self.is_valid?(value, type:)
  return true if type.include? '*'

  types = type.split('|').map { |t| get_constant(t) }.flatten

  types.any? { |t| value.is_a?(t) }
end