mather-rb 0.0.4 → 0.0.7

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b277dd23874f7390de7c11af6c5e79dcb92a423bb6f54e04310831b42e4deff3
4
- data.tar.gz: 040a083645043d9624e6bda2bcc4d14bbce103e5bff38c7fc8ce1e627f03003a
3
+ metadata.gz: 83304e6d64ac58c74da248c86e088a5d1e8616dc804a8b5a32923d9f6a3414f3
4
+ data.tar.gz: e3aede09a1fec47cc1a32e549558b4ddaa40f4b5bf6861e4f445d676b93d8c38
5
5
  SHA512:
6
- metadata.gz: f8007430fceaf0b6e87626e3fc7999eabd223e1e22f690e56b5aa89e93b548c97e3d8f46da560dc921d329a87f0fa2814471f0e773f4e52cbf40d371c0795dca
7
- data.tar.gz: 91ca5f570333f8914666960dd32638027c172737d898c178b56972bec9cca9ca2ab7cf362a982b73f830c270969caa411363f9b827a88ba38679760ac28fd474
6
+ metadata.gz: 59fd8e801162dbfa11f4628c652d0375707267074f3842abc0a9fd5767ed1e4caeabd126fc13edb8e8b229a79488aebe5c40839aea24dc308d77d2af7a4f6f43
7
+ data.tar.gz: a39eea8deb22f51a0ea8f74aa30ac8ea4d880523b62082ed0ab3c51f93413a9e4ff8a76076226b93882eab3d9b1806068307a1854d118f8665dcb139add71f0a
@@ -1,6 +1,6 @@
1
1
  #!/usr/bin/env ruby
2
2
  this_dir = File.expand_path(File.dirname(__FILE__))
3
- lib_dir = File.join(this_dir, '..', 'src', 'svc')
3
+ lib_dir = File.join(this_dir, '..', '..', 'src', 'svc')
4
4
  $LOAD_PATH.unshift(lib_dir)
5
5
 
6
6
  require 'rubygems'
@@ -8,6 +8,8 @@ require 'bundler/setup'
8
8
  require 'grpc'
9
9
  require 'mather'
10
10
  require 'commander'
11
+ require 'ougai'
12
+ LOG = Ougai::Logger.new(STDOUT) if !defined?(LOG)
11
13
 
12
14
  class MatherServer
13
15
  include Commander::Methods
@@ -15,13 +17,12 @@ class MatherServer
15
17
  def run
16
18
  program :name, 'Mather Server (in Ruby)'
17
19
  program :version, '1.0.0'
18
- program :description,
19
- 'A simple math gRPC microservice, for the purpose of learning and evaluating Ruby and gRPC.'
20
+ program :description, 'Simple Ruby gRPC microservice that does math.'
20
21
 
21
22
  command :start do |c|
22
23
  c.syntax = 'mather-rb-server start'
23
24
  c.description = 'Starts the server'
24
- c.option '--port PORT', String, "Server's port (by default :30000)"
25
+ c.option '--port PORT', String, "Server's port (default \":30000\")"
25
26
 
26
27
  c.action do |args, options|
27
28
  port = options.port || ':30000'
@@ -30,7 +31,7 @@ class MatherServer
30
31
  s.add_http2_port("0.0.0.0#{port}", :this_port_is_insecure)
31
32
  s.handle(MatherService)
32
33
 
33
- puts "Server started on port #{port}"
34
+ LOG.info "Server started on port #{port}"
34
35
  s.run_till_terminated_or_interrupted([1, 'int', 'SIGQUIT'])
35
36
  end
36
37
  end
@@ -1,8 +1,10 @@
1
1
  class MatherLib
2
+ # add adds two numbers
2
3
  def add(first, second)
3
4
  return first + second
4
5
  end
5
6
 
7
+ # subtract subtracts two numbers
6
8
  def subtract(first, second)
7
9
  return second - first
8
10
  end
@@ -0,0 +1,34 @@
1
+ require 'minitest/autorun'
2
+ require_relative 'mather'
3
+
4
+ add_results = [
5
+ [0, 0, 0],
6
+ [0, 1, 1],
7
+ [1, 0, 1],
8
+ [1, 1, 2],
9
+ [-1, 1, 0],
10
+ [1, -1, 0],
11
+ [-1, -1, -2]
12
+ ]
13
+
14
+ subtract_results = [
15
+ [0, 0, 0],
16
+ [1, 0, -1],
17
+ [0, 1, 1],
18
+ [-1, 0, 1],
19
+ [-1, -1, 0],
20
+ [1, -1, -2]
21
+ ]
22
+
23
+ describe 'Mather' do
24
+ it 'Adds' do
25
+ matherLib = MatherLib.new
26
+ add_results.each { |r| _(matherLib.add(r[0], r[1])).must_equal(r[2]) }
27
+ end
28
+ it 'Subtracts' do
29
+ matherLib = MatherLib.new
30
+ subtract_results.each do |r|
31
+ _(matherLib.subtract(r[0], r[1])).must_equal(r[2])
32
+ end
33
+ end
34
+ end
File without changes
@@ -1,5 +1,5 @@
1
1
  this_dir = File.expand_path(File.dirname(__FILE__))
2
- proto_dir = File.join(this_dir, 'proto')
2
+ proto_dir = File.join(this_dir, '..', 'proto', 'generated')
3
3
  lib_dir = File.join(this_dir, '..', 'lib')
4
4
  $LOAD_PATH.unshift(proto_dir)
5
5
  $LOAD_PATH.unshift(lib_dir)
@@ -7,45 +7,49 @@ $LOAD_PATH.unshift(lib_dir)
7
7
  require 'mather_services_pb'
8
8
  require 'grpc'
9
9
  require 'mather'
10
+ require 'ougai'
11
+ LOG = Ougai::Logger.new(STDOUT) if !defined?(LOG)
10
12
 
11
13
  class MatherService < Mather::Math::Service
14
+ # add adds two numbers
12
15
  def add(req, _)
16
+ # Validate input
13
17
  if req.First == 0
14
- raise GRPC::BadStatus.new(
15
- GRPC::Core::StatusCodes::INVALID_ARGUMENT,
16
- 'Could not add, `First` has not been provided'
17
- )
18
+ msg = 'Could not add, `First` has not been provided'
19
+ LOG.error msg
20
+ raise GRPC::BadStatus.new(GRPC::Core::StatusCodes::INVALID_ARGUMENT, msg)
18
21
  end
19
-
20
22
  if req.Second == 0
21
- raise GRPC::BadStatus.new(
22
- GRPC::Core::StatusCodes::INVALID_ARGUMENT,
23
- 'Could not add, `Second` has not been provided'
24
- )
23
+ msg = 'Could not add, `Second` has not been provided'
24
+ LOG.error msg
25
+ raise GRPC::BadStatus.new(GRPC::Core::StatusCodes::INVALID_ARGUMENT, msg)
25
26
  end
26
27
 
27
- puts "Adding #{req.First} to #{req.Second}"
28
+ # Log progress
29
+ LOG.info "Adding #{req.First} to #{req.Second}"
28
30
 
31
+ # Return added numbers
29
32
  Mather::MathAddReply.new(Result: MatherLib.new.add(req.First, req.Second))
30
33
  end
31
34
 
35
+ # subtract subtracts two numbers
32
36
  def subtract(req, _)
37
+ # Validate input
33
38
  if req.First == 0
34
- raise GRPC::BadStatus.new(
35
- GRPC::Core::StatusCodes::INVALID_ARGUMENT,
36
- 'Could not add, `First` has not been provided'
37
- )
39
+ msg = 'Could not subtract, `First` has not been provided'
40
+ LOG.error msg
41
+ raise GRPC::BadStatus.new(GRPC::Core::StatusCodes::INVALID_ARGUMENT, msg)
38
42
  end
39
-
40
43
  if req.Second == 0
41
- raise GRPC::BadStatus.new(
42
- GRPC::Core::StatusCodes::INVALID_ARGUMENT,
43
- 'Could not add, `Second` has not been provided'
44
- )
44
+ msg = 'Could not subtract, `Second` has not been provided'
45
+ LOG.error msg
46
+ raise GRPC::BadStatus.new(GRPC::Core::StatusCodes::INVALID_ARGUMENT, msg)
45
47
  end
46
48
 
47
- puts "Subtracting #{req.First} from #{req.Second}"
49
+ # Log progress
50
+ LOG.info "Subtracting #{req.First} from #{req.Second}"
48
51
 
52
+ # Return subtracted numbers
49
53
  Mather::MathSubtractReply.new(
50
54
  Result: MatherLib.new.subtract(req.First, req.Second)
51
55
  )
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mather-rb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.4
4
+ version: 0.0.7
5
5
  platform: ruby
6
6
  authors:
7
7
  - Felix Pojtinger
8
8
  autorequire:
9
- bindir: exe
9
+ bindir: cmd/mather-rb-server
10
10
  cert_chain: []
11
- date: 2019-11-09 00:00:00.000000000 Z
11
+ date: 2019-11-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grpc
@@ -52,6 +52,20 @@ dependencies:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
54
  version: '2.0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: ougai
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '1.8'
62
+ type: :runtime
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '1.8'
55
69
  - !ruby/object:Gem::Dependency
56
70
  name: rake
57
71
  requirement: !ruby/object:Gem::Requirement
@@ -66,6 +80,20 @@ dependencies:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
82
  version: '10.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: rerun
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 0.13.0
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 0.13.0
69
97
  - !ruby/object:Gem::Dependency
70
98
  name: grpc-tools
71
99
  requirement: !ruby/object:Gem::Requirement
@@ -108,6 +136,20 @@ dependencies:
108
136
  - - "~>"
109
137
  - !ruby/object:Gem::Version
110
138
  version: '1.0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: minitest
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - "~>"
144
+ - !ruby/object:Gem::Version
145
+ version: '5.13'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - "~>"
151
+ - !ruby/object:Gem::Version
152
+ version: '5.13'
111
153
  description:
112
154
  email:
113
155
  - felix@pojtinger.com
@@ -116,12 +158,13 @@ executables:
116
158
  extensions: []
117
159
  extra_rdoc_files: []
118
160
  files:
119
- - exe/mather-rb-server
161
+ - cmd/mather-rb-server/mather-rb-server
120
162
  - src/lib/mather.rb
163
+ - src/lib/mather_test.rb
164
+ - src/proto/generated/mather_pb.rb
165
+ - src/proto/generated/mather_services_pb.rb
166
+ - src/proto/mather.proto
121
167
  - src/svc/mather.rb
122
- - src/svc/proto/mather.proto
123
- - src/svc/proto/mather_pb.rb
124
- - src/svc/proto/mather_services_pb.rb
125
168
  homepage: https://pojntfx.github.io/mather-rb/
126
169
  licenses:
127
170
  - AGPL-3.0
@@ -148,5 +191,5 @@ rubyforge_project:
148
191
  rubygems_version: 2.7.8
149
192
  signing_key:
150
193
  specification_version: 4
151
- summary: Simple gRPC microservice that does math.
194
+ summary: Simple Ruby gRPC microservice that does math.
152
195
  test_files: []