Class: RFunk::ErrorChecking

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

Instance Method Summary collapse

Instance Method Details

#raise_expected_type(name, value, type) ⇒ Object



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

def raise_expected_type(name, value, type)
  unless value.is_a?(type)
    message = "Expected a type of '#{type}' for attribute '#{name}'"
    raise TypeError, message
  end
end

#raise_immutable(options, variable) ⇒ Object

Raises:



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

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



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

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