Class: RFunk::ErrorChecking

Inherits:
Object
  • Object
show all
Defined in:
lib/rfunk/attribute/error_checking.rb

Instance Method Summary collapse

Instance Method Details

#raise_condition_error(type, value) ⇒ Object

Raises:

  • (type)

3
4
5
# File 'lib/rfunk/attribute/error_checking.rb', line 3

def raise_condition_error(type, value)
  raise type, 'The condition was not met!' unless value
end

#raise_expected_attribute_type(name, value, types) ⇒ Object


11
12
13
# File 'lib/rfunk/attribute/error_checking.rb', line 11

def raise_expected_attribute_type(name, value, types)
  raise_return_type_with_message name, value, types, 'attribute'
end

#raise_expected_parameter_type(name, value, types) ⇒ Object


15
16
17
# File 'lib/rfunk/attribute/error_checking.rb', line 15

def raise_expected_parameter_type(name, value, types)
  raise_return_type_with_message name, value, types, 'parameter'
end

#raise_expected_return_type(name, value, types) ⇒ Object


7
8
9
# File 'lib/rfunk/attribute/error_checking.rb', line 7

def raise_expected_return_type(name, value, types)
  raise_return_type_with_message name, value, types, 'return'
end

#raise_immutable(options, variable) ⇒ Object


26
27
28
29
30
# File 'lib/rfunk/attribute/error_checking.rb', line 26

def raise_immutable(options, variable)
  keys = options.keys.select { |k| variable.key?(k) }
  message = "Could not rebind a value '#{keys}', because they are immutable."
  raise RFunk::ImmutableError, message if keys.any?
end

#raise_not_found(key, attributes) ⇒ Object


19
20
21
22
23
24
# File 'lib/rfunk/attribute/error_checking.rb', line 19

def raise_not_found(key, attributes)
  return if attributes.key?(key)

  message = "Attribute with name '#{key}' does not exist. The only available attributes are '#{attributes.keys}'"
  raise RFunk::NotFoundError, message
end