Module: LZWS::Validation

Defined in:
lib/lzws/validation.rb

Constant Summary collapse

IO_METHODS =
%i[
  read
  write
  readpartial
  read_nonblock
  write_nonblock
  eof?
  flush
  close
  closed?
]
.freeze

Class Method Summary collapse

Class Method Details

.validate_bool(value) ⇒ Object

Raises:



21
22
23
# File 'lib/lzws/validation.rb', line 21

def self.validate_bool(value)
  raise ValidateError, "invalid bool" unless value.is_a?(::TrueClass) || value.is_a?(::FalseClass)
end

.validate_hash(value) ⇒ Object

Raises:



41
42
43
# File 'lib/lzws/validation.rb', line 41

def self.validate_hash(value)
  raise ValidateError, "invalid hash" unless value.is_a? ::Hash
end

.validate_io(value) ⇒ Object

Raises:



37
38
39
# File 'lib/lzws/validation.rb', line 37

def self.validate_io(value)
  raise ValidateError, "invalid io" unless IO_METHODS.all? { |method| value.respond_to? method }
end

.validate_not_negative_integer(value) ⇒ Object

Raises:



29
30
31
# File 'lib/lzws/validation.rb', line 29

def self.validate_not_negative_integer(value)
  raise ValidateError, "invalid not negative integer" unless value.is_a?(::Integer) && value >= 0
end

.validate_positive_integer(value) ⇒ Object

Raises:



25
26
27
# File 'lib/lzws/validation.rb', line 25

def self.validate_positive_integer(value)
  raise ValidateError, "invalid positive integer" unless value.is_a?(::Integer) && value.positive?
end

.validate_proc(value) ⇒ Object



45
46
47
48
49
# File 'lib/lzws/validation.rb', line 45

def self.validate_proc(value)
  unless value.is_a?(::Proc) || value.is_a?(::Method) || value.is_a?(::UnboundMethod)
    raise ValidateError, "invalid proc"
  end
end

.validate_string(value) ⇒ Object

Raises:



33
34
35
# File 'lib/lzws/validation.rb', line 33

def self.validate_string(value)
  raise ValidateError, "invalid string" unless value.is_a? ::String
end