Class: GrpcRest::GeneratedMethod
- Inherits:
-
Object
- Object
- GrpcRest::GeneratedMethod
- Defined in:
- lib/generator/method.rb
Defined Under Namespace
Classes: PathInfo
Instance Attribute Summary collapse
-
#http_method ⇒ Object
Returns the value of attribute http_method.
-
#path ⇒ Object
Returns the value of attribute path.
-
#path_info ⇒ Object
Returns the value of attribute path_info.
-
#rest_options ⇒ Object
Returns the value of attribute rest_options.
Instance Method Summary collapse
- #extract_options ⇒ Google::Api::HttpRule
- #extract_path_info ⇒ PathInfo
- #extract_rest_options ⇒ Hash
-
#initialize(proto_method) ⇒ GeneratedMethod
constructor
A new instance of GeneratedMethod.
- #method_and_path ⇒ String
- #name ⇒ String
- #option_body ⇒ String
- #request_type ⇒ String
- #sanitized_path ⇒ String
Constructor Details
#initialize(proto_method) ⇒ GeneratedMethod
Returns a new instance of GeneratedMethod.
10 11 12 13 14 15 16 |
# File 'lib/generator/method.rb', line 10 def initialize(proto_method) @method = proto_method @rest_options = @options = @http_method, @path = method_and_path @path_info = extract_path_info end |
Instance Attribute Details
#http_method ⇒ Object
Returns the value of attribute http_method.
7 8 9 |
# File 'lib/generator/method.rb', line 7 def http_method @http_method end |
#path ⇒ Object
Returns the value of attribute path.
7 8 9 |
# File 'lib/generator/method.rb', line 7 def path @path end |
#path_info ⇒ Object
Returns the value of attribute path_info.
7 8 9 |
# File 'lib/generator/method.rb', line 7 def path_info @path_info end |
#rest_options ⇒ Object
Returns the value of attribute rest_options.
7 8 9 |
# File 'lib/generator/method.rb', line 7 def @rest_options end |
Instance Method Details
#extract_options ⇒ Google::Api::HttpRule
45 46 47 48 49 50 |
# File 'lib/generator/method.rb', line 45 def return nil if @method..nil? extension = Google::Protobuf::DescriptorPool.generated_pool.lookup('google.api.http') extension.get(@method.) end |
#extract_path_info ⇒ PathInfo
79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 |
# File 'lib/generator/method.rb', line 79 def extract_path_info @path.scan(/\{(.*?)}/).map do |match| name = match[0] val = '' equal = name.index('=') if equal val = name[equal+1..] name = name[0..equal - 1] end PathInfo.new( name: name, val: val, split_name: name.split('.') ) end end |
#extract_rest_options ⇒ Hash
53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/generator/method.rb', line 53 def return nil if @method..nil? extension = Google::Protobuf::DescriptorPool.generated_pool .lookup('grpc.gateway.protoc_gen_openapiv2.options.openapiv2_operation') result = extension.get(@method.) return {} if result.nil? emit_defaults = result.extensions['x-grpc-rest-emit-defaults']&.bool_value || false { emit_defaults: emit_defaults } end |
#method_and_path ⇒ String
68 69 70 71 72 73 74 75 76 |
# File 'lib/generator/method.rb', line 68 def method_and_path return if @options.nil? if @options.pattern == :custom [@options.custom.kind, @options.custom.path] else [@options.pattern, @options.send(@options.pattern)] end end |
#name ⇒ String
21 |
# File 'lib/generator/method.rb', line 21 def name = @method.name.underscore |
#option_body ⇒ String
19 20 |
# File 'lib/generator/method.rb', line 19 def option_body = @options&.body # @return [String] |
#request_type ⇒ String
24 25 26 |
# File 'lib/generator/method.rb', line 24 def request_type @method.input_type.msgclass end |
#sanitized_path ⇒ String
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/generator/method.rb', line 29 def sanitized_path path = @path re = /\{(.*?)}/ matches = path.scan(re) matches.each do |match| repl = match[0] equal = repl.index('=') repl = repl[0...equal] if equal dot = repl.index('.') repl = repl[(dot + 1)..] if dot path = path.sub("{#{match[0]}}", "*#{repl}") end path end |