Class: Stitches::ApiGenerator

Inherits:
Rails::Generators::Base
  • Object
show all
Defined in:
lib/stitches/api_generator.rb

Instance Method Summary collapse

Instance Method Details

#bootstrap_apiObject



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
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/stitches/api_generator.rb', line 8

def bootstrap_api
  gem_group :development, :test do
    gem "rspec"
    gem "rspec-rails"
    gem "rspec_api_documentation"
  end

  Bundler.with_unbundled_env do
    run "bundle install"
  end
  generate "rspec:install"

  inject_into_file "config/routes.rb", before: /^end/ do<<-ROUTES
namespace :api do
  scope module: :v1, constraints: Stitches::ApiVersionConstraint.new(1) do
resource 'ping', only: [ :create ]
# Add your V1 resources here
  end
  scope module: :v2, constraints: Stitches::ApiVersionConstraint.new(2) do
resource 'ping', only: [ :create ]
# This is here simply to validate that versioning is working
# as well as for your client to be able to validate this as well.
  end
end
  ROUTES
  end

  copy_file "app/controllers/api.rb"
  copy_file "app/controllers/api/api_controller.rb"
  copy_file "app/controllers/api/v1.rb"
  copy_file "app/controllers/api/v2.rb"
  copy_file "app/controllers/api/v1/pings_controller.rb"
  copy_file "app/controllers/api/v2/pings_controller.rb"
  copy_file "config/initializers/stitches.rb"
  template "spec/features/api_spec.rb.erb", "spec/features/api_spec.rb"
  copy_file "spec/acceptance/ping_v1_spec.rb", "spec/acceptance/ping_v1_spec.rb"

  inject_into_file 'spec/rails_helper.rb', %q{
config.include RSpec::Rails::RequestExampleGroup, type: :feature
}, before: /^end/

  inject_into_file 'spec/rails_helper.rb', before: /^RSpec.configure/ do<<-REQUIRE
require 'stitches/spec'
  REQUIRE
  end

  append_to_file 'spec/rails_helper.rb' do<<-RSPEC_API
require 'rspec_api_documentation'

RspecApiDocumentation.configure do |config|
  config.format = [:json, :html]
  config.request_headers_to_include = %w(
Accept
Content-Type
Authorization
If-Modified-Since
  )
  config.response_headers_to_include = %w(
Last-Modified
ETag
  )
  config.api_name = "YOUR SERVICE NAME HERE"
end
RSPEC_API
  end
end