grpc-rest 0.1.1 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 0ca423be5a7314061750adbe2e151db9780fa33fd81f6737520ba697d8f71d43
4
- data.tar.gz: 6729fbbd231299780f71ae9fcf437c969f04975ecca2bd871fa733cc8ee4fa6a
3
+ metadata.gz: b9c3044d8f6813a33030d336a91e4d86b4305a781d178d85a07e5e287ab22264
4
+ data.tar.gz: 659013b9ab51cd05f4e1b9570eeb71fb48f07992bd0f1eba80eb37aca1093921
5
5
  SHA512:
6
- metadata.gz: 47b4b888dc91c03388bb6a20c2cdafd12ee0d6e9e6c0e288cb84696009df07b5ed30312038eda6b479a806f4fbf929122e5a5d05b7ca149b8e7a415a55fc67cd
7
- data.tar.gz: 20263c167837551a33f9b69ea2f923bf55f8c251ad7d4c11d4aa6832aa873955180fdd4946a6f2b7f9f101a6643c2d86bea8d36f2e229dddf1b70deeddc5ea6a
6
+ metadata.gz: 04ed1b2acf85c8ec4c069195dd1cd8711e7b68209dcf24cf62a60e832c89158364946d4da72012cc2b7bc037b6f2ac06df36a33a5a43b956e12e7dfe1b9d393b
7
+ data.tar.gz: 64f846bc132c121521c4ba1c8c1189bfed3ebfc4c1ee78473fac297aba84b1254037922a08859f165569a366c23df2b6da0ea391e08ef1e50c4430db713b9f86
@@ -23,7 +23,7 @@ jobs:
23
23
  uses: arduino/setup-protoc@v2
24
24
  - run: git reset --hard
25
25
  - run: git clean -f -d
26
- - run: go test ./...
26
+ - run: cd protoc-gen-rails && go test ./...
27
27
 
28
28
  build_and_deploy:
29
29
  needs: test
data/CHANGELOG CHANGED
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
7
7
 
8
8
  ## UNRELEASED
9
9
 
10
+ # 0.1.4 - 2024-04-04
11
+ - Remove geo-admin hardcoded requirement.
12
+ - Use baked-in Protobuf initialization to support nested objects properly.
13
+
10
14
  # 0.1.0 - 2024-03-01
11
15
 
12
16
  * Initial release.
@@ -1,3 +1,3 @@
1
1
  module GrpcRest
2
- VERSION = "0.1.1"
2
+ VERSION = "0.1.4"
3
3
  end
data/lib/grpc_rest.rb CHANGED
@@ -56,11 +56,6 @@ module GrpcRest
56
56
  sub_record.public_send(:"#{key}=", parameters.delete(key))
57
57
  end
58
58
  end
59
-
60
- # assign remaining parameters
61
- parameters.each do |k, v|
62
- assign_value(request, k, v)
63
- end
64
59
  end
65
60
 
66
61
  def error_msg(error)
@@ -16,7 +16,6 @@ type FileResult struct {
16
16
 
17
17
  type controller struct {
18
18
  ControllerName string
19
- ServiceFilePath string
20
19
  Methods []method
21
20
  ServiceName string
22
21
  FullServiceName string
@@ -41,7 +40,6 @@ type Route struct {
41
40
 
42
41
  var controllerTemplate = `
43
42
  require 'grpc_rest'
44
- require 'services/geo_admin/v1/test_services_pb'
45
43
  class {{.ControllerName}}Controller < ActionController::Base
46
44
  protect_from_forgery with: :null_session
47
45
 
@@ -60,8 +58,9 @@ class {{.ControllerName}}Controller < ActionController::Base
60
58
  {{$fullServiceName := .FullServiceName -}}
61
59
  {{range .Methods }}
62
60
  def {{.Name}}
63
- grpc_request = {{.RequestType}}.new
64
- GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["{{.Name}}"], "{{.Body}}", request.parameters)
61
+ fields = {{.RequestType}}.descriptor.to_a.map(&:name)
62
+ grpc_request = {{.RequestType}}.new(request.parameters.to_h.slice(*fields))
63
+ GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["{{.Name}}"], "{{.Body}}", request.parameters)
65
64
  render json: GrpcRest.send_request("{{$fullServiceName}}", "{{.Name}}", grpc_request)
66
65
  end
67
66
  {{end}}
@@ -74,7 +73,6 @@ func ProcessService(service *descriptorpb.ServiceDescriptorProto, pkg string) (F
74
73
  Methods: []method{},
75
74
  ServiceName: Classify(service.GetName()),
76
75
  ControllerName: Demodulize(service.GetName()),
77
- ServiceFilePath: FilePathify(pkg + "." + service.GetName()),
78
76
  FullServiceName: Classify(pkg + "." + service.GetName()),
79
77
  }
80
78
  for _, m := range service.GetMethod() {
@@ -78,7 +78,7 @@ func runTest(t *testing.T, directory string, options map[string]string) {
78
78
 
79
79
  testDir := workdir + "/testdata/" + directory
80
80
  if os.Getenv("UPDATE_SNAPSHOTS") != "" {
81
- cmd := exec.Command("/bin/sh", "-c", fmt.Sprintf("cp %v/* %v", tmpdir, testDir))
81
+ cmd := exec.Command("/bin/sh", "-c", fmt.Sprintf("cp -R %v/* %v", tmpdir, testDir))
82
82
  cmd.Run()
83
83
  } else {
84
84
  assertEqualFiles(t, testDir, tmpdir)
@@ -1,28 +1,44 @@
1
1
 
2
2
  require 'grpc_rest'
3
- require 'services/geo_admin/v1/test_services_pb'
4
3
  class MyServiceController < ActionController::Base
5
4
  protect_from_forgery with: :null_session
6
5
 
7
- rescue_from Google::Protobuf::TypeError do |e|
6
+ rescue_from StandardError do |e|
8
7
  render json: GrpcRest.error_msg(e)
9
8
  end
9
+ METHOD_PARAM_MAP = {
10
+
11
+ "test" => [
12
+ {name: "blah", val: "foobar/*", split_name:["blah"]},
13
+ {name: "repeated_string", val: nil, split_name:["repeated_string"]},
14
+ ],
15
+
16
+ "test_2" => [
17
+ ],
18
+
19
+ "test_3" => [
20
+ {name: "sub_record.sub_id", val: nil, split_name:["sub_record","sub_id"]},
21
+ ],
22
+ }.freeze
10
23
 
11
24
  def test
12
- grpc_request = Testdata::TestRequest.new
13
- GrpcRest.assign_params(grpc_request, "/test/{blah=foobar/*}/{repeated_string}", "*", request.parameters)
25
+ fields = Testdata::TestRequest.descriptor.to_a.map(&:name)
26
+ grpc_request = Testdata::TestRequest.new(request.parameters.to_h.slice(*fields))
27
+ GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["test"], "*", request.parameters)
14
28
  render json: GrpcRest.send_request("Testdata::MyService", "test", grpc_request)
15
29
  end
16
30
 
17
31
  def test_2
18
- grpc_request = Testdata::TestRequest.new
19
- GrpcRest.assign_params(grpc_request, "/test2", "second_record", request.parameters)
32
+ fields = Testdata::TestRequest.descriptor.to_a.map(&:name)
33
+ grpc_request = Testdata::TestRequest.new(request.parameters.to_h.slice(*fields))
34
+ GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["test_2"], "second_record", request.parameters)
20
35
  render json: GrpcRest.send_request("Testdata::MyService", "test_2", grpc_request)
21
36
  end
22
37
 
23
38
  def test_3
24
- grpc_request = Testdata::TestRequest.new
25
- GrpcRest.assign_params(grpc_request, "/test3/{sub_record.sub_id}", "", request.parameters)
39
+ fields = Testdata::TestRequest.descriptor.to_a.map(&:name)
40
+ grpc_request = Testdata::TestRequest.new(request.parameters.to_h.slice(*fields))
41
+ GrpcRest.assign_params(grpc_request, METHOD_PARAM_MAP["test_3"], "", request.parameters)
26
42
  render json: GrpcRest.send_request("Testdata::MyService", "test_3", grpc_request)
27
43
  end
28
44
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: grpc-rest
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Daniel Orner
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-03-03 00:00:00.000000000 Z
11
+ date: 2024-04-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: grpc