undercarriage 0.1.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (25) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +42 -4
  3. data/lib/undercarriage.rb +15 -3
  4. data/lib/undercarriage/controllers/action_concern.rb +18 -0
  5. data/lib/undercarriage/controllers/kaminari_concern.rb +11 -0
  6. data/lib/undercarriage/controllers/locale_concern.rb +7 -1
  7. data/lib/undercarriage/controllers/restful/actions/base_concern.rb +120 -0
  8. data/lib/undercarriage/controllers/restful/actions/create_concern.rb +107 -0
  9. data/lib/undercarriage/controllers/restful/actions/destroy_concern.rb +97 -0
  10. data/lib/undercarriage/controllers/restful/actions/edit_concern.rb +94 -0
  11. data/lib/undercarriage/controllers/restful/actions/index_concern.rb +85 -0
  12. data/lib/undercarriage/controllers/restful/actions/new_concern.rb +96 -0
  13. data/lib/undercarriage/controllers/restful/actions/show_concern.rb +91 -0
  14. data/lib/undercarriage/controllers/restful/actions/update_concern.rb +105 -0
  15. data/lib/undercarriage/controllers/restful/flash_concern.rb +112 -0
  16. data/lib/undercarriage/controllers/restful/location_after_concern.rb +79 -0
  17. data/lib/undercarriage/controllers/restful/namespace_concern.rb +41 -0
  18. data/lib/undercarriage/controllers/restful/permitted_attributes_concern.rb +109 -0
  19. data/lib/undercarriage/controllers/restful/utility_concern.rb +74 -0
  20. data/lib/undercarriage/controllers/restful_concern.rb +34 -0
  21. data/lib/undercarriage/models/published_concern.rb +120 -0
  22. data/lib/undercarriage/version.rb +4 -1
  23. metadata +17 -4
  24. data/lib/tasks/undercarriage_tasks.rake +0 -6
  25. data/lib/undercarriage/railtie.rb +0 -6
@@ -0,0 +1,97 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Undercarriage
4
+ # :nodoc:
5
+ module Controllers
6
+ # :nodoc:
7
+ module Restful
8
+ # :nodoc:
9
+ module Actions
10
+ ##
11
+ # Destroy restful action
12
+ #
13
+ # Usage
14
+ # class ExamplesController < ApplicationController
15
+ # include Undercarriage::Controllers::RestfulConcern
16
+ # end
17
+ #
18
+ module DestroyConcern
19
+ extend ActiveSupport::Concern
20
+
21
+ included do
22
+ before_action :destroy_resource, only: %i[destroy]
23
+ end
24
+
25
+ ##
26
+ # Destroy action
27
+ #
28
+ # Usage
29
+ # class ExamplesController < ApplicationController
30
+ # include Undercarriage::Controllers::RestfulConcern
31
+ #
32
+ # ##
33
+ # # This method is only needed if you want to override the action entirely. Otherwise, it is not needed.
34
+ # # Database resources can be accessed as `@destroy_resource` or `@example`
35
+ # #
36
+ # # def destroy
37
+ # # ...
38
+ # # end
39
+ # end
40
+ #
41
+ def destroy
42
+ @destroy_resource.destroy
43
+
44
+ flash[flash_status_type] = flash_destroyed_message
45
+
46
+ redirect_to location_after_destroy
47
+ end
48
+
49
+ protected
50
+
51
+ ##
52
+ # Destroy restful action
53
+ #
54
+ # Usage
55
+ # class ExamplesController < ApplicationController
56
+ # include Undercarriage::Controllers::RestfulConcern
57
+ #
58
+ # ##
59
+ # # This method is only needed if you want to override the query entirely. Otherwise, it is not needed.
60
+ # # Database resources can be accessed as `@example`
61
+ # #
62
+ # # def destroy_resource_content
63
+ # # ...
64
+ # # end
65
+ #
66
+ # ##
67
+ # # To add authorization through something like Pundit, the following could be used
68
+ # #
69
+ # # def destroy_resource_content
70
+ # # super
71
+ # #
72
+ # # authorize @example
73
+ # # end
74
+ #
75
+ # ##
76
+ # # The `resource_content` method can also be overwritten. Be careful with this because the `show`,
77
+ # # `edit` and `update` actions will also use this method
78
+ # #
79
+ # # def resource_content
80
+ # # ...
81
+ # # end
82
+ # end
83
+ #
84
+ def destroy_resource_content
85
+ resource_content
86
+ end
87
+
88
+ private
89
+
90
+ def destroy_resource
91
+ @destroy_resource ||= destroy_resource_content
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
97
+ end
@@ -0,0 +1,94 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Undercarriage
4
+ # :nodoc:
5
+ module Controllers
6
+ # :nodoc:
7
+ module Restful
8
+ # :nodoc:
9
+ module Actions
10
+ ##
11
+ # Edit restful action
12
+ #
13
+ # Usage
14
+ # class ExamplesController < ApplicationController
15
+ # include Undercarriage::Controllers::RestfulConcern
16
+ # end
17
+ #
18
+ module EditConcern
19
+ extend ActiveSupport::Concern
20
+
21
+ included do
22
+ before_action :edit_resource, only: %i[edit]
23
+ end
24
+
25
+ ##
26
+ # Edit action
27
+ #
28
+ # Usage
29
+ # class ExamplesController < ApplicationController
30
+ # include Undercarriage::Controllers::RestfulConcern
31
+ #
32
+ # ##
33
+ # # This method is only needed if you want to override the action entirely. Otherwise, it is not needed.
34
+ # # Database resources can be accessed as `@edit_resource` or `@example`
35
+ # #
36
+ # # def edit
37
+ # # ...
38
+ # # end
39
+ # end
40
+ #
41
+ def edit
42
+ nested_resource_pre_build
43
+ nested_resource_build
44
+ end
45
+
46
+ protected
47
+
48
+ ##
49
+ # Edit restful action
50
+ #
51
+ # Usage
52
+ # class ExamplesController < ApplicationController
53
+ # include Undercarriage::Controllers::RestfulConcern
54
+ #
55
+ # ##
56
+ # # This method is only needed if you want to override the query entirely. Otherwise, it is not needed.
57
+ # # Database resources can be accessed as `@example`
58
+ # #
59
+ # # def edit_resource_content
60
+ # # ...
61
+ # # end
62
+ #
63
+ # ##
64
+ # # To add authorization through something like Pundit, the following could be used
65
+ # #
66
+ # # def edit_resource_content
67
+ # # super
68
+ # #
69
+ # # authorize @example
70
+ # # end
71
+ #
72
+ # ##
73
+ # # The `resource_content` method can also be overwritten. Be careful with this because the `show`,
74
+ # # `update` and `destroy` actions will also use this method
75
+ # #
76
+ # # def resource_content
77
+ # # ...
78
+ # # end
79
+ # end
80
+ #
81
+ def edit_resource_content
82
+ resource_content
83
+ end
84
+
85
+ private
86
+
87
+ def edit_resource
88
+ @edit_resource ||= edit_resource_content
89
+ end
90
+ end
91
+ end
92
+ end
93
+ end
94
+ end
@@ -0,0 +1,85 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Undercarriage
4
+ # :nodoc:
5
+ module Controllers
6
+ # :nodoc:
7
+ module Restful
8
+ # :nodoc:
9
+ module Actions
10
+ ##
11
+ # Index restful action
12
+ #
13
+ # Usage
14
+ # class ExamplesController < ApplicationController
15
+ # include Undercarriage::Controllers::RestfulConcern
16
+ # end
17
+ #
18
+ module IndexConcern
19
+ extend ActiveSupport::Concern
20
+
21
+ included do
22
+ before_action :index_resources, only: %i[index]
23
+ end
24
+
25
+ ##
26
+ # Index action
27
+ #
28
+ # Usage
29
+ # class ExamplesController < ApplicationController
30
+ # include Undercarriage::Controllers::RestfulConcern
31
+ #
32
+ # ##
33
+ # # This method is only needed if you want to override the action entirely. Otherwise, it is not needed.
34
+ # # Database resources can be accessed as `@index_resources` or `@examples`
35
+ # #
36
+ # # def index
37
+ # # ...
38
+ # # end
39
+ # end
40
+ #
41
+ def index; end
42
+
43
+ protected
44
+
45
+ ##
46
+ # Index restful action
47
+ #
48
+ # Usage
49
+ # class ExamplesController < ApplicationController
50
+ # include Undercarriage::Controllers::RestfulConcern
51
+ #
52
+ # ##
53
+ # # This method is only needed if you want to override the query entirely. Otherwise, it is not needed.
54
+ # # Database resources can be accessed as `@examples`
55
+ # #
56
+ # # def resources_content
57
+ # # ...
58
+ # # end
59
+ #
60
+ # ##
61
+ # # To add authorization through something like Pundit, the following could be used
62
+ # #
63
+ # # def resources_content
64
+ # # super
65
+ # #
66
+ # # authorize @examples
67
+ # # end
68
+ # end
69
+ #
70
+ def resources_content
71
+ resources_query = model_class.all
72
+
73
+ instance_variable_set("@#{instances_name}", resources_query)
74
+ end
75
+
76
+ private
77
+
78
+ def index_resources
79
+ @index_resources ||= resources_content
80
+ end
81
+ end
82
+ end
83
+ end
84
+ end
85
+ end
@@ -0,0 +1,96 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Undercarriage
4
+ # :nodoc:
5
+ module Controllers
6
+ # :nodoc:
7
+ module Restful
8
+ # :nodoc:
9
+ module Actions
10
+ ##
11
+ # New restful action
12
+ #
13
+ # Usage
14
+ # class ExamplesController < ApplicationController
15
+ # include Undercarriage::Controllers::RestfulConcern
16
+ # end
17
+ #
18
+ module NewConcern
19
+ extend ActiveSupport::Concern
20
+
21
+ included do
22
+ before_action :new_resource, only: %i[new]
23
+ end
24
+
25
+ ##
26
+ # New action
27
+ #
28
+ # Usage
29
+ # class ExamplesController < ApplicationController
30
+ # include Undercarriage::Controllers::RestfulConcern
31
+ #
32
+ # ##
33
+ # # This method is only needed if you want to override the action entirely. Otherwise, it is not needed.
34
+ # # Database resources can be accessed as `@new_resource` or `@example`
35
+ # #
36
+ # # def new
37
+ # # ...
38
+ # # end
39
+ # end
40
+ #
41
+ def new
42
+ nested_resource_pre_build
43
+ nested_resource_build
44
+ end
45
+
46
+ protected
47
+
48
+ ##
49
+ # New restful action
50
+ #
51
+ # Usage
52
+ # class ExamplesController < ApplicationController
53
+ # include Undercarriage::Controllers::RestfulConcern
54
+ #
55
+ # ##
56
+ # # This method is only needed if you want to override the query entirely. Otherwise, it is not needed.
57
+ # # Database resources can be accessed as `@example`
58
+ # #
59
+ # # def new_resource_content
60
+ # # ...
61
+ # # end
62
+ #
63
+ # ##
64
+ # # To add authorization through something like Pundit, the following could be used
65
+ # #
66
+ # # def new_resource_content
67
+ # # super
68
+ # #
69
+ # # authorize @example
70
+ # # end
71
+ #
72
+ # ##
73
+ # # The `resource_new_content` method can also be overwritten. This method is meant to share content with
74
+ # # the `create` action
75
+ # #
76
+ # # def resource_new_content
77
+ # # ...
78
+ # # end
79
+ # end
80
+ #
81
+ def new_resource_content
82
+ resource_query = model_class.new
83
+
84
+ instance_variable_set("@#{instance_name}", resource_query)
85
+ end
86
+
87
+ private
88
+
89
+ def new_resource
90
+ @new_resource ||= resource_new_content
91
+ end
92
+ end
93
+ end
94
+ end
95
+ end
96
+ end
@@ -0,0 +1,91 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Undercarriage
4
+ # :nodoc:
5
+ module Controllers
6
+ # :nodoc:
7
+ module Restful
8
+ # :nodoc:
9
+ module Actions
10
+ ##
11
+ # Show restful action
12
+ #
13
+ # Usage
14
+ # class ExamplesController < ApplicationController
15
+ # include Undercarriage::Controllers::RestfulConcern
16
+ # end
17
+ #
18
+ module ShowConcern
19
+ extend ActiveSupport::Concern
20
+
21
+ included do
22
+ before_action :show_resource, only: %i[show]
23
+ end
24
+
25
+ ##
26
+ # Show action
27
+ #
28
+ # Usage
29
+ # class ExamplesController < ApplicationController
30
+ # include Undercarriage::Controllers::RestfulConcern
31
+ #
32
+ # ##
33
+ # # This method is only needed if you want to override the action entirely. Otherwise, it is not needed.
34
+ # # Database resources can be accessed as `@show_resource` or `@example`
35
+ # #
36
+ # # def show
37
+ # # ...
38
+ # # end
39
+ # end
40
+ #
41
+ def show; end
42
+
43
+ protected
44
+
45
+ ##
46
+ # Show restful action
47
+ #
48
+ # Usage
49
+ # class ExamplesController < ApplicationController
50
+ # include Undercarriage::Controllers::RestfulConcern
51
+ #
52
+ # ##
53
+ # # This method is only needed if you want to override the query entirely. Otherwise, it is not needed.
54
+ # # Database resources can be accessed as `@example`
55
+ # #
56
+ # # def show_resource_content
57
+ # # ...
58
+ # # end
59
+ #
60
+ # ##
61
+ # # To add authorization through something like Pundit, the following could be used
62
+ # #
63
+ # # def show_resource_content
64
+ # # super
65
+ # #
66
+ # # authorize @example
67
+ # # end
68
+ #
69
+ # ##
70
+ # # The `resource_content` method can also be overwritten. Be careful with this because the `edit`,
71
+ # # `update`, and `destroy` actions will also use this method
72
+ # #
73
+ # # def resource_content
74
+ # # ...
75
+ # # end
76
+ # end
77
+ #
78
+ def show_resource_content
79
+ resource_content
80
+ end
81
+
82
+ private
83
+
84
+ def show_resource
85
+ @show_resource ||= show_resource_content
86
+ end
87
+ end
88
+ end
89
+ end
90
+ end
91
+ end