Class: GrapeBunch::Generators::InstallGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/generators/grape_bunch/install_generator.rb

Instance Method Summary collapse

Instance Method Details

#create_root_apiObject



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/generators/grape_bunch/install_generator.rb', line 6

def create_root_api
  create_file "app/api/api_v1/api.rb", <<-ROOT_API
module ApiV1
  class API < Grape::API
    prefix 'api'
    version 'v1'
    format :json

    add_swagger_documentation(
api_version: 'v1',
hide_documentation_path: true,
hide_format: true,
info: {
  title: 'API documentation'
}
    )
  end
end
  ROOT_API
end

#mount_routesObject



27
28
29
30
31
32
33
# File 'lib/generators/grape_bunch/install_generator.rb', line 27

def mount_routes
  inject_into_file 'config/routes.rb', after: "Rails.application.routes.draw do\n" do <<-ROUTES
  mount ApiV1::API => '/'
  mount GrapeSwaggerRails::Engine => '/swagger'
  ROUTES
  end
end

#swagger_initializerObject



35
36
37
38
39
40
41
# File 'lib/generators/grape_bunch/install_generator.rb', line 35

def swagger_initializer
  create_file "config/initializers/swagger.rb", <<-SWAGGER_INIT
GrapeSwaggerRails.options.url      = 'api/v1/swagger_doc'
GrapeSwaggerRails.options.app_name = 'GrapeSwagger'
GrapeSwaggerRails.options.app_url  = '/'
  SWAGGER_INIT
end