Class: Explicit::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/explicit/request.rb

Defined Under Namespace

Modules: InvalidParams Classes: InvalidResponseError, Route

Class Method Summary collapse

Class Method Details

.delete(path) ⇒ Object



11
# File 'lib/explicit/request.rb', line 11

def delete(path)  = routes << Route.new(method: :delete, path:)

.description(markdown) ⇒ Object



19
20
21
# File 'lib/explicit/request.rb', line 19

def description(markdown)
  # TODO
end

.get(path) ⇒ Object



7
# File 'lib/explicit/request.rb', line 7

def get(path)     = routes << Route.new(method: :get, path:)

.head(path) ⇒ Object



8
# File 'lib/explicit/request.rb', line 8

def head(path)    = routes << Route.new(method: :head, path:)

.header(name, format) ⇒ Object



23
24
25
26
27
# File 'lib/explicit/request.rb', line 23

def header(name, format)
  raise ArgumentError("duplicated header #{name}") if headers.key?(name)

  headers[name] = format
end

.options(path) ⇒ Object



12
# File 'lib/explicit/request.rb', line 12

def options(path) = routes << Route.new(method: :options, path:)

.param(name, format, **options) ⇒ Object



29
30
31
32
33
# File 'lib/explicit/request.rb', line 29

def param(name, format, **options)
  raise ArgumentError("duplicated param #{name}") if params.key?(name)

  params[name] = format
end

.patch(path) ⇒ Object



13
# File 'lib/explicit/request.rb', line 13

def patch(path)   = routes << Route.new(method: :patch, path:)

.post(path) ⇒ Object



9
# File 'lib/explicit/request.rb', line 9

def post(path)    = routes << Route.new(method: :post, path:)

.put(path) ⇒ Object



10
# File 'lib/explicit/request.rb', line 10

def put(path)     = routes << Route.new(method: :put, path:)

.response(status, format) ⇒ Object



35
36
37
# File 'lib/explicit/request.rb', line 35

def response(status, format)
  responses << { status: [:literal, status], data: format }
end

.title(text) ⇒ Object



15
16
17
# File 'lib/explicit/request.rb', line 15

def title(text)
  # TODO
end

.validate!(values) ⇒ Object



39
40
41
42
43
44
45
46
# File 'lib/explicit/request.rb', line 39

def validate!(values)
  params_validator = Explicit::Spec.build(params)

  case params_validator.call(values)
  in [:ok, validated_data] then validated_data
  in [:error, err] then raise InvalidParams::Error.new(err)
  end
end