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_type(name, value, type) ⇒ Object



7
8
9
10
11
12
13
14
15
# File 'lib/rfunk/attribute/error_checking.rb', line 7

def raise_expected_type(name, value, type)
  case value
  when Some
    expected_type?(name, value.value, type)
  when None
  else
    expected_type?(name, value, type)
  end
end

#raise_immutable(options, variable) ⇒ Object

Raises:



24
25
26
27
28
# File 'lib/rfunk/attribute/error_checking.rb', line 24

def raise_immutable(options, variable)
  keys = options.keys.select { |k| variable.has_key?(k) }
  message = "Could not set variables '#{keys}', because variables are immutable."
  raise ImmutableError, message if keys.any?
end

#raise_not_found(key, attributes) ⇒ Object



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

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