Module: Callme::ArgsValidator

Defined in:
lib/callme/args_validator.rb

Overview

Helper class for arguments validation

Class Method Summary collapse

Class Method Details

.block_given!(block) ⇒ Object

Checks that specified block is given

Parameters:

  • block

    some block



43
44
45
46
47
# File 'lib/callme/args_validator.rb', line 43

def block_given!(block)
  unless block
    raise ArgumentError, "Block should be given"
  end
end

.has_key!(hash, key) ⇒ Object

Checks that specifid hash has a specified key

Parameters:

  • hash

    some hash

  • key

    hash’s key



35
36
37
38
39
# File 'lib/callme/args_validator.rb', line 35

def has_key!(hash, key)
  unless hash.has_key?(key)
    raise ArgumentError, "#{hash} should has #{key} key"
  end
end

.is_array!(obj, obj_name) ⇒ Object

Checks that specifid obj is an Array

Parameters:

  • obj

    some object

  • obj_name

    object’s name, used to clarify error causer in exception



17
18
19
20
21
# File 'lib/callme/args_validator.rb', line 17

def is_array!(obj, obj_name)
  unless obj.is_a?(Array)
    raise ArgumentError, "#{obj_name} should be an Array"
  end
end

.is_hash!(obj, obj_name) ⇒ Object

Checks that specifid obj is a Hash

Parameters:

  • obj

    some object

  • obj_name

    object’s name, used to clarify error causer in exception



26
27
28
29
30
# File 'lib/callme/args_validator.rb', line 26

def is_hash!(obj, obj_name)
  unless obj.is_a?(Hash)
    raise ArgumentError, "#{obj_name} should be a Hash"
  end
end

.is_symbol!(obj, obj_name) ⇒ Object

Checks that specifid obj is a symbol

Parameters:

  • obj

    some object

  • obj_name

    object’s name, used to clarify error causer in exception



8
9
10
11
12
# File 'lib/callme/args_validator.rb', line 8

def is_symbol!(obj, obj_name)
  unless obj.is_a?(Symbol)
    raise ArgumentError, "#{obj_name} should be a Symbol"
  end
end