Class: Trane::RequestBuilder
- Inherits:
-
Object
- Object
- Trane::RequestBuilder
- Defined in:
- lib/trane/operation_definition.rb
Overview
Builder for the request do ... end block
Instance Method Summary collapse
- #body(&block) ⇒ Object
- #build ⇒ Object
-
#initialize ⇒ RequestBuilder
constructor
A new instance of RequestBuilder.
- #path(name, type:) ⇒ Object
- #query(name, type:, required: false, enum: nil) ⇒ Object
Constructor Details
#initialize ⇒ RequestBuilder
Returns a new instance of RequestBuilder.
51 52 53 54 |
# File 'lib/trane/operation_definition.rb', line 51 def initialize @params = [] @body_fields = [] end |
Instance Method Details
#body(&block) ⇒ Object
69 70 71 72 73 |
# File 'lib/trane/operation_definition.rb', line 69 def body(&block) builder = BodyBuilder.new builder.instance_eval(&block) @body_fields = builder.fields end |
#build ⇒ Object
75 76 77 |
# File 'lib/trane/operation_definition.rb', line 75 def build RequestDefinition.new(params: @params, body_fields: @body_fields) end |
#path(name, type:) ⇒ Object
56 57 58 59 60 |
# File 'lib/trane/operation_definition.rb', line 56 def path(name, type:) raise ArgumentError, "path #{name.inspect} type: cannot be nil" if type.nil? @params << ParamDefinition.new(name: name, type: type, required: true, location: :path) end |
#query(name, type:, required: false, enum: nil) ⇒ Object
62 63 64 65 66 67 |
# File 'lib/trane/operation_definition.rb', line 62 def query(name, type:, required: false, enum: nil) raise ArgumentError, "query #{name.inspect} type: cannot be nil" if type.nil? Trane::Types.validate_enum!(name: name, type: type, enum: enum) if enum @params << ParamDefinition.new(name: name, type: type, required: required, location: :query, enum: enum) end |