rest_framework 0.2.2 → 0.2.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 37a40fca2be23a6fe5fb1f982349ce5dd212644ffe450d979d04c339360b22eb
4
- data.tar.gz: 3e036f7150018a46756efc378dacf16321a9394cb9d04d9b4af7220158400cda
3
+ metadata.gz: '09c24135bd79001e0113aa92f21e63c5dcb67e93891db2a5df36b4d83d1c5da2'
4
+ data.tar.gz: ba3bd5829fdb9fd3c61a6050f5800c91a0077c76e78aedb049f850e581027f67
5
5
  SHA512:
6
- metadata.gz: 9c4a665ccde25d1c53423c168d1e5849d4ba4b91a2a0bcf6fb1f3b3714b624112d951c06aa84029aeaeb7c3703b30e8c73824688070370b3f0e9e3c3d2fd70ec
7
- data.tar.gz: 6a4511553767ed27726a9d12daf0cd46958fe2098566f0daff5c1f9056bfbfa8c26836646b76e3f4a22a1efbea341dc6cb682a04c7c1b5b7635b46cc56548c3a
6
+ metadata.gz: c89c8af64c2eeb36dba79747770df5497d8505f2a4ced03ed6e25e81804a3a8a8f656e87bb0739a31d26be8e1f0fdcdd9e3df25721766e2e5d4bb2a01d40746f
7
+ data.tar.gz: 4bd5bdf9f2735622a07795245f605137c0310d16b3596fc544e9ade2046744a499ea0fdf1e7f11c7f5fc49f137650cceefadcf805884e6a6df5361ed919211d4
@@ -1 +1 @@
1
- 0.2.2
1
+ 0.2.3
@@ -124,7 +124,9 @@ module RESTFramework::BaseControllerMixin
124
124
  begin
125
125
  formatter = ActionDispatch::Routing::ConsoleFormatter::Sheet
126
126
  rescue NameError
127
+ # :nocov:
127
128
  formatter = ActionDispatch::Routing::ConsoleFormatter
129
+ # :nocov:
128
130
  end
129
131
  return ActionDispatch::Routing::RoutesInspector.new(Rails.application.routes.routes).format(
130
132
  formatter.new
@@ -1,26 +1,67 @@
1
1
  require 'rails/generators'
2
2
 
3
3
 
4
+ # Some projects don't have the inflection "REST" as an acronym, so this is a helper class to prevent
5
+ # this generator from being namespaced under `r_e_s_t_framework`.
6
+ # :nocov:
7
+ class RESTFrameworkCustomGeneratorControllerNamespace < String
8
+ def camelize
9
+ return "RESTFramework"
10
+ end
11
+ end
12
+ # :nocov:
13
+
14
+
4
15
  class RESTFramework::Generators::ControllerGenerator < Rails::Generators::Base
16
+ PATH_REGEX = /^\/*([a-z0-9_\/]*[a-z0-9_])(?:[\.a-z\/]*)$/
17
+
5
18
  desc <<~END
6
- Description:
7
- Stubs out a active_scaffolded controller. Pass the model name,
8
- either CamelCased or under_scored.
9
- The controller name is retrieved as a pluralized version of the model
10
- name.
11
- To create a controller within a module, specify the model name as a
12
- path like 'parent_module/controller_name'.
13
- This generates a controller class in app/controllers and invokes helper,
14
- template engine and test framework generators.
15
- Example:
16
- `rails generate rest_framework:controller CreditCard`
17
- Credit card controller with URLs like /credit_card/debit.
18
- Controller: app/controllers/credit_cards_controller.rb
19
- Functional Test: test/functional/credit_cards_controller_test.rb
20
- Helper: app/helpers/credit_cards_helper.rb
19
+ Description:
20
+ Generates a new REST Framework controller.
21
+
22
+ Specify the controller as a path, including the module, if needed, like:
23
+ 'parent_module/controller_name'.
24
+
25
+ Example:
26
+ `rails generate rest_framework:controller user_api/groups`
27
+
28
+ Generates a controller at `app/controllers/user_api/groups_controller.rb` named
29
+ `UserApi::GroupsController`.
21
30
  END
22
31
 
23
- def create_controller_file
24
- create_file "app/controllers/some_controller.rb", "# Add initialization content here"
32
+ argument :path, type: :string
33
+ class_option(
34
+ :parent_class,
35
+ type: :string,
36
+ default: 'ApplicationController',
37
+ desc: "Inheritance parent",
38
+ )
39
+ class_option(
40
+ :include_base,
41
+ type: :boolean,
42
+ default: false,
43
+ desc: "Include `BaseControllerMixin`, not `ModelControllerMixin`",
44
+ )
45
+
46
+ # Some projects may not have the inflection "REST" as an acronym, which changes this generator to
47
+ # be namespaced in `r_e_s_t_framework`, which is weird.
48
+ def self.namespace
49
+ return RESTFrameworkCustomGeneratorControllerNamespace.new("rest_framework:controller")
50
+ end
51
+
52
+ def create_rest_controller_file
53
+ unless (path_match = PATH_REGEX.match(self.path))
54
+ raise StandardError.new("Path isn't correct.")
55
+ end
56
+
57
+ cleaned_path = path_match[1]
58
+ content = <<~END
59
+ class #{cleaned_path.camelize}Controller < #{options[:parent_class]}
60
+ include RESTFramework::#{
61
+ options[:include_base] ? "BaseControllerMixin" : "ModelControllerMixin"
62
+ }
63
+ end
64
+ END
65
+ create_file("app/controllers/#{path}_controller.rb", content)
25
66
  end
26
67
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rest_framework
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gregory N. Schmit
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-03-28 00:00:00.000000000 Z
11
+ date: 2021-03-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails