Sha256: 4e963453de0a6334c3916e60652d1bdb5491a9f31cc33b6e5390b26d3b8015ac

Contents?: true

Size: 992 Bytes

Versions: 33

Compression:

Stored size: 992 Bytes

Contents

# frozen_string_literal  = true

module Ree::Args
  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

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

  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

  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

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

Version data entries

33 entries across 33 versions & 1 rubygems

Version Path
ree-1.0.32 lib/ree/args.rb
ree-1.0.31 lib/ree/args.rb
ree-1.0.30 lib/ree/args.rb
ree-1.0.29 lib/ree/args.rb
ree-1.0.28 lib/ree/args.rb
ree-1.0.27 lib/ree/args.rb
ree-1.0.26 lib/ree/args.rb
ree-1.0.25 lib/ree/args.rb
ree-1.0.24 lib/ree/args.rb
ree-1.0.23 lib/ree/args.rb
ree-1.0.22 lib/ree/args.rb
ree-1.0.21 lib/ree/args.rb
ree-1.0.20 lib/ree/args.rb
ree-1.0.19 lib/ree/args.rb
ree-1.0.18 lib/ree/args.rb
ree-1.0.17 lib/ree/args.rb
ree-1.0.16 lib/ree/args.rb
ree-1.0.15 lib/ree/args.rb
ree-1.0.14 lib/ree/args.rb
ree-1.0.13 lib/ree/args.rb