Class: CodinRep::EmployeeCommand

Inherits:
Command
  • Object
show all
Defined in:
lib/codin_rep/employee_command.rb

Direct Known Subclasses

AddEmployee, DelEmployee

Defined Under Namespace

Classes: InvalidInteger, UnknownEmployeeOperation

Constant Summary collapse

CODE_MAX_SIZE =
12

Constants inherited from Command

Command::COMMAND_PREFIX

Instance Method Summary collapse

Methods inherited from Command

#generate_command_payload, #generate_header, #get_max_attempts, #get_timeout_time, #should_close_connection?

Constructor Details

#initialize(*args) ⇒ EmployeeCommand

Returns a new instance of EmployeeCommand.



47
48
49
50
# File 'lib/codin_rep/employee_command.rb', line 47

def initialize(*args)
  super(*args)
  @sent_registration = false
end

Instance Method Details

#check_response_headerObject



72
73
74
75
76
# File 'lib/codin_rep/employee_command.rb', line 72

def check_response_header
  unless @response.match(/^#{self.class::EXPECTED_HEADER}/)
    raise UnknownHeader.new @response[0..6], 'get time', self.class::EXPECTED_HEADER
  end
end

#executeObject



52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/codin_rep/employee_command.rb', line 52

def execute
  @command_data = generate_header
  @command_data += generate_command_payload
  @response = communicate!
  check_response_header
  @sent_registration = true
  @command_data = self.class::REGISTRATION_COMPLETED_HEADER
  @response = communicate!
  return get_data_from_response_payload
rescue
  @communication.close
  raise
ensure
  @communication.close if should_close_connection?
end

#get_data_from_response_payloadObject



82
83
84
# File 'lib/codin_rep/employee_command.rb', line 82

def get_data_from_response_payload
  true
end

#get_expected_response_sizeObject



68
69
70
# File 'lib/codin_rep/employee_command.rb', line 68

def get_expected_response_size
  @sent_registration ? 0 : 9
end

#get_response_payloadObject



78
79
80
# File 'lib/codin_rep/employee_command.rb', line 78

def get_response_payload
  @sent_employee_data = true
end