protocol-grpc 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/protocol/grpc/interface.rb +32 -14
- data/lib/protocol/grpc/version.rb +1 -1
- data/readme.md +4 -0
- data/releases.md +4 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 1918529ed154432a768c783d4677b6912017fb3acd4054fd392c79fbdc97c9b3
|
|
4
|
+
data.tar.gz: f076c43f3f1a6e429f0b057eb5ce512f4405fb350b88dfbfdddf2a476ccbf949
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 593456adb014c6caa239365a9652253838d7f0930fd2d898c052914a8535a3e34aa40905f951e01d7e2c2b77d27e49c1445f113b3b88f53d54e42fd572dc4501
|
|
7
|
+
data.tar.gz: b14442b758e562affbc13011a2e5d982d40d0cd742d844921fb8e5efe63cecc5fa7fc633656f8fd7ef13b0f1acde18ceea9f0864aa8adf3bf571ee07558a17db
|
|
@@ -7,16 +7,16 @@ require_relative "methods"
|
|
|
7
7
|
|
|
8
8
|
module Protocol
|
|
9
9
|
module GRPC
|
|
10
|
-
# RPC method definition
|
|
11
|
-
RPC = Struct.new(:request_class, :response_class, :streaming, :method, keyword_init: true) do
|
|
12
|
-
def initialize(request_class:, response_class:, streaming: :unary, method: nil)
|
|
13
|
-
super
|
|
14
|
-
end
|
|
15
|
-
end
|
|
16
|
-
|
|
17
10
|
# Represents an interface definition for gRPC methods.
|
|
18
11
|
# Can be used by both client stubs and server implementations.
|
|
19
12
|
class Interface
|
|
13
|
+
# RPC method definition
|
|
14
|
+
RPC = Struct.new(:request_class, :response_class, :streaming, :method, keyword_init: true) do
|
|
15
|
+
def initialize(request_class:, response_class:, streaming: :unary, method: nil)
|
|
16
|
+
super
|
|
17
|
+
end
|
|
18
|
+
end
|
|
19
|
+
|
|
20
20
|
# Hook called when a subclass is created.
|
|
21
21
|
# Initializes the RPC hash for the subclass.
|
|
22
22
|
# @parameter subclass [Class] The subclass being created
|
|
@@ -33,6 +33,9 @@ module Protocol
|
|
|
33
33
|
# @parameter streaming [Symbol] Streaming type (:unary, :server_streaming, :client_streaming, :bidirectional)
|
|
34
34
|
# @parameter method [Symbol | Nil] Optional explicit Ruby method name (snake_case). If not provided, automatically converts PascalCase to snake_case.
|
|
35
35
|
def self.rpc(name, **options)
|
|
36
|
+
# Ensure snake_case method name is always available
|
|
37
|
+
options[:method] ||= pascal_case_to_snake_case(name.to_s).to_sym
|
|
38
|
+
|
|
36
39
|
@rpcs[name] = RPC.new(**options)
|
|
37
40
|
end
|
|
38
41
|
|
|
@@ -44,12 +47,15 @@ module Protocol
|
|
|
44
47
|
klass = self
|
|
45
48
|
while klass && klass != Interface
|
|
46
49
|
if klass.instance_variable_defined?(:@rpcs)
|
|
47
|
-
rpc = klass.instance_variable_get(:@rpcs)[name]
|
|
48
|
-
|
|
50
|
+
if rpc = klass.instance_variable_get(:@rpcs)[name]
|
|
51
|
+
return rpc
|
|
52
|
+
end
|
|
49
53
|
end
|
|
50
54
|
klass = klass.superclass
|
|
51
55
|
end
|
|
52
|
-
|
|
56
|
+
|
|
57
|
+
# Not found:
|
|
58
|
+
return nil
|
|
53
59
|
end
|
|
54
60
|
|
|
55
61
|
# Get all RPC definitions from this class and all parent classes.
|
|
@@ -69,21 +75,33 @@ module Protocol
|
|
|
69
75
|
all_rpcs
|
|
70
76
|
end
|
|
71
77
|
|
|
72
|
-
# @attribute [String] The service name (e.g., "hello.Greeter").
|
|
73
|
-
attr :name
|
|
74
|
-
|
|
75
78
|
# Initialize a new interface instance.
|
|
76
79
|
# @parameter name [String] Service name
|
|
77
80
|
def initialize(name)
|
|
78
81
|
@name = name
|
|
79
82
|
end
|
|
80
83
|
|
|
84
|
+
# @attribute [String] The service name (e.g., "hello.Greeter").
|
|
85
|
+
attr :name
|
|
86
|
+
|
|
81
87
|
# Build gRPC path for a method.
|
|
82
88
|
# @parameter method_name [String, Symbol] Method name in PascalCase (e.g., :SayHello)
|
|
83
89
|
# @returns [String] gRPC path with PascalCase method name
|
|
84
90
|
def path(method_name)
|
|
85
91
|
Methods.build_path(@name, method_name.to_s)
|
|
86
92
|
end
|
|
93
|
+
|
|
94
|
+
private
|
|
95
|
+
|
|
96
|
+
# Convert PascalCase to snake_case.
|
|
97
|
+
# @parameter pascal_case [String] PascalCase string (e.g., "SayHello")
|
|
98
|
+
# @returns [String] snake_case string (e.g., "say_hello")
|
|
99
|
+
def self.pascal_case_to_snake_case(pascal_case)
|
|
100
|
+
pascal_case
|
|
101
|
+
.gsub(/([A-Z]+)([A-Z][a-z])/, '\1_\2') # Insert underscore before capital letters followed by lowercase
|
|
102
|
+
.gsub(/([a-z\d])([A-Z])/, '\1_\2') # Insert underscore between lowercase/digit and uppercase
|
|
103
|
+
.downcase
|
|
104
|
+
end
|
|
87
105
|
end
|
|
88
106
|
end
|
|
89
|
-
end
|
|
107
|
+
end
|
data/readme.md
CHANGED
|
@@ -28,6 +28,10 @@ Please see the [project documentation](https://socketry.github.io/protocol-grpc/
|
|
|
28
28
|
|
|
29
29
|
Please see the [project releases](https://socketry.github.io/protocol-grpc/releases/index) for all releases.
|
|
30
30
|
|
|
31
|
+
### v0.2.0
|
|
32
|
+
|
|
33
|
+
- `RCP#method` is always defined (snake case).
|
|
34
|
+
|
|
31
35
|
### v0.1.0
|
|
32
36
|
|
|
33
37
|
- Initial design.
|
data/releases.md
CHANGED