-
Notifications
You must be signed in to change notification settings - Fork 539
/
Copy pathspec_insert.rb
47 lines (41 loc) · 1.49 KB
/
spec_insert.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
# frozen_string_literal: true
require_relative 'components/base_mustache_renderer'
require_relative '../api/action'
require_relative '../spec_insert_error'
require_relative 'endpoints'
require_relative 'path_parameters'
require_relative 'query_parameters'
require_relative 'body_parameters'
# Class to render spec insertions
class SpecInsert < BaseMustacheRenderer
self.template_file = "#{__dir__}/templates/spec_insert.mustache"
# @param [InsertArguments]
def initialize(args)
action = Api::Action.by_full_name[args.api]
super(action, args)
raise SpecInsertError, '`api` argument not specified.' unless @args.api
raise SpecInsertError, "API Action '#{@args.api}' does not exist in the spec." unless @action
end
def arguments
@args.raw.map { |key, value| { key:, value: } }
end
def api; @args.api end
def component; @args.component end
def content
raise SpecInsertError, '`component` argument not specified.' unless @args.component
case @args.component.to_sym
when :query_parameters
QueryParameters.new(@action, @args).render
when :path_parameters
PathParameters.new(@action, @args).render
when :endpoints
Endpoints.new(@action, @args).render
when :request_body_parameters
BodyParameters.new(@action, @args, is_request: true).render
when :response_body_parameters
BodyParameters.new(@action, @args, is_request: false).render
else
raise SpecInsertError, "Invalid component: #{@args.component}"
end
end
end