Class: Krakow::Command

Inherits:
Object
  • Object
show all
Includes:
Utils::Lazy
Defined in:
lib/krakow/command.rb,
lib/krakow/command/cls.rb,
lib/krakow/command/fin.rb,
lib/krakow/command/nop.rb,
lib/krakow/command/pub.rb,
lib/krakow/command/rdy.rb,
lib/krakow/command/req.rb,
lib/krakow/command/sub.rb,
lib/krakow/command/auth.rb,
lib/krakow/command/mpub.rb,
lib/krakow/command/touch.rb,
lib/krakow/command/identify.rb

Overview

Messages for sending to remote server

Direct Known Subclasses

Auth, Cls, Fin, Identify, Mpub, Nop, Pub, Rdy, Req, Sub, Touch

Defined Under Namespace

Classes: Auth, Cls, Fin, Identify, Mpub, Nop, Pub, Rdy, Req, Sub, Touch

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Utils::Lazy

included

Methods included from Utils::Logging

level=, #log

Instance Attribute Details

#responseKrakow::FrameType

Returns response to command.

Returns:



58
59
60
# File 'lib/krakow/command.rb', line 58

def response
  @response
end

Class Method Details

.errorArray<String>

Allowed ERROR return values

Returns:

  • (Array<String>)


35
36
37
# File 'lib/krakow/command.rb', line 35

def error
  []
end

.okArray<String>

Allowed OK return values

Returns:

  • (Array<String>)


28
29
30
# File 'lib/krakow/command.rb', line 28

def ok
  []
end

.response_for(message) ⇒ Symbol

Response type expected

Parameters:

  • message (Krakow::Message)

    message to check

Returns:

  • (Symbol)

    response expected (:none, :error_only, :required)



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/krakow/command.rb', line 43

def response_for(message)
  if(message.class.ok.empty?)
    if(message.class.error.empty?)
      :none
    else
      :error_only
    end
  else
    :required
  end
end

Instance Method Details

#error?(response) ⇒ TrueClass, FalseClass

Is response ERROR

Returns:

  • (TrueClass, FalseClass)


83
84
85
86
# File 'lib/krakow/command.rb', line 83

def error?(response)
  response = response.content if response.is_a?(FrameType)
  self.class.error.include?(response)
end

#nameString

Returns name of command.

Returns:

  • (String)

    name of command



61
62
63
# File 'lib/krakow/command.rb', line 61

def name
  self.class.name.split('::').last.upcase
end

#ok?(response) ⇒ TrueClass, FalseClass

Is response OK

Returns:

  • (TrueClass, FalseClass)


75
76
77
78
# File 'lib/krakow/command.rb', line 75

def ok?(response)
  response = response.content if response.is_a?(FrameType)
  self.class.ok.include?(response)
end

#to_line(*args) ⇒ String

Convert to line output

Returns:

  • (String)

    socket ready string



68
69
70
# File 'lib/krakow/command.rb', line 68

def to_line(*args)
  raise NotImplementedError.new 'No line conversion method defined!'
end