codin_rep 0.1.0 → 0.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/codin_rep/mock_time_clock.rb +186 -0
- data/lib/codin_rep/version.rb +1 -1
- data/test/coverage/index.html +1164 -10
- data/test/coverage/rcov/index.html +25 -9
- data/test/coverage/rcov/lib-codin_rep-add_employee_rb.html +1 -1
- data/test/coverage/rcov/lib-codin_rep-command_rb.html +1 -1
- data/test/coverage/rcov/lib-codin_rep-communication_rb.html +1 -1
- data/test/coverage/rcov/lib-codin_rep-del_employee_rb.html +1 -1
- data/test/coverage/rcov/lib-codin_rep-employee_command_rb.html +1 -1
- data/test/coverage/rcov/lib-codin_rep-get_afd_header_rb.html +1 -1
- data/test/coverage/rcov/lib-codin_rep-get_records_rb.html +1 -1
- data/test/coverage/rcov/lib-codin_rep-get_time_rb.html +1 -1
- data/test/coverage/rcov/lib-codin_rep-mock_time_clock_rb.html +617 -0
- data/test/coverage/rcov/lib-codin_rep-set_time_rb.html +1 -1
- data/test/coverage/rcov/lib-codin_rep-time_util_rb.html +1 -1
- data/test/coverage/rcov/lib-codin_rep-version_rb.html +2 -2
- data/test/coverage/rcov/lib-codin_rep_rb.html +1 -1
- data/test/test_helper.rb +1 -1
- data/test/unit/add_employee_test.rb +1 -1
- data/test/unit/del_employee_test.rb +1 -1
- data/test/unit/get_employer_test.rb +1 -1
- data/test/unit/get_records_test.rb +1 -1
- data/test/unit/get_serial_number_test.rb +1 -1
- data/test/unit/get_time_test.rb +1 -1
- data/test/unit/set_time_test.rb +1 -1
- metadata +5 -4
- data/test/mock_time_clock.rb +0 -184
@@ -236,7 +236,7 @@
|
|
236
236
|
</tbody>
|
237
237
|
</table>
|
238
238
|
|
239
|
-
<p>Generated on 2017-01-
|
239
|
+
<p>Generated on 2017-01-25 17:10:31 -0200 with <a href="https://github.com/fguillen/simplecov-rcov">SimpleCov-RCov 0.2.3</a></p>
|
240
240
|
|
241
241
|
</body>
|
242
242
|
</html>
|
@@ -206,7 +206,7 @@
|
|
206
206
|
</tbody>
|
207
207
|
</table>
|
208
208
|
|
209
|
-
<p>Generated on 2017-01-
|
209
|
+
<p>Generated on 2017-01-25 17:10:31 -0200 with <a href="https://github.com/fguillen/simplecov-rcov">SimpleCov-RCov 0.2.3</a></p>
|
210
210
|
|
211
211
|
</body>
|
212
212
|
</html>
|
@@ -114,7 +114,7 @@
|
|
114
114
|
<td><pre><a name="line22">22</a> module CodinRep</pre></td>
|
115
115
|
</tr>
|
116
116
|
<tr class="marked">
|
117
|
-
<td><pre><a name="line23">23</a> VERSION = "0.
|
117
|
+
<td><pre><a name="line23">23</a> VERSION = "0.2.0".freeze</pre></td>
|
118
118
|
</tr>
|
119
119
|
<tr class="inferred">
|
120
120
|
<td><pre><a name="line24">24</a> end</pre></td>
|
@@ -122,7 +122,7 @@
|
|
122
122
|
</tbody>
|
123
123
|
</table>
|
124
124
|
|
125
|
-
<p>Generated on 2017-01-
|
125
|
+
<p>Generated on 2017-01-25 17:10:31 -0200 with <a href="https://github.com/fguillen/simplecov-rcov">SimpleCov-RCov 0.2.3</a></p>
|
126
126
|
|
127
127
|
</body>
|
128
128
|
</html>
|
@@ -311,7 +311,7 @@
|
|
311
311
|
</tbody>
|
312
312
|
</table>
|
313
313
|
|
314
|
-
<p>Generated on 2017-01-
|
314
|
+
<p>Generated on 2017-01-25 17:10:31 -0200 with <a href="https://github.com/fguillen/simplecov-rcov">SimpleCov-RCov 0.2.3</a></p>
|
315
315
|
|
316
316
|
</body>
|
317
317
|
</html>
|
data/test/test_helper.rb
CHANGED
data/test/unit/get_time_test.rb
CHANGED
data/test/unit/set_time_test.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: codin_rep
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- O.S. Systems Softwares Ltda.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-01-
|
11
|
+
date: 2017-01-25 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: Use this gem to manage several features of the Telebyte eletronic timeclocks,
|
14
14
|
like report creation, user management, configuration etc.
|
@@ -26,6 +26,7 @@ files:
|
|
26
26
|
- lib/codin_rep/get_afd_header.rb
|
27
27
|
- lib/codin_rep/get_records.rb
|
28
28
|
- lib/codin_rep/get_time.rb
|
29
|
+
- lib/codin_rep/mock_time_clock.rb
|
29
30
|
- lib/codin_rep/set_time.rb
|
30
31
|
- lib/codin_rep/time_util.rb
|
31
32
|
- lib/codin_rep/version.rb
|
@@ -69,12 +70,12 @@ files:
|
|
69
70
|
- test/coverage/rcov/lib-codin_rep-get_identification_rb.html
|
70
71
|
- test/coverage/rcov/lib-codin_rep-get_records_rb.html
|
71
72
|
- test/coverage/rcov/lib-codin_rep-get_time_rb.html
|
73
|
+
- test/coverage/rcov/lib-codin_rep-mock_time_clock_rb.html
|
72
74
|
- test/coverage/rcov/lib-codin_rep-set_employee_rb.html
|
73
75
|
- test/coverage/rcov/lib-codin_rep-set_time_rb.html
|
74
76
|
- test/coverage/rcov/lib-codin_rep-time_util_rb.html
|
75
77
|
- test/coverage/rcov/lib-codin_rep-version_rb.html
|
76
78
|
- test/coverage/rcov/lib-codin_rep_rb.html
|
77
|
-
- test/mock_time_clock.rb
|
78
79
|
- test/reports/TEST-GetTimeTest.xml
|
79
80
|
- test/test_helper.rb
|
80
81
|
- test/unit/add_employee_test.rb
|
@@ -134,6 +135,7 @@ test_files:
|
|
134
135
|
- test/coverage/assets/0.10.0/colorbox/loading.gif
|
135
136
|
- test/coverage/assets/0.10.0/loading.gif
|
136
137
|
- test/coverage/assets/0.10.0/favicon_red.png
|
138
|
+
- test/coverage/rcov/lib-codin_rep-mock_time_clock_rb.html
|
137
139
|
- test/coverage/rcov/lib-codin_rep-communication_rb.html
|
138
140
|
- test/coverage/rcov/index.html
|
139
141
|
- test/coverage/rcov/lib-codin_rep_rb.html
|
@@ -155,7 +157,6 @@ test_files:
|
|
155
157
|
- test/coverage/rcov/lib-codin_rep-get_identification_rb.html
|
156
158
|
- test/coverage/rcov/lib-codin_rep-del_employee_rb.html
|
157
159
|
- test/test_helper.rb
|
158
|
-
- test/mock_time_clock.rb
|
159
160
|
- test/unit/add_employee_test.rb
|
160
161
|
- test/unit/get_employer_test.rb
|
161
162
|
- test/unit/set_time_test.rb
|
data/test/mock_time_clock.rb
DELETED
@@ -1,184 +0,0 @@
|
|
1
|
-
# -*- coding: utf-8 -*-
|
2
|
-
# codin_rep - Gem para acesso de REPs da Telebyte
|
3
|
-
# Copyright (C) 2016 O.S. Systems Softwares Ltda.
|
4
|
-
|
5
|
-
# This program is free software: you can redistribute it and/or modify
|
6
|
-
# it under the terms of the GNU Affero General Public License as
|
7
|
-
# published by the Free Software Foundation, either version 3 of the
|
8
|
-
# License, or (at your option) any later version.
|
9
|
-
|
10
|
-
# This program is distributed in the hope that it will be useful,
|
11
|
-
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12
|
-
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13
|
-
# GNU Affero General Public License for more details.
|
14
|
-
|
15
|
-
# You should have received a copy of the GNU Affero General Public License
|
16
|
-
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
17
|
-
|
18
|
-
# Rua Clóvis Gularte Candiota 132, Pelotas-RS, Brasil.
|
19
|
-
# e-mail: contato@ossystems.com.br
|
20
|
-
|
21
|
-
require 'codin_rep'
|
22
|
-
require 'codin_rep/time_util'
|
23
|
-
require 'socket'
|
24
|
-
|
25
|
-
class MockTimeClock
|
26
|
-
include CodinRep
|
27
|
-
|
28
|
-
attr_reader :data, :ip
|
29
|
-
|
30
|
-
def initialize
|
31
|
-
@data = OpenStruct.new
|
32
|
-
@ip = '127.0.0.1'
|
33
|
-
@server = TCPServer.new(@ip, 0)
|
34
|
-
@running = false
|
35
|
-
@served_connections = 0
|
36
|
-
@threads = []
|
37
|
-
@threadsMutex = Mutex.new
|
38
|
-
@served_connections = 0
|
39
|
-
@time = true
|
40
|
-
@is_sending_records = false
|
41
|
-
end
|
42
|
-
|
43
|
-
def tcp_port
|
44
|
-
@server.addr[1]
|
45
|
-
end
|
46
|
-
|
47
|
-
def serve(socket)
|
48
|
-
Thread.new do
|
49
|
-
Thread.current.abort_on_exception = true
|
50
|
-
@threadsMutex.synchronize {
|
51
|
-
@threads << Thread.current
|
52
|
-
@served_connections += 1
|
53
|
-
}
|
54
|
-
begin
|
55
|
-
raw_command = []
|
56
|
-
@keep_connected = true
|
57
|
-
@first_connection = true
|
58
|
-
# Read command type
|
59
|
-
while @keep_connected && raw_command = read_from_socket_with_timeout(socket, 9)
|
60
|
-
response = process_command(raw_command, socket)
|
61
|
-
socket.write response
|
62
|
-
@first_connection = false
|
63
|
-
end
|
64
|
-
ensure
|
65
|
-
socket.close unless socket.closed?
|
66
|
-
@threadsMutex.synchronize {
|
67
|
-
@threads.delete(Thread.current)
|
68
|
-
}
|
69
|
-
end
|
70
|
-
end
|
71
|
-
end
|
72
|
-
|
73
|
-
def start
|
74
|
-
@server_thread = Thread.new do
|
75
|
-
Thread.current.abort_on_exception = true
|
76
|
-
@running = true
|
77
|
-
while @running
|
78
|
-
break if @server.closed?
|
79
|
-
socket = @server.accept
|
80
|
-
serve(socket)
|
81
|
-
end
|
82
|
-
end
|
83
|
-
self
|
84
|
-
end
|
85
|
-
|
86
|
-
def stop
|
87
|
-
@threadsMutex.synchronize {
|
88
|
-
@threads.each{|thread| thread.kill}
|
89
|
-
@threads = []
|
90
|
-
}
|
91
|
-
@server_thread.kill if @server_thread
|
92
|
-
@server.close unless @server.closed?
|
93
|
-
@server_thread.join
|
94
|
-
@running = false
|
95
|
-
true
|
96
|
-
end
|
97
|
-
|
98
|
-
def running?
|
99
|
-
@running
|
100
|
-
end
|
101
|
-
|
102
|
-
private
|
103
|
-
def process_command(raw_command, socket)
|
104
|
-
case raw_command
|
105
|
-
when "PGREP009b" # Get time
|
106
|
-
response = 'REP008b' + get_timeclock_time
|
107
|
-
when "PGREP016A" # Set time
|
108
|
-
payload = read_from_socket_with_timeout(socket, 7)
|
109
|
-
response = 'REP008A' + payload
|
110
|
-
set_timeclock_time(payload)
|
111
|
-
when "PGREP009Z"
|
112
|
-
response = 'REP2359' + @data.afd.header.export + "\r\n"
|
113
|
-
@keep_connected = false
|
114
|
-
when "PGREP0289"
|
115
|
-
@afd_read_start_id = read_from_socket_with_timeout(socket, 9).to_i
|
116
|
-
@afd_read_end_id = read_from_socket_with_timeout(socket, 9).to_i
|
117
|
-
@afd_read_current_id = nil
|
118
|
-
@afd_read_finished = false
|
119
|
-
response = "REP0029["
|
120
|
-
when "PGREP009,"
|
121
|
-
if @afd_read_finished
|
122
|
-
response = "REP0029]"
|
123
|
-
@keep_connected = false
|
124
|
-
else
|
125
|
-
if @afd_read_current_id.nil?
|
126
|
-
@afd_read_current_id = @afd_read_start_id
|
127
|
-
response = 'REP3029'
|
128
|
-
elsif @afd_read_current_id == @afd_read_end_id or @afd_read_current_id >= @data.afd.records.size
|
129
|
-
response = 'REP0909'
|
130
|
-
@afd_read_finished = true
|
131
|
-
else
|
132
|
-
response = 'REP0379'
|
133
|
-
end
|
134
|
-
afd_records = ([@data.afd.header] + @data.afd.records)
|
135
|
-
response += afd_records[@afd_read_current_id].export + "\r\n"
|
136
|
-
end
|
137
|
-
@afd_read_current_id += 1
|
138
|
-
when "PGREP075h"
|
139
|
-
payload = read_from_socket_with_timeout(socket, 66)
|
140
|
-
raw_registration, raw_pis, raw_name = payload.scan(/.(.{6})(.{6})(.+)/).flatten
|
141
|
-
registration = convert_bytes_to_string(raw_registration)
|
142
|
-
pis = convert_bytes_to_string(raw_pis)
|
143
|
-
name = raw_name.strip
|
144
|
-
@data.employees << {name: name, pis: pis, registration: registration}
|
145
|
-
response = "REP003h1\0"
|
146
|
-
when "PGREP016j"
|
147
|
-
payload = read_from_socket_with_timeout(socket, 7)
|
148
|
-
raw_registration = payload.scan(/.(.{6})/).flatten[0]
|
149
|
-
registration = convert_bytes_to_string(raw_registration)
|
150
|
-
@data.employees.delete_if{|employee| employee[:registration] == registration}
|
151
|
-
response = "REP003j1\0"
|
152
|
-
when 'PGREP010h', 'PGREP010j'
|
153
|
-
# Don't care for the result of these comands, just disconnect when
|
154
|
-
# possible.
|
155
|
-
@keep_connected = false
|
156
|
-
response = ""
|
157
|
-
else
|
158
|
-
raise StandardError.new("Unknown command \"#{raw_command}\"!")
|
159
|
-
end
|
160
|
-
response
|
161
|
-
end
|
162
|
-
|
163
|
-
def read_from_socket_with_timeout(socket, bytes_to_be_read, timeout_value=5)
|
164
|
-
data_to_receive = nil
|
165
|
-
timeout_value = 600 if @first_connection # use a large timeout on first connection
|
166
|
-
timeout(timeout_value) { data_to_receive = socket.readpartial( bytes_to_be_read ) }
|
167
|
-
return data_to_receive
|
168
|
-
end
|
169
|
-
|
170
|
-
def get_timeclock_time(current_time=nil)
|
171
|
-
current_time ||= @data.time
|
172
|
-
CodinRep::TimeUtil.pack current_time
|
173
|
-
end
|
174
|
-
|
175
|
-
def set_timeclock_time(payload)
|
176
|
-
time = CodinRep::TimeUtil.unpack payload
|
177
|
-
@data.time = time
|
178
|
-
return time
|
179
|
-
end
|
180
|
-
|
181
|
-
def convert_bytes_to_string(bytes)
|
182
|
-
bytes.unpack('H*')[0]
|
183
|
-
end
|
184
|
-
end
|