Module: Starter::Templates::Endpoints

Included in:
Builder
Defined in:
lib/starter/builder/templates/endpoints.rb

Overview

defining the endpoints -> http methods of a resource

Instance Method Summary collapse

Instance Method Details

#crudObject



7
8
9
10
11
12
13
14
15
16
# File 'lib/starter/builder/templates/endpoints.rb', line 7

def crud
  %i[
    post
    get_all
    get_specific
    put_specific
    patch_specific
    delete_specific
  ]
end

#get_allObject

GET



44
45
46
47
48
49
50
51
52
53
# File 'lib/starter/builder/templates/endpoints.rb', line 44

def get_all
  "
  desc 'get all of #{resource.pluralize}' do
    is_array true
    tags %w[#{resource.singularize}]
  end
  get do
    # your code goes here
  end"
end

#get_all_specObject



90
91
92
# File 'lib/starter/builder/templates/endpoints.rb', line 90

def get_all_spec
  "it_behaves_like 'GET all'"
end

#postObject

available API/HTTP methods POST



30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/starter/builder/templates/endpoints.rb', line 30

def post
  "
  desc 'create #{resource.singularize}' do
    tags %w[#{resource.singularize}]
  end
  params do
    # TODO: specify the parameters
  end
  post do
    # your code goes here
  end"
end

#post_specObject

request specs shared examples



86
87
88
# File 'lib/starter/builder/templates/endpoints.rb', line 86

def post_spec
  "it_behaves_like 'POST', params: {}"
end

#singular_oneObject



18
19
20
21
22
23
24
25
26
# File 'lib/starter/builder/templates/endpoints.rb', line 18

def singular_one
  %i[
    post
    get_one
    put_one
    patch_one
    delete_one
  ]
end