Module: Ree::Args

Instance Method Summary collapse

Instance Method Details

#check_arg(value, name, klass) ⇒ Object



4
5
6
7
8
9
10
11
# File 'lib/ree/args.rb', line 4

def check_arg(value, name, klass)
  if !value.is_a?(klass)
    raise Ree::Error.new(
      ":#{name} should be a #{klass}. Got #{value.class}: #{Ree::StringUtils.truncate(value.inspect)}",
      :invalid_arg
    )
  end
end

#check_arg_any(value, name, klasses) ⇒ Object



23
24
25
26
27
# File 'lib/ree/args.rb', line 23

def check_arg_any(value, name, klasses)
  if !klasses.detect {|klass| value.is_a?(klass)}
    raise Ree::Error.new(":#{name} should be any of #{klasses.inspect}", :invalid_arg)
  end
end

#check_arg_array_of(value, name, klass) ⇒ Object



17
18
19
20
21
# File 'lib/ree/args.rb', line 17

def check_arg_array_of(value, name, klass)
  if !value.is_a?(Array) && value.detect { |_| !_.is_a?(Symbol)}
    raise Ree::Error.new(":#{name} should be array of #{klass.inspect}. Got #{value.class}: #{Ree::StringUtils.truncate(value.inspect)}", :invalid_arg)
  end
end

#check_bool(value, name) ⇒ Object



13
14
15
# File 'lib/ree/args.rb', line 13

def check_bool(value, name)
  check_arg_any(value, name, [TrueClass, FalseClass])
end

#not_nil(value, name) ⇒ Object



29
30
31
32
33
# File 'lib/ree/args.rb', line 29

def not_nil(value, name)
  if value.nil?
    raise Ree::Error(":#{name} should not be nil", :invalid_arg)
  end
end