rest-api-generator 0.1.3 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a3c84db27490fa76b76096f10ba351092bfb42479890a2a279d725f579c4edb7
4
- data.tar.gz: 25e537cd496a09eb3b5755fadf4d04bbcaad38c941bf54af60e230ed7a1ccd13
3
+ metadata.gz: 04727c112f46dd53f0ab7b45c0e83c13ddd3ae2df45fed5b3aa89cf7fac6efa4
4
+ data.tar.gz: 8de60fa55662ef20a6390af3da742c5873e3a2499598790afe759e0afae00352
5
5
  SHA512:
6
- metadata.gz: a0f07b832a6373ed5197f114a0bdc54c6a6c2088d712e3641b8d55d717a5d5b019bba3427907b73495ac6a97de2bfbdd68ee48de267651808cf3d6adbe9f2547
7
- data.tar.gz: 565c3cc7797794a6c59008990e58727173c5fa472ef8a8a188cb2a2ba60789cf03994ba8feaff7d8d5dfcf3443333412ece5dbb926f5a44156fa71ad240531b0
6
+ metadata.gz: 585ad32f866f1e0374dd6051c91ee898a382ed67b1995c511536e3548ed25cc0731725980570ef814d9782d73803b94fd78183af5eee137ed8a054cfb3ab2850
7
+ data.tar.gz: 68aedf154d0f0b0472cc082d5cbf8ec47e2276070a60963aa8ab58cbb827221fcde13c709e4d7dcd3341ac6a7787a9373fd7564d904b0595aabd165f009ac41e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- rest-api-generator (0.1.3)
4
+ rest-api-generator (0.1.4)
5
5
  rails (>= 5.0)
6
6
 
7
7
  GEM
@@ -78,6 +78,8 @@ GEM
78
78
  activesupport (>= 3.0)
79
79
  railties (>= 3.0)
80
80
  rspec-rails (>= 2.2)
81
+ anyway_config (2.3.1)
82
+ ruby-next-core (>= 0.14.0)
81
83
  ast (2.4.2)
82
84
  builder (3.2.4)
83
85
  concurrent-ruby (1.1.10)
@@ -218,6 +220,7 @@ GEM
218
220
  rubocop (~> 1.33)
219
221
  rubocop-shopify (2.10.1)
220
222
  rubocop (~> 1.35)
223
+ ruby-next-core (0.15.3)
221
224
  ruby-progressbar (1.11.0)
222
225
  sqlite3 (1.5.4-x86_64-linux)
223
226
  switchcop (0.1.2)
@@ -237,10 +240,12 @@ GEM
237
240
  zeitwerk (2.6.6)
238
241
 
239
242
  PLATFORMS
243
+ ruby
240
244
  x86_64-linux
241
245
 
242
246
  DEPENDENCIES
243
247
  ammeter (~> 1.1.5)
248
+ anyway_config (>= 2.0.0)
244
249
  database_cleaner
245
250
  rake (~> 13.0)
246
251
  rest-api-generator!
data/README.md CHANGED
@@ -243,6 +243,20 @@ This spec options work as generators too, so you can call them individually:
243
243
  rails g rest_api_generator:spec:rswag Car name:string color:string
244
244
  ```
245
245
 
246
+ ##### Custom paths
247
+
248
+ By default, the plain rspec and rswag specs are going to be generated in the _spec/requests_ and _spec/docs_
249
+ directories, respectively. You can override this configuration with an initializer inside your project:
250
+
251
+ ```rb
252
+ # config/initializers/rest_api_generator.rb
253
+
254
+ RestApiGenerator.configure do |config|
255
+ config.test_path = "custom_test_dir/requests"
256
+ config.docs_path = "custom_docs_dir/rswag"
257
+ end
258
+ ```
259
+
246
260
  ### Resource Features
247
261
 
248
262
  #### Modular Error Handler
@@ -5,7 +5,8 @@ module RestApiGenerator
5
5
  attr_accessor :options, :attributes
6
6
 
7
7
  API_CONTROLLER_DIR_PATH = "app/controllers"
8
- API_TEST_DIR_PATH = "spec/requests"
8
+ API_TEST_DIR_PATH = RestApiGenerator.configuration.test_path
9
+ API_DOCS_DIR_PATH = RestApiGenerator.configuration.docs_path
9
10
 
10
11
  private
11
12
 
@@ -71,22 +72,24 @@ module RestApiGenerator
71
72
  def nested_routes
72
73
  return "" if options["father"].blank?
73
74
 
74
- "#{options["father"].downcase.pluralize}/\#{#{options["father"].singularize.downcase}.id}/#{plural_name}"
75
+ "#{options["father"].downcase.pluralize}/\#{#{options["father"].singularize.downcase}.id}"
75
76
  end
76
77
 
77
78
  def initial_route
78
- return "/#{plural_name}" if options["father"].blank? && options["scope"].blank?
79
-
80
- scope_route_path + "/" + nested_routes
79
+ route = ""
80
+ route += scope_route_path if options["scope"].present?
81
+ route += options["father"].present? && route.present? ? "/#{nested_routes}" : nested_routes
82
+ route += "/#{plural_name}"
83
+ route[0] == "/" ? route : "/#{route}"
81
84
  end
82
85
 
83
86
  def spec_routes
84
87
  {
85
88
  index: initial_route,
86
- show: initial_route + "\#{#{singular_name}.id}",
89
+ show: initial_route + "/\#{#{singular_name}.id}",
87
90
  create: initial_route,
88
- update: initial_route + "\#{#{singular_name}.id}",
89
- delete: initial_route + "\#{#{singular_name}.id}",
91
+ update: initial_route + "/\#{#{singular_name}.id}",
92
+ delete: initial_route + "/\#{#{singular_name}.id}",
90
93
  }
91
94
  end
92
95
  end
@@ -26,9 +26,9 @@ module RestApiGenerator
26
26
 
27
27
  def spec_controller_template
28
28
  if options["father"].present?
29
- "rspec/resource_controller_spec.rb"
30
- else
31
29
  "rspec/nested_resource_controller_spec.rb"
30
+ else
31
+ "rspec/resource_controller_spec.rb"
32
32
  end
33
33
  end
34
34
  end
@@ -25,7 +25,7 @@ module RestApiGenerator
25
25
  def nested_routes
26
26
  return "" if options["father"].blank?
27
27
 
28
- "#{options["father"].downcase.pluralize}/{#{options["father"].singularize.downcase}_id}/#{plural_name}"
28
+ "#{options["father"].downcase.pluralize}/{#{options["father"].singularize.downcase}_id}"
29
29
  end
30
30
 
31
31
  def spec_routes
@@ -39,7 +39,7 @@ module RestApiGenerator
39
39
  end
40
40
 
41
41
  def controller_test_path
42
- "#{API_TEST_DIR_PATH}#{scope_path}/#{file_name.pluralize}_spec.rb"
42
+ "#{API_DOCS_DIR_PATH}#{scope_path}/#{file_name.pluralize}_spec.rb"
43
43
  end
44
44
 
45
45
  def spec_controller_template
@@ -38,7 +38,7 @@ RSpec.describe "<%= class_name %>", type: :request do
38
38
 
39
39
  describe "DELETE /<%= plural_name %>/:id" do
40
40
  it "deletes an <%= plural_name %>" do
41
- item = create(:<%= singular_name %>)
41
+ <%= singular_name %> = create(:<%= singular_name %>)
42
42
  expect do
43
43
  delete "<%= spec_routes[:delete] %>"
44
44
  end.to change(<%= class_name %>, :count).by(-1)
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "anyway_config"
4
+
5
+ module RestApiGenerator
6
+ class Config < Anyway::Config
7
+ config_name :rest_api_generator
8
+
9
+ attr_config test_path: "spec/requests", docs_path: "spec/docs"
10
+ end
11
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RestApiGenerator
4
- VERSION = "0.1.3"
4
+ VERSION = "0.1.5"
5
5
  end
@@ -4,6 +4,7 @@ require "rails"
4
4
  require_relative "rest_api_generator/version"
5
5
  require_relative "rest_api_generator/application_controller"
6
6
  require_relative "rest_api_generator/error_handler"
7
+ require_relative "rest_api_generator/config"
7
8
  require_relative "rest_api_generator/custom_error"
8
9
  require_relative "rest_api_generator/helpers/render"
9
10
  require_relative "rest_api_generator/filterable"
@@ -12,6 +13,16 @@ require_relative "rest_api_generator/orderable"
12
13
  module RestApiGenerator
13
14
  class Error < StandardError; end
14
15
 
16
+ class << self
17
+ def configuration
18
+ @configuration ||= Config.new
19
+ end
20
+
21
+ def configure
22
+ yield(configuration)
23
+ end
24
+ end
25
+
15
26
  def self.parent_controller
16
27
  "RestApiGenerator::ApplicationController"
17
28
  end
@@ -35,6 +35,7 @@ Gem::Specification.new do |spec|
35
35
  spec.add_dependency "rails", ">= 5.0"
36
36
 
37
37
  spec.add_development_dependency "ammeter", "~> 1.1.5"
38
+ spec.add_development_dependency "anyway_config", ">= 2.0.0"
38
39
  spec.add_development_dependency "database_cleaner"
39
40
  spec.add_development_dependency "rspec-rails", "~> 6.0.0"
40
41
  spec.add_development_dependency "rswag"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest-api-generator
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - PedroAugustoRamalhoDuarte
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-01-06 00:00:00.000000000 Z
11
+ date: 2023-03-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -38,6 +38,20 @@ dependencies:
38
38
  - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: 1.1.5
41
+ - !ruby/object:Gem::Dependency
42
+ name: anyway_config
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: 2.0.0
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: 2.0.0
41
55
  - !ruby/object:Gem::Dependency
42
56
  name: database_cleaner
43
57
  requirement: !ruby/object:Gem::Requirement
@@ -125,6 +139,7 @@ files:
125
139
  - lib/rest_api_generator.rb
126
140
  - lib/rest_api_generator/application_controller.rb
127
141
  - lib/rest_api_generator/child_resource_controller.rb
142
+ - lib/rest_api_generator/config.rb
128
143
  - lib/rest_api_generator/custom_error.rb
129
144
  - lib/rest_api_generator/error_handler.rb
130
145
  - lib/rest_api_generator/filterable.rb
@@ -158,7 +173,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
158
173
  - !ruby/object:Gem::Version
159
174
  version: '0'
160
175
  requirements: []
161
- rubygems_version: 3.3.7
176
+ rubygems_version: 3.3.3
162
177
  signing_key:
163
178
  specification_version: 4
164
179
  summary: Build a Ruby on Rails REST API faster