-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #21 from SwitchDreams/feature/rswag
[CU-326fyxt] Feature/rswag
- Loading branch information
Showing
20 changed files
with
775 additions
and
60 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -16,4 +16,6 @@ rest-api-generator.iml | |
|
||
rest-api-generator-*.gem | ||
|
||
tmp | ||
tmp | ||
|
||
.tool-versions |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,5 @@ gem "rake", "~> 13.0" | |
gem "rspec", "~> 3.0" | ||
|
||
gem "switchcop" | ||
|
||
gem "sqlite3" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails/generators" | ||
require "generators/rest_api_generator/helpers" | ||
|
||
module RestApiGenerator | ||
module Spec | ||
class RspecGenerator < Rails::Generators::NamedBase | ||
include Helpers | ||
source_root File.expand_path("templates", __dir__) | ||
|
||
argument :attributes, type: :array, default: [], banner: "field[:type][:index] field[:type][:index]" | ||
class_option :eject, type: :boolean, default: false | ||
class_option :scope, type: :string, default: "" | ||
class_option :father, type: :string, default: "" | ||
|
||
def create_service_file | ||
template spec_controller_template, controller_test_path | ||
end | ||
|
||
private | ||
|
||
def controller_test_path | ||
"#{API_TEST_DIR_PATH}#{scope_path}/#{file_name.pluralize}_controller_spec.rb" | ||
end | ||
|
||
def spec_controller_template | ||
if options["father"].present? | ||
"rspec/resource_controller_spec.rb" | ||
else | ||
"rspec/nested_resource_controller_spec.rb" | ||
end | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
# frozen_string_literal: true | ||
|
||
require "rails/generators" | ||
require "generators/rest_api_generator/helpers" | ||
|
||
module RestApiGenerator | ||
module Spec | ||
class RswagGenerator < Rails::Generators::NamedBase | ||
include Helpers | ||
source_root File.expand_path("templates", __dir__) | ||
|
||
argument :attributes, type: :array, default: [], banner: "field[:type][:index] field[:type][:index]" | ||
class_option :eject, type: :boolean, default: false | ||
class_option :scope, type: :string, default: "" | ||
class_option :father, type: :string, default: "" | ||
|
||
def create_service_file | ||
template spec_controller_template, controller_test_path | ||
end | ||
|
||
private | ||
|
||
# Changes nested routes for rswag format | ||
# Example: /cars/{car.id}/drivers/{id} | ||
def nested_routes | ||
return "" if options["father"].blank? | ||
|
||
"#{options["father"].downcase.pluralize}/{#{options["father"].singularize.downcase}_id}/#{plural_name}" | ||
end | ||
|
||
def spec_routes | ||
{ | ||
index: initial_route, | ||
show: initial_route + "/{id}", | ||
create: initial_route, | ||
update: initial_route + "/{id}", | ||
delete: initial_route + "/{id}", | ||
} | ||
end | ||
|
||
def controller_test_path | ||
"#{API_TEST_DIR_PATH}#{scope_path}/#{file_name.pluralize}_spec.rb" | ||
end | ||
|
||
def spec_controller_template | ||
if options["father"].present? | ||
"rswag/nested_resource_controller_spec.rb" | ||
else | ||
"rswag/resource_controller_spec.rb" | ||
end | ||
end | ||
end | ||
end | ||
end |
File renamed without changes.
File renamed without changes.
Oops, something went wrong.