Module: Mortymer::ApiMetadata::ClassMethods

Defined in:
lib/mortymer/api_metadata.rb

Overview

The DSL

Instance Method Summary collapse

Instance Method Details

#__default_tag_for_endpoint__Object



32
33
34
35
36
37
# File 'lib/mortymer/api_metadata.rb', line 32

def __default_tag_for_endpoint__
  # Assuming the endpoint is always defined inside a module
  # the Tag would be the module of that endpoint. If no module, then
  # we take the endpoint and remove any endpoint, controller suffix
  [name.split("::").last(2).first] || [name.gsub(/Controller$/, "").gsub(/Endpoint$/, "")]
end

#delete(input:, output:, path: nil, security: nil) ⇒ Object



51
52
53
# File 'lib/mortymer/api_metadata.rb', line 51

def delete(input:, output:, path: nil, security: nil)
  register_endpoint(:delete, input, output, path, security || @__endpoint_security__)
end

#get(input:, output:, path: nil, security: nil) ⇒ Object



39
40
41
# File 'lib/mortymer/api_metadata.rb', line 39

def get(input:, output:, path: nil, security: nil)
  register_endpoint(:get, input, output, path, security || @__endpoint_security__)
end

#handles_exception(exception, status: 400, output: nil) {|exception| ... } ⇒ Object

Register an exception handler for the next endpoint

Parameters:

  • exception (Class)

    The exception class to handle

  • status (Symbol, Integer) (defaults to: 400)

    The HTTP status code to return

  • output (Class) (defaults to: nil)

    The output schema class for the error response

Yields:

  • (exception)

    Optional block to transform the exception into a response

Yield Parameters:

  • exception (Exception)

    The caught exception

Yield Returns:

  • (Hash)

    The response body



62
63
64
65
66
67
68
69
70
# File 'lib/mortymer/api_metadata.rb', line 62

def handles_exception(exception, status: 400, output: nil, &block)
  @__endpoint_exception_handlers__ ||= []
  @__endpoint_exception_handlers__ << {
    exception: exception,
    status: status,
    output: output,
    handler: block
  }
end

#post(input:, output:, path: nil, security: nil) ⇒ Object



43
44
45
# File 'lib/mortymer/api_metadata.rb', line 43

def post(input:, output:, path: nil, security: nil)
  register_endpoint(:post, input, output, path, security || @__endpoint_security__)
end

#put(input:, output:, path: nil, security: nil) ⇒ Object



47
48
49
# File 'lib/mortymer/api_metadata.rb', line 47

def put(input:, output:, path: nil, security: nil)
  register_endpoint(:put, input, output, path, security || @__endpoint_security__)
end

#remove_security!Object



24
25
26
# File 'lib/mortymer/api_metadata.rb', line 24

def remove_security!
  @__endpoint_security__ = nil
end

#secured_with(security) ⇒ Object



20
21
22
# File 'lib/mortymer/api_metadata.rb', line 20

def secured_with(security)
  @__endpoint_security__ = security
end

#tags(*tag_list) ⇒ Object



28
29
30
# File 'lib/mortymer/api_metadata.rb', line 28

def tags(*tag_list)
  @__endpoint_tags__ = tag_list
end