Class: Camille::Endpoint
- Inherits:
-
Object
- Object
- Camille::Endpoint
- Defined in:
- lib/camille/endpoint.rb
Defined Under Namespace
Classes: ArgumentError, UnknownResponseError
Instance Attribute Summary collapse
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#params_type ⇒ Object
readonly
Returns the value of attribute params_type.
-
#response_type ⇒ Object
readonly
Returns the value of attribute response_type.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#verb ⇒ Object
readonly
Returns the value of attribute verb.
Instance Method Summary collapse
- #function ⇒ Object
-
#initialize(schema, verb, name) ⇒ Endpoint
constructor
A new instance of Endpoint.
- #path ⇒ Object
- #signature ⇒ Object
Constructor Details
#initialize(schema, verb, name) ⇒ Endpoint
Returns a new instance of Endpoint.
8 9 10 11 12 |
# File 'lib/camille/endpoint.rb', line 8 def initialize schema, verb, name @verb = verb @name = name @schema = schema end |
Instance Attribute Details
#name ⇒ Object (readonly)
Returns the value of attribute name.
6 7 8 |
# File 'lib/camille/endpoint.rb', line 6 def name @name end |
#params_type ⇒ Object (readonly)
Returns the value of attribute params_type.
6 7 8 |
# File 'lib/camille/endpoint.rb', line 6 def params_type @params_type end |
#response_type ⇒ Object (readonly)
Returns the value of attribute response_type.
6 7 8 |
# File 'lib/camille/endpoint.rb', line 6 def response_type @response_type end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
6 7 8 |
# File 'lib/camille/endpoint.rb', line 6 def schema @schema end |
#verb ⇒ Object (readonly)
Returns the value of attribute verb.
6 7 8 |
# File 'lib/camille/endpoint.rb', line 6 def verb @verb end |
Instance Method Details
#function ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/camille/endpoint.rb', line 29 def function if @params_type "#{signature}{ return request('#{@verb}', '#{path}', params) }" else "#{signature}{ return request('#{@verb}', '#{path}', {}) }" end end |
#path ⇒ Object
25 26 27 |
# File 'lib/camille/endpoint.rb', line 25 def path "#{@schema.path}/#{name}" end |
#signature ⇒ Object
14 15 16 17 18 19 20 21 22 23 |
# File 'lib/camille/endpoint.rb', line 14 def signature unless @response_type raise UnknownResponseError.new("Endpoint lacking a `response` definition.") end if @params_type "#{Camille::Configuration.response_key_converter.call(@name.to_s)}(params: #{@params_type.literal}): Promise<#{@response_type.literal}>" else "#{Camille::Configuration.response_key_converter.call(@name.to_s)}(): Promise<#{@response_type.literal}>" end end |