Module: RuneRb::IO::Validation

Extended by:
Utils::Logging
Defined in:
lib/rrb/io/validation.rb

Overview

A module used for validating data operations performed on buffer objects.

Since:

  • 0.0.1

Constant Summary

Constants included from Utils::Logging

Utils::Logging::LOG_FILE_PATH

Class Method Summary collapse

Methods included from Utils::Logging

class_name, err, err!, log, log!

Class Method Details

.from_io(io, length, buffer) ⇒ Object

Reads data directly from an IO stream.

Parameters:

  • io (Socket, IO)

    the IO object to read from.

  • length (Integer)

    the amount of data to read

  • buffer (Buffer)

    the buffer to read to.

Since:

  • 0.0.1



27
28
29
30
31
# File 'lib/rrb/io/validation.rb', line 27

def from_io(io, length, buffer)
  raise 'Closed IO' if io.closed?

  io.read_nonblock(length, buffer.data)
end

.validate(buffer, operation, params = {}) ⇒ Object

TODO:

implement a ValidationError type to be raised when a validation fails.

Validates the passed parameters according to the options.

Parameters:

  • buffer (Buffer)

    the buffer to validate against.

  • operation (String)

    the operation to validate.

  • params (Hash) (defaults to: {})

    a map of parameters to validate.

Since:

  • 0.0.1



14
15
16
17
18
19
20
21
# File 'lib/rrb/io/validation.rb', line 14

def validate(buffer, operation, params = {})
  return false unless valid_mode?(buffer, operation)
  return false if buffer.mode.include?('w') && params[:bit_access] && !valid_access?(buffer, params[:bit_access])
  return false if params[:mutation] && !valid_mutation?(params[:mutation])
  return false if params[:order] && !valid_order?(params[:order])

  true
end