Class: Camille::Endpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/camille/endpoint.rb

Defined Under Namespace

Classes: ArgumentError, UnknownResponseError

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#nameObject (readonly)

Returns the value of attribute name.



6
7
8
# File 'lib/camille/endpoint.rb', line 6

def name
  @name
end

#params_typeObject (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_typeObject (readonly)

Returns the value of attribute response_type.



6
7
8
# File 'lib/camille/endpoint.rb', line 6

def response_type
  @response_type
end

#schemaObject (readonly)

Returns the value of attribute schema.



6
7
8
# File 'lib/camille/endpoint.rb', line 6

def schema
  @schema
end

#verbObject (readonly)

Returns the value of attribute verb.



6
7
8
# File 'lib/camille/endpoint.rb', line 6

def verb
  @verb
end

Instance Method Details

#functionObject



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

#pathObject



25
26
27
# File 'lib/camille/endpoint.rb', line 25

def path
  "#{@schema.path}/#{name}"
end

#signatureObject



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