Class: BuildWatcher::FakeSerialPort

Inherits:
Object
  • Object
show all
Defined in:
lib/build_watcher/fake_serial_port.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFakeSerialPort

Returns a new instance of FakeSerialPort.



6
7
8
9
10
11
# File 'lib/build_watcher/fake_serial_port.rb', line 6

def initialize
  @projects = []
  @messages_sent = []
  @messages_received = []
  @serial_buffer = []
end

Instance Attribute Details

#messages_receivedObject (readonly)

Returns the value of attribute messages_received.



3
4
5
# File 'lib/build_watcher/fake_serial_port.rb', line 3

def messages_received
  @messages_received
end

#messages_sentObject (readonly)

Returns the value of attribute messages_sent.



3
4
5
# File 'lib/build_watcher/fake_serial_port.rb', line 3

def messages_sent
  @messages_sent
end

#projectsObject (readonly)

Returns the value of attribute projects.



3
4
5
# File 'lib/build_watcher/fake_serial_port.rb', line 3

def projects
  @projects
end

#read_timeoutObject

Returns the value of attribute read_timeout.



4
5
6
# File 'lib/build_watcher/fake_serial_port.rb', line 4

def read_timeout
  @read_timeout
end

Instance Method Details

#closeObject



38
# File 'lib/build_watcher/fake_serial_port.rb', line 38

def close; end

#puts(content) ⇒ Object

If an array is passed in, the first element is “sent” and the second element is added to the list of messages recieved



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/build_watcher/fake_serial_port.rb', line 20

def puts(content)
  message, response = content
  @messages_sent << message

  unless response.nil?
    @messages_received << response
    @serial_buffer << response
  end

  message
end

#readObject



32
33
34
35
36
# File 'lib/build_watcher/fake_serial_port.rb', line 32

def read
  buffers_contents = @serial_buffer.join
  @serial_buffer = []
  buffers_contents
end

#register_project(public_key, private_key) ⇒ Object



13
14
15
# File 'lib/build_watcher/fake_serial_port.rb', line 13

def register_project(public_key, private_key)
  @projects << [public_key, private_key]
end