inherited_resources 1.7.0 → 2.1.0
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 +5 -5
- data/MIT-LICENSE +1 -1
- data/README.md +40 -11
- data/app/controllers/inherited_resources/base.rb +5 -4
- data/lib/generators/rails/inherited_resources_controller_generator.rb +3 -1
- data/lib/generators/rails/templates/{controller.rb → controller.rb.tt} +1 -3
- data/lib/inherited_resources/actions.rb +3 -2
- data/lib/inherited_resources/base_helpers.rb +30 -32
- data/lib/inherited_resources/belongs_to_helpers.rb +9 -7
- data/lib/inherited_resources/blank_slate.rb +3 -1
- data/lib/inherited_resources/class_methods.rb +23 -16
- data/lib/inherited_resources/dsl.rb +2 -0
- data/lib/inherited_resources/engine.rb +13 -0
- data/lib/inherited_resources/polymorphic_helpers.rb +12 -9
- data/lib/inherited_resources/responder.rb +6 -2
- data/lib/inherited_resources/shallow_helpers.rb +3 -1
- data/lib/inherited_resources/singleton_helpers.rb +2 -0
- data/lib/inherited_resources/url_helpers.rb +171 -162
- data/lib/inherited_resources/version.rb +2 -1
- data/lib/inherited_resources.rb +12 -12
- metadata +24 -34
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: aaebb8b497c48f9057e36c1dcf828487b28fec89e6b71c586b358e402fd34984
|
4
|
+
data.tar.gz: 5e52d03746f0c38b5dc1babb70e52e8f0c563613e67fa6ce1169e0ec130472e7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcdda43c097f8a9e75d5711ca5268b6b4b01c0462bd46084b30e48d880fdd2334399885f54dc966f6ecbac38390c25805c5f31333e467c892be2ae3a10afc9a0
|
7
|
+
data.tar.gz: ec4aede5a01a46cc309e2254d2817d4d9e5a134f15dec60590c1473ce723c5a170152188e89048ace1aae0c2d2cf54b81cdb25628b1b6ac1dcbf47dccef49276
|
data/MIT-LICENSE
CHANGED
data/README.md
CHANGED
@@ -1,16 +1,17 @@
|
|
1
1
|
## Notice
|
2
|
-
|
2
|
+
|
3
3
|
Inherited Resources is no longer actively maintained by the original author and
|
4
4
|
has been transferred to the ActiveAdmin organization for maintenance. New feature
|
5
5
|
requests are not encouraged.
|
6
6
|
|
7
|
-
If you are not already using Inherited Resources we suggest instead using Rails'
|
8
|
-
`respond_with` feature alongside the [responders gem](https://github.com/
|
7
|
+
If you are not already using Inherited Resources we suggest instead using Rails'
|
8
|
+
`respond_with` feature alongside the [responders gem](https://github.com/heartcombo/responders).
|
9
9
|
|
10
10
|
## Inherited Resources
|
11
11
|
|
12
|
-
[![Version ]
|
13
|
-
[![
|
12
|
+
[![Version ][rubygems_badge]][rubygems]
|
13
|
+
[![Github Actions ][actions_badge]][actions]
|
14
|
+
[![Tidelift ][tidelift_badge]][tidelift]
|
14
15
|
|
15
16
|
Inherited Resources speeds up development by making your controllers inherit
|
16
17
|
all restful actions so you just have to focus on what is important. It makes
|
@@ -21,7 +22,7 @@ code by following fat models and skinny controllers convention. There are
|
|
21
22
|
two screencasts available besides this README:
|
22
23
|
|
23
24
|
* http://railscasts.com/episodes/230-inherited-resources
|
24
|
-
*
|
25
|
+
* https://www.akitaonrails.com/2009/09/01/screencast-real-thin-restful-controllers-with-inherited-resources
|
25
26
|
|
26
27
|
## Installation
|
27
28
|
|
@@ -48,7 +49,7 @@ $ gem install inherited_resources
|
|
48
49
|
Since Inherited Resources 1.0, has_scope is not part of its core anymore but
|
49
50
|
a gem dependency. Be sure to check the documentation to see how you can use it:
|
50
51
|
|
51
|
-
- <
|
52
|
+
- <https://github.com/heartcombo/has_scope>
|
52
53
|
|
53
54
|
And it can be installed as:
|
54
55
|
|
@@ -63,7 +64,7 @@ but is set as Inherited Resources dependency and it's used by default by
|
|
63
64
|
InheritedResources controllers. Be sure to check the documentation to see
|
64
65
|
how it will change your application:
|
65
66
|
|
66
|
-
- <
|
67
|
+
- <https://github.com/heartcombo/responders>
|
67
68
|
|
68
69
|
And it can be installed with:
|
69
70
|
|
@@ -167,6 +168,13 @@ class AccountsController < ApplicationController
|
|
167
168
|
end
|
168
169
|
```
|
169
170
|
|
171
|
+
By default, `InheritedResources::Base` will inherit from `::ApplicationController`. You can change this in a rails initializer:
|
172
|
+
|
173
|
+
```ruby
|
174
|
+
# config/initializers/inherited_resources.rb
|
175
|
+
InheritedResources.parent_controller = 'MyController'
|
176
|
+
```
|
177
|
+
|
170
178
|
## Overwriting defaults
|
171
179
|
|
172
180
|
Whenever you inherit from InheritedResources, several defaults are assumed.
|
@@ -188,7 +196,7 @@ different route prefix you can do the following:
|
|
188
196
|
|
189
197
|
```ruby
|
190
198
|
class Administrators::PeopleController < InheritedResources::Base
|
191
|
-
defaults :route_prefix =>
|
199
|
+
defaults :route_prefix => :admin
|
192
200
|
end
|
193
201
|
```
|
194
202
|
|
@@ -634,7 +642,7 @@ end
|
|
634
642
|
```
|
635
643
|
|
636
644
|
This code creates delete and search actions in controller (they behaves like show and
|
637
|
-
index actions accordingly). Also, it will produce `delete_resource_{path,url}` and
|
645
|
+
index actions accordingly). Also, it will produce `delete_resource_{path,url}` and
|
638
646
|
`search_resources_{path,url}` url helpers.
|
639
647
|
|
640
648
|
## What about views?
|
@@ -715,6 +723,13 @@ end
|
|
715
723
|
|
716
724
|
In such case you should remove #permitted_params method because it has greater priority.
|
717
725
|
|
726
|
+
## Funding
|
727
|
+
|
728
|
+
If you want to support us financially, you can [help fund the project
|
729
|
+
through a Tidelift subscription][tidelift]. By buying a Tidelift subscription
|
730
|
+
you make sure your whole dependency stack is properly maintained, while also
|
731
|
+
getting a comprehensive view of outdated dependencies, new releases, security
|
732
|
+
alerts, and licensing compatibility issues.
|
718
733
|
|
719
734
|
## Bugs and Feedback
|
720
735
|
|
@@ -722,4 +737,18 @@ If you discover any bugs, please describe it in the issues tracker, including Ra
|
|
722
737
|
|
723
738
|
Questions are better handled on StackOverflow.
|
724
739
|
|
725
|
-
MIT License. Copyright (c) 2009-
|
740
|
+
MIT License. Copyright (c) 2009-2017 José Valim.
|
741
|
+
|
742
|
+
## Security contact information
|
743
|
+
|
744
|
+
Please use the Tidelift security contact to [report a security vulnerability][Tidelift security contact].
|
745
|
+
Tidelift will coordinate the fix and disclosure.
|
746
|
+
|
747
|
+
[rubygems_badge]: https://img.shields.io/gem/v/inherited_resources.svg
|
748
|
+
[rubygems]: https://rubygems.org/gems/inherited_resources
|
749
|
+
[actions_badge]: https://github.com/activeadmin/inherited_resources/workflows/ci/badge.svg
|
750
|
+
[actions]: https://github.com/activeadmin/inherited_resources/actions
|
751
|
+
[tidelift_badge]: https://tidelift.com/badges/package/rubygems/inherited_resources?style=flat
|
752
|
+
[tidelift]: https://tidelift.com/subscription/pkg/rubygems-inherited-resources?utm_source=rubygems-inherited-resources&utm_medium=referral&utm_campaign=readme
|
753
|
+
|
754
|
+
[Tidelift security contact]: https://tidelift.com/security
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# frozen_string_literal: true
|
1
2
|
module InheritedResources
|
2
3
|
# = Base
|
3
4
|
#
|
@@ -8,7 +9,7 @@ module InheritedResources
|
|
8
9
|
# call <tt>default</tt> class method, call <<tt>actions</tt> class method
|
9
10
|
# or overwrite some helpers in the base_helpers.rb file.
|
10
11
|
#
|
11
|
-
class Base <
|
12
|
+
class Base < InheritedResources.parent_controller.constantize
|
12
13
|
# Overwrite inherit_resources to add specific InheritedResources behavior.
|
13
14
|
def self.inherit_resources(base)
|
14
15
|
base.class_eval do
|
@@ -30,8 +31,8 @@ module InheritedResources
|
|
30
31
|
:parent_url, :parent_path,
|
31
32
|
:smart_resource_url, :smart_collection_url
|
32
33
|
|
33
|
-
self.class_attribute :resource_class, :
|
34
|
-
self.class_attribute :parents_symbols, :resources_configuration, :
|
34
|
+
self.class_attribute :resource_class, instance_writer: false unless self.respond_to? :resource_class
|
35
|
+
self.class_attribute :parents_symbols, :resources_configuration, instance_writer: false
|
35
36
|
|
36
37
|
protected :resource_class, :parents_symbols, :resources_configuration,
|
37
38
|
:resource_class?, :parents_symbols?, :resources_configuration?
|
@@ -40,4 +41,4 @@ module InheritedResources
|
|
40
41
|
|
41
42
|
inherit_resources(self)
|
42
43
|
end
|
43
|
-
end
|
44
|
+
end
|
@@ -2,13 +2,11 @@ class <%= controller_class_name %>Controller < InheritedResources::Base
|
|
2
2
|
<% if options[:singleton] -%>
|
3
3
|
defaults :singleton => true
|
4
4
|
<% end -%>
|
5
|
-
<% if Rails::VERSION::MAJOR >= 4 || defined?(ActiveModel::ForbiddenAttributesProtection) -%>
|
6
5
|
|
7
6
|
private
|
8
7
|
|
9
8
|
def <%= singular_name %>_params
|
10
9
|
params.require(:<%= singular_name %>).permit(<%= attributes_names.map{ |a_name| ":#{a_name}" }.join(", ") %>)
|
11
10
|
end
|
12
|
-
<% end -%>
|
13
|
-
end
|
14
11
|
|
12
|
+
end
|
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module InheritedResources
|
2
|
-
# Holds all default actions for
|
4
|
+
# Holds all default actions for InheritedResources.
|
3
5
|
module Actions
|
4
6
|
|
5
7
|
# GET /resources
|
@@ -64,4 +66,3 @@ module InheritedResources
|
|
64
66
|
protected :index!, :show!, :new!, :create!, :edit!, :update!, :destroy!
|
65
67
|
end
|
66
68
|
end
|
67
|
-
|
@@ -1,5 +1,7 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
# Whenever base is required load the dumb responder since it's used inside actions.
|
2
|
-
|
4
|
+
require_relative 'blank_slate'
|
3
5
|
|
4
6
|
module InheritedResources
|
5
7
|
# Base helpers for InheritedResource work. Some methods here can be overwritten
|
@@ -22,14 +24,7 @@ module InheritedResources
|
|
22
24
|
def collection
|
23
25
|
get_collection_ivar || begin
|
24
26
|
c = end_of_association_chain
|
25
|
-
|
26
|
-
# ActiveRecord::Base#scoped and ActiveRecord::Relation#all
|
27
|
-
# are deprecated in Rails 4. If it's a relation just use
|
28
|
-
# it, otherwise use .all to get a relation.
|
29
|
-
set_collection_ivar(c.is_a?(ActiveRecord::Relation) ? c : c.all)
|
30
|
-
else
|
31
|
-
set_collection_ivar(c.respond_to?(:scoped) ? c.scoped : c.all)
|
32
|
-
end
|
27
|
+
set_collection_ivar(c.respond_to?(:scoped) ? c.scoped : c.all)
|
33
28
|
end
|
34
29
|
end
|
35
30
|
|
@@ -61,7 +56,7 @@ module InheritedResources
|
|
61
56
|
|
62
57
|
# Responsible for saving the resource on :create method. Overwriting this
|
63
58
|
# allow you to control the way resource is saved. Let's say you have a
|
64
|
-
#
|
59
|
+
# PasswordsController who is responsible for finding an user by email and
|
65
60
|
# sent password instructions for him. Instead of overwriting the entire
|
66
61
|
# :create method, you could do something:
|
67
62
|
#
|
@@ -75,14 +70,14 @@ module InheritedResources
|
|
75
70
|
|
76
71
|
# Responsible for updating the resource in :update method. This allow you
|
77
72
|
# to handle how the resource is going to be updated, let's say in a different
|
78
|
-
# way than the usual :
|
73
|
+
# way than the usual :update:
|
79
74
|
#
|
80
75
|
# def update_resource(object, attributes)
|
81
76
|
# object.reset_password!(attributes)
|
82
77
|
# end
|
83
78
|
#
|
84
79
|
def update_resource(object, attributes)
|
85
|
-
object.
|
80
|
+
object.update(*attributes)
|
86
81
|
end
|
87
82
|
|
88
83
|
# Handle the :destroy method for the resource. Overwrite it to call your
|
@@ -133,25 +128,23 @@ module InheritedResources
|
|
133
128
|
# current resource).
|
134
129
|
#
|
135
130
|
def association_chain
|
136
|
-
@association_chain ||=
|
137
|
-
|
138
|
-
symbols_for_association_chain.reverse
|
139
|
-
else
|
140
|
-
symbols_for_association_chain
|
141
|
-
end
|
142
|
-
|
143
|
-
symbol_chain.inject([begin_of_association_chain]) do |chain, symbol|
|
131
|
+
@association_chain ||=
|
132
|
+
symbols_for_association_chain.inject([begin_of_association_chain]) do |chain, symbol|
|
144
133
|
chain << evaluate_parent(symbol, resources_configuration[symbol], chain.last)
|
145
134
|
end.compact.freeze
|
146
|
-
end
|
147
135
|
end
|
148
136
|
|
137
|
+
# rubocop:disable Layout/CommentIndentation
|
138
|
+
# See https://github.com/rubocop/rubocop/issues/6450
|
139
|
+
#
|
149
140
|
# Overwrite this method to provide other interpolation options when
|
150
141
|
# the flash message is going to be set.
|
151
142
|
#
|
152
|
-
# def
|
143
|
+
# def flash_interpolation_options
|
153
144
|
# { }
|
154
145
|
# end
|
146
|
+
#
|
147
|
+
# rubocop:enable Layout/CommentIndentation
|
155
148
|
|
156
149
|
private
|
157
150
|
|
@@ -223,27 +216,33 @@ module InheritedResources
|
|
223
216
|
# Get resource ivar based on the current resource controller.
|
224
217
|
#
|
225
218
|
def get_resource_ivar #:nodoc:
|
226
|
-
instance_variable_defined?(:"@#{resource_instance_name}")
|
227
|
-
instance_variable_get("@#{resource_instance_name}")
|
219
|
+
if instance_variable_defined?(:"@#{resource_instance_name}")
|
220
|
+
instance_variable_get(:"@#{resource_instance_name}")
|
221
|
+
else
|
222
|
+
nil
|
223
|
+
end
|
228
224
|
end
|
229
225
|
|
230
226
|
# Set resource ivar based on the current resource controller.
|
231
227
|
#
|
232
228
|
def set_resource_ivar(resource) #:nodoc:
|
233
|
-
instance_variable_set("@#{resource_instance_name}", resource)
|
229
|
+
instance_variable_set(:"@#{resource_instance_name}", resource)
|
234
230
|
end
|
235
231
|
|
236
232
|
# Get collection ivar based on the current resource controller.
|
237
233
|
#
|
238
234
|
def get_collection_ivar #:nodoc:
|
239
|
-
instance_variable_defined?(:"@#{resource_collection_name}")
|
240
|
-
instance_variable_get("@#{resource_collection_name}")
|
235
|
+
if instance_variable_defined?(:"@#{resource_collection_name}")
|
236
|
+
instance_variable_get(:"@#{resource_collection_name}")
|
237
|
+
else
|
238
|
+
nil
|
239
|
+
end
|
241
240
|
end
|
242
241
|
|
243
242
|
# Set collection ivar based on the current resource controller.
|
244
243
|
#
|
245
244
|
def set_collection_ivar(collection) #:nodoc:
|
246
|
-
instance_variable_set("@#{resource_collection_name}", collection)
|
245
|
+
instance_variable_set(:"@#{resource_collection_name}", collection)
|
247
246
|
end
|
248
247
|
|
249
248
|
# Used to allow to specify success and failure within just one block:
|
@@ -371,9 +370,9 @@ module InheritedResources
|
|
371
370
|
self.resources_configuration[:self][:role].present?
|
372
371
|
end
|
373
372
|
|
374
|
-
# getting role for mass-
|
373
|
+
# getting role for mass-assignment
|
375
374
|
def as_role
|
376
|
-
{ :
|
375
|
+
{ as: self.resources_configuration[:self][:role] }
|
377
376
|
end
|
378
377
|
|
379
378
|
def without_protection_given?
|
@@ -381,8 +380,7 @@ module InheritedResources
|
|
381
380
|
end
|
382
381
|
|
383
382
|
def without_protection
|
384
|
-
{ :
|
383
|
+
{ without_protection: self.resources_configuration[:self][:without_protection] }
|
385
384
|
end
|
386
385
|
end
|
387
386
|
end
|
388
|
-
|
@@ -1,9 +1,11 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module InheritedResources
|
2
4
|
|
3
5
|
# = belongs_to
|
4
6
|
#
|
5
7
|
# Let's suppose that we have some tasks that belongs to projects. To specify
|
6
|
-
# this
|
8
|
+
# this association in your controllers, just do:
|
7
9
|
#
|
8
10
|
# class TasksController < InheritedResources::Base
|
9
11
|
# belongs_to :project
|
@@ -56,11 +58,11 @@ module InheritedResources
|
|
56
58
|
def parent?
|
57
59
|
true
|
58
60
|
end
|
59
|
-
|
61
|
+
|
60
62
|
def parent
|
61
63
|
@parent ||= association_chain[-1]
|
62
64
|
end
|
63
|
-
|
65
|
+
|
64
66
|
def parent_type
|
65
67
|
parent.class.name.underscore.to_sym
|
66
68
|
end
|
@@ -75,12 +77,12 @@ module InheritedResources
|
|
75
77
|
set_parent_instance(parent_config, chain)
|
76
78
|
end
|
77
79
|
|
78
|
-
def get_parent_ivar(instance_name)
|
80
|
+
def get_parent_ivar(instance_name) #:nodoc:
|
79
81
|
instance_variable_defined?(:"@#{instance_name}") &&
|
80
|
-
instance_variable_get("@#{instance_name}")
|
82
|
+
instance_variable_get(:"@#{instance_name}")
|
81
83
|
end
|
82
84
|
|
83
|
-
def set_parent_instance(parent_config, chain)
|
85
|
+
def set_parent_instance(parent_config, chain) #:nodoc:
|
84
86
|
if parent_config[:singleton]
|
85
87
|
parent = if chain
|
86
88
|
chain.send(parent_config[:instance_name])
|
@@ -97,7 +99,7 @@ module InheritedResources
|
|
97
99
|
parent = parent.send(parent_config[:finder], params[parent_config[:param]])
|
98
100
|
end
|
99
101
|
|
100
|
-
instance_variable_set("@#{parent_config[:instance_name]}", parent)
|
102
|
+
instance_variable_set(:"@#{parent_config[:instance_name]}", parent)
|
101
103
|
end
|
102
104
|
|
103
105
|
# Maps parents_symbols to build association chain. In this case, it
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module InheritedResources
|
2
4
|
# An object from BlankSlate simply discards all messages sent to it.
|
3
5
|
class BlankSlate
|
4
6
|
instance_methods.each do |m|
|
5
|
-
undef_method m unless
|
7
|
+
undef_method m unless /^(__|object_id)/.match?(m)
|
6
8
|
end
|
7
9
|
|
8
10
|
def method_missing(*args)
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module InheritedResources
|
2
4
|
module ClassMethods
|
3
5
|
|
@@ -25,7 +27,7 @@ module InheritedResources
|
|
25
27
|
#
|
26
28
|
# * <tt>:route_instance_name</tt> - The name of the singular route. Defaults to :instance_name.
|
27
29
|
#
|
28
|
-
# * <tt>:route_prefix</tt> - The route prefix which is
|
30
|
+
# * <tt>:route_prefix</tt> - The route prefix which is automatically set in namespaced
|
29
31
|
# controllers. Default to :admin on Admin::ProjectsController.
|
30
32
|
#
|
31
33
|
# * <tt>:singleton</tt> - Tells if this controller is singleton or not.
|
@@ -48,21 +50,24 @@ module InheritedResources
|
|
48
50
|
acts_as_singleton! if options.delete(:singleton)
|
49
51
|
|
50
52
|
config = self.resources_configuration[:self]
|
51
|
-
config[:route_prefix] = options.delete(:route_prefix) if options.key?(:route_prefix)
|
52
53
|
|
53
54
|
if options.key?(:resource_class) or options.key?(:class_name)
|
54
|
-
config[:request_name] =
|
55
|
+
config[:request_name] = begin
|
56
|
+
request_name = self.resource_class
|
57
|
+
request_name = request_name.model_name.param_key if request_name.respond_to?(:model_name)
|
58
|
+
request_name.to_s.underscore.tr('/', '_')
|
59
|
+
end
|
55
60
|
options.delete(:resource_class) and options.delete(:class_name)
|
56
61
|
end
|
57
62
|
|
58
63
|
options.each do |key, value|
|
59
|
-
config[key] = value
|
64
|
+
config[key] = value&.to_sym
|
60
65
|
end
|
61
66
|
|
62
67
|
create_resources_url_helpers!
|
63
68
|
end
|
64
69
|
|
65
|
-
# Defines
|
70
|
+
# Defines which actions will be inherited from the inherited controller.
|
66
71
|
# Syntax is borrowed from resource_controller.
|
67
72
|
#
|
68
73
|
# actions :index, :show, :edit
|
@@ -148,7 +153,10 @@ module InheritedResources
|
|
148
153
|
polymorphic = options.delete(:polymorphic)
|
149
154
|
finder = options.delete(:finder)
|
150
155
|
|
151
|
-
|
156
|
+
if self.parents_symbols.empty?
|
157
|
+
include BelongsToHelpers
|
158
|
+
helper_method :parent, :parent?
|
159
|
+
end
|
152
160
|
|
153
161
|
acts_as_polymorphic! if polymorphic || optional
|
154
162
|
acts_as_shallow! if shallow
|
@@ -175,7 +183,7 @@ module InheritedResources
|
|
175
183
|
config[:parent_class] = options.delete(:parent_class) ||
|
176
184
|
begin
|
177
185
|
class_name = if options[:class_name]
|
178
|
-
options.delete(:class_name)
|
186
|
+
options.delete(:class_name)
|
179
187
|
else
|
180
188
|
namespace = self.name.deconstantize
|
181
189
|
model_name = symbol.to_s.pluralize.classify
|
@@ -209,12 +217,11 @@ module InheritedResources
|
|
209
217
|
config[:finder] = finder || :find
|
210
218
|
end
|
211
219
|
|
212
|
-
if
|
220
|
+
if block
|
213
221
|
class_eval(&block)
|
214
222
|
else
|
215
223
|
create_resources_url_helpers!
|
216
224
|
end
|
217
|
-
helper_method :parent, :parent?
|
218
225
|
end
|
219
226
|
alias :nested_belongs_to :belongs_to
|
220
227
|
|
@@ -222,7 +229,7 @@ module InheritedResources
|
|
222
229
|
#
|
223
230
|
def polymorphic_belongs_to(*symbols, &block)
|
224
231
|
options = symbols.extract_options!
|
225
|
-
options
|
232
|
+
options[:polymorphic] = true
|
226
233
|
belongs_to(*symbols, options, &block)
|
227
234
|
end
|
228
235
|
|
@@ -230,7 +237,7 @@ module InheritedResources
|
|
230
237
|
#
|
231
238
|
def singleton_belongs_to(*symbols, &block)
|
232
239
|
options = symbols.extract_options!
|
233
|
-
options
|
240
|
+
options[:singleton] = true
|
234
241
|
belongs_to(*symbols, options, &block)
|
235
242
|
end
|
236
243
|
|
@@ -238,7 +245,7 @@ module InheritedResources
|
|
238
245
|
#
|
239
246
|
def optional_belongs_to(*symbols, &block)
|
240
247
|
options = symbols.extract_options!
|
241
|
-
options
|
248
|
+
options[:optional] = true
|
242
249
|
belongs_to(*symbols, options, &block)
|
243
250
|
end
|
244
251
|
|
@@ -292,7 +299,7 @@ module InheritedResources
|
|
292
299
|
unless self.resources_configuration[:self][:singleton]
|
293
300
|
self.resources_configuration[:self][:singleton] = true
|
294
301
|
include SingletonHelpers
|
295
|
-
actions :all, :
|
302
|
+
actions :all, except: :index
|
296
303
|
end
|
297
304
|
end
|
298
305
|
|
@@ -373,16 +380,16 @@ module InheritedResources
|
|
373
380
|
end
|
374
381
|
end
|
375
382
|
|
376
|
-
config[:route_prefix] = namespaces.join('_') unless namespaces.empty?
|
383
|
+
config[:route_prefix] = namespaces.join('_').to_sym unless namespaces.empty?
|
377
384
|
|
378
385
|
# Deal with default request parameters in namespaced controllers, e.g.
|
379
386
|
# Forum::Thread#create will properly pick up the request parameter
|
380
387
|
# which will be forum_thread, and not thread
|
381
388
|
# Additionally make this work orthogonally with instance_name
|
382
|
-
config[:request_name] = self.resource_class.to_s.underscore.
|
389
|
+
config[:request_name] = self.resource_class.to_s.underscore.tr('/', '_')
|
383
390
|
|
384
391
|
# Initialize polymorphic, singleton, scopes and belongs_to parameters
|
385
|
-
polymorphic = self.resources_configuration[:polymorphic] || { :
|
392
|
+
polymorphic = self.resources_configuration[:polymorphic] || { symbols: [], optional: false }
|
386
393
|
polymorphic[:symbols] = polymorphic[:symbols].dup
|
387
394
|
self.resources_configuration[:polymorphic] = polymorphic
|
388
395
|
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module InheritedResources
|
4
|
+
class Railtie < ::Rails::Engine
|
5
|
+
config.inherited_resources = InheritedResources
|
6
|
+
|
7
|
+
if config.respond_to?(:app_generators)
|
8
|
+
config.app_generators.scaffold_controller = :inherited_resources_controller
|
9
|
+
else
|
10
|
+
config.generators.scaffold_controller = :inherited_resources_controller
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module InheritedResources
|
2
4
|
|
3
5
|
# = polymorphic associations
|
@@ -102,11 +104,13 @@ module InheritedResources
|
|
102
104
|
# as parent types.
|
103
105
|
#
|
104
106
|
def parent_type
|
105
|
-
unless
|
107
|
+
unless instance_variable_defined?(:@parent_type)
|
106
108
|
symbols_for_association_chain
|
107
109
|
end
|
108
110
|
|
109
|
-
|
111
|
+
if instance_variable_defined?(:@parent_type)
|
112
|
+
@parent_type
|
113
|
+
end
|
110
114
|
end
|
111
115
|
|
112
116
|
def parent_class
|
@@ -118,8 +122,8 @@ module InheritedResources
|
|
118
122
|
#
|
119
123
|
def parent
|
120
124
|
if parent_type
|
121
|
-
p = instance_variable_get("@#{parent_type}")
|
122
|
-
p || instance_variable_set("@#{parent_type}", association_chain[-1])
|
125
|
+
p = instance_variable_defined?(:"@#{parent_type}") && instance_variable_get(:"@#{parent_type}")
|
126
|
+
p || instance_variable_set(:"@#{parent_type}", association_chain[-1])
|
123
127
|
end
|
124
128
|
end
|
125
129
|
|
@@ -149,9 +153,9 @@ module InheritedResources
|
|
149
153
|
if symbol == :polymorphic
|
150
154
|
params_keys = params.keys
|
151
155
|
|
152
|
-
keys = polymorphic_config[:symbols].
|
153
|
-
params_keys.include?(resources_configuration[poly][:param].to_s)
|
154
|
-
end
|
156
|
+
keys = polymorphic_config[:symbols].select do |poly|
|
157
|
+
params_keys.include?(resources_configuration[poly][:param].to_s)
|
158
|
+
end
|
155
159
|
|
156
160
|
if keys.empty?
|
157
161
|
raise ScriptError, "Could not find param for polymorphic association. The request " <<
|
@@ -161,7 +165,7 @@ module InheritedResources
|
|
161
165
|
nil
|
162
166
|
else
|
163
167
|
@parent_type = keys[-1].to_sym
|
164
|
-
|
168
|
+
@parent_types = keys.map(&:to_sym)
|
165
169
|
end
|
166
170
|
else
|
167
171
|
symbol
|
@@ -171,4 +175,3 @@ module InheritedResources
|
|
171
175
|
|
172
176
|
end
|
173
177
|
end
|
174
|
-
|
@@ -1,6 +1,10 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module InheritedResources
|
2
4
|
class Responder < ActionController::Responder
|
3
5
|
include Responders::FlashResponder
|
4
|
-
|
6
|
+
|
7
|
+
self.error_status = :unprocessable_entity
|
8
|
+
self.redirect_status = :see_other
|
5
9
|
end
|
6
|
-
end
|
10
|
+
end
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module InheritedResources
|
2
4
|
# Shallow provides a functionality that goes on pair with Rails' shallow.
|
3
5
|
# It is very similar to "optional" but it actually finds all the parents
|
@@ -33,7 +35,7 @@ module InheritedResources
|
|
33
35
|
end
|
34
36
|
|
35
37
|
def load_parents(instance, parent_symbols)
|
36
|
-
parent_symbols.
|
38
|
+
parent_symbols.reverse_each do |parent|
|
37
39
|
instance = instance.send(parent)
|
38
40
|
config = resources_configuration[parent]
|
39
41
|
params[config[:param]] = instance.to_param
|
@@ -1,3 +1,5 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
1
3
|
module InheritedResources
|
2
4
|
# = URLHelpers
|
3
5
|
#
|
@@ -34,203 +36,210 @@ module InheritedResources
|
|
34
36
|
module UrlHelpers
|
35
37
|
protected
|
36
38
|
|
37
|
-
|
38
|
-
#
|
39
|
-
# We are doing this because is cheaper than guessing them when our action
|
40
|
-
# is being processed (and even more cheaper when we are using nested
|
41
|
-
# resources).
|
42
|
-
#
|
43
|
-
# When we are using polymorphic associations, those helpers rely on
|
44
|
-
# polymorphic_url Rails helper.
|
45
|
-
#
|
46
|
-
def create_resources_url_helpers!
|
47
|
-
resource_segments, resource_ivars = [], []
|
48
|
-
resource_config = self.resources_configuration[:self]
|
49
|
-
|
50
|
-
singleton = resource_config[:singleton]
|
51
|
-
uncountable = !singleton && resource_config[:route_collection_name] == resource_config[:route_instance_name]
|
52
|
-
polymorphic = self.parents_symbols.include?(:polymorphic)
|
53
|
-
|
54
|
-
# Add route_prefix if any.
|
55
|
-
unless resource_config[:route_prefix].blank?
|
56
|
-
if polymorphic
|
57
|
-
resource_ivars << resource_config[:route_prefix].to_s.inspect
|
58
|
-
else
|
59
|
-
resource_segments << resource_config[:route_prefix]
|
60
|
-
end
|
61
|
-
end
|
62
|
-
|
63
|
-
# Deal with belongs_to associations and polymorphic associations.
|
64
|
-
# Remember that we don't have to build the segments in polymorphic cases,
|
65
|
-
# because the url will be polymorphic_url.
|
39
|
+
# This method hard code url helpers in the class.
|
66
40
|
#
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
41
|
+
# We are doing this because is cheaper than guessing them when our action
|
42
|
+
# is being processed (and even more cheaper when we are using nested
|
43
|
+
# resources).
|
44
|
+
#
|
45
|
+
# When we are using polymorphic associations, those helpers rely on
|
46
|
+
# polymorphic_url Rails helper.
|
47
|
+
#
|
48
|
+
def create_resources_url_helpers!
|
49
|
+
resource_segments, resource_ivars = [], []
|
50
|
+
resource_config = self.resources_configuration[:self]
|
51
|
+
|
52
|
+
singleton = resource_config[:singleton]
|
53
|
+
uncountable = !singleton && resource_config[:route_collection_name] == resource_config[:route_instance_name]
|
54
|
+
polymorphic = self.parents_symbols.include?(:polymorphic)
|
55
|
+
|
56
|
+
# Add route_prefix if any.
|
57
|
+
unless resource_config[:route_prefix].blank?
|
58
|
+
if polymorphic
|
59
|
+
resource_ivars << resource_config[:route_prefix]
|
74
60
|
else
|
75
|
-
resource_segments <<
|
76
|
-
end
|
77
|
-
if !config[:singleton]
|
78
|
-
resource_ivars << :"@#{config[:instance_name]}"
|
61
|
+
resource_segments << resource_config[:route_prefix]
|
79
62
|
end
|
80
63
|
end
|
81
|
-
end
|
82
|
-
|
83
|
-
collection_ivars = resource_ivars.dup
|
84
|
-
collection_segments = resource_segments.dup
|
85
64
|
|
65
|
+
# Deal with belongs_to associations and polymorphic associations.
|
66
|
+
# Remember that we don't have to build the segments in polymorphic cases,
|
67
|
+
# because the url will be polymorphic_url.
|
68
|
+
#
|
69
|
+
self.parents_symbols.each do |symbol|
|
70
|
+
if symbol == :polymorphic
|
71
|
+
resource_ivars << :parent
|
72
|
+
else
|
73
|
+
config = self.resources_configuration[symbol]
|
74
|
+
if config[:singleton] && polymorphic
|
75
|
+
resource_ivars << config[:instance_name]
|
76
|
+
else
|
77
|
+
resource_segments << config[:route_name]
|
78
|
+
end
|
79
|
+
if !config[:singleton]
|
80
|
+
resource_ivars << :"@#{config[:instance_name]}"
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
86
84
|
|
87
|
-
|
88
|
-
|
89
|
-
generate_url_and_path_helpers nil, :parent, resource_segments, resource_ivars
|
90
|
-
generate_url_and_path_helpers :edit, :parent, resource_segments, resource_ivars
|
91
|
-
end
|
92
|
-
|
93
|
-
# This is the default route configuration, later we have to deal with
|
94
|
-
# exception from polymorphic and singleton cases.
|
95
|
-
#
|
96
|
-
collection_segments << resource_config[:route_collection_name]
|
97
|
-
resource_segments << resource_config[:route_instance_name]
|
98
|
-
resource_ivars << :"@#{resource_config[:instance_name]}"
|
85
|
+
collection_ivars = resource_ivars.dup
|
86
|
+
collection_segments = resource_segments.dup
|
99
87
|
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
# Instead of:
|
106
|
-
#
|
107
|
-
# project_manager_url(@project, @manager)
|
108
|
-
#
|
109
|
-
# Another exception in singleton cases is that collection url does not
|
110
|
-
# exist. In such cases, we create the parent collection url. So in the
|
111
|
-
# manager case above, the collection url will be:
|
112
|
-
#
|
113
|
-
# project_url(@project)
|
114
|
-
#
|
115
|
-
# If the singleton does not have a parent, it will default to root_url.
|
116
|
-
#
|
117
|
-
# Finally, polymorphic cases we have to give hints to the polymorphic url
|
118
|
-
# builder. This works by attaching new ivars as symbols or records.
|
119
|
-
#
|
120
|
-
if singleton
|
121
|
-
collection_segments.pop
|
122
|
-
resource_ivars.pop
|
88
|
+
# Generate parent url before we add resource instances.
|
89
|
+
unless parents_symbols.empty?
|
90
|
+
generate_url_and_path_helpers nil, :parent, resource_segments, resource_ivars
|
91
|
+
generate_url_and_path_helpers :edit, :parent, resource_segments, resource_ivars
|
92
|
+
end
|
123
93
|
|
124
|
-
|
125
|
-
|
94
|
+
# In singleton cases, we do not send the current element instance variable
|
95
|
+
# because the id is not in the URL. For example, we should call:
|
96
|
+
#
|
97
|
+
# project_manager_url(@project)
|
98
|
+
#
|
99
|
+
# Instead of:
|
100
|
+
#
|
101
|
+
# project_manager_url(@project, @manager)
|
102
|
+
#
|
103
|
+
# Another exception in singleton cases is that collection url does not
|
104
|
+
# exist. In such cases, we create the parent collection url. So in the
|
105
|
+
# manager case above, the collection url will be:
|
106
|
+
#
|
107
|
+
# project_url(@project)
|
108
|
+
#
|
109
|
+
# If the singleton does not have a parent, it will default to root_url.
|
110
|
+
#
|
111
|
+
collection_segments << resource_config[:route_collection_name] unless singleton
|
112
|
+
resource_segments << resource_config[:route_instance_name]
|
113
|
+
resource_ivars << :"@#{resource_config[:instance_name]}" unless singleton
|
114
|
+
|
115
|
+
# Finally, polymorphic cases we have to give hints to the polymorphic url
|
116
|
+
# builder. This works by attaching new ivars as symbols or records.
|
117
|
+
#
|
118
|
+
if polymorphic && singleton
|
119
|
+
resource_ivars << resource_config[:instance_name]
|
126
120
|
new_ivars = resource_ivars
|
127
121
|
end
|
128
|
-
elsif polymorphic
|
129
|
-
collection_ivars << '(@_resource_class_new ||= resource_class.new)'
|
130
|
-
end
|
131
122
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
123
|
+
# If route is uncountable then add "_index" suffix to collection index route name
|
124
|
+
if uncountable
|
125
|
+
collection_segments << :"#{collection_segments.pop}_index"
|
126
|
+
end
|
136
127
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
128
|
+
generate_url_and_path_helpers nil, :collection, collection_segments, collection_ivars
|
129
|
+
generate_url_and_path_helpers :new, :resource, resource_segments, new_ivars || collection_ivars
|
130
|
+
generate_url_and_path_helpers nil, :resource, resource_segments, resource_ivars
|
131
|
+
generate_url_and_path_helpers :edit, :resource, resource_segments, resource_ivars
|
141
132
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
133
|
+
if resource_config[:custom_actions]
|
134
|
+
[*resource_config[:custom_actions][:resource]].each do | method |
|
135
|
+
generate_url_and_path_helpers method, :resource, resource_segments, resource_ivars
|
136
|
+
end
|
137
|
+
[*resource_config[:custom_actions][:collection]].each do | method |
|
138
|
+
generate_url_and_path_helpers method, :resources, collection_segments, collection_ivars
|
139
|
+
end
|
148
140
|
end
|
149
141
|
end
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
when :collection, :resources
|
156
|
-
segments = segments[-2..-1]
|
157
|
-
ivars = [ivars.last]
|
158
|
-
when :resource
|
159
|
-
if prefix == :new
|
142
|
+
|
143
|
+
def handle_shallow_resource(prefix, name, segments, ivars) #:nodoc:
|
144
|
+
return segments, ivars unless self.resources_configuration[:self][:shallow]
|
145
|
+
case name
|
146
|
+
when :collection, :resources
|
160
147
|
segments = segments[-2..-1]
|
161
148
|
ivars = [ivars.last]
|
162
|
-
|
149
|
+
when :resource
|
150
|
+
if prefix == :new
|
151
|
+
segments = segments[-2..-1]
|
152
|
+
ivars = [ivars.last]
|
153
|
+
else
|
154
|
+
segments = [segments.last]
|
155
|
+
ivars = [ivars.last]
|
156
|
+
end
|
157
|
+
when :parent
|
163
158
|
segments = [segments.last]
|
164
159
|
ivars = [ivars.last]
|
165
160
|
end
|
166
|
-
when :parent
|
167
|
-
segments = [segments.last]
|
168
|
-
ivars = [ivars.last]
|
169
|
-
end
|
170
161
|
|
171
|
-
|
162
|
+
segments ||= []
|
163
|
+
|
164
|
+
unless self.resources_configuration[:self][:route_prefix].blank?
|
165
|
+
segments.unshift self.resources_configuration[:self][:route_prefix]
|
166
|
+
end
|
172
167
|
|
173
|
-
|
174
|
-
segments.unshift self.resources_configuration[:self][:route_prefix]
|
168
|
+
return segments, ivars
|
175
169
|
end
|
176
170
|
|
177
|
-
|
178
|
-
|
171
|
+
def generate_url_and_path_helpers(prefix, name, resource_segments, resource_ivars) #:nodoc:
|
172
|
+
resource_segments, resource_ivars = handle_shallow_resource(prefix, name, resource_segments, resource_ivars)
|
179
173
|
|
180
|
-
|
181
|
-
|
174
|
+
ivars = resource_ivars.dup
|
175
|
+
singleton = self.resources_configuration[:self][:singleton]
|
176
|
+
polymorphic = self.parents_symbols.include?(:polymorphic)
|
182
177
|
|
183
|
-
|
184
|
-
|
185
|
-
|
178
|
+
# In collection in polymorphic cases, allow an argument to be given as a
|
179
|
+
# replacemente for the parent.
|
180
|
+
#
|
181
|
+
parent_index = ivars.index(:parent) if polymorphic
|
186
182
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
183
|
+
segments = if polymorphic
|
184
|
+
:polymorphic
|
185
|
+
elsif resource_segments.empty?
|
186
|
+
'root'
|
187
|
+
else
|
188
|
+
resource_segments.join('_')
|
189
|
+
end
|
193
190
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
if name == :collection && polymorphic
|
198
|
-
index = ivars.index(:parent)
|
199
|
-
ivars.insert index, "(given_args.first || parent)"
|
200
|
-
ivars.delete(:parent)
|
191
|
+
define_params_helper(prefix, name, singleton, polymorphic, parent_index, ivars)
|
192
|
+
define_helper_method(prefix, name, :path, segments)
|
193
|
+
define_helper_method(prefix, name, :url, segments)
|
201
194
|
end
|
202
195
|
|
203
|
-
|
204
|
-
|
205
|
-
# optional.
|
206
|
-
#
|
207
|
-
if polymorphic
|
208
|
-
segments = :polymorphic
|
209
|
-
ivars = "[#{ivars.join(', ')}]"
|
210
|
-
ivars << '.compact' if self.resources_configuration[:polymorphic][:optional]
|
211
|
-
else
|
212
|
-
segments = resource_segments.empty? ? 'root' : resource_segments.join('_')
|
213
|
-
ivars = ivars.join(', ')
|
214
|
-
end
|
196
|
+
def define_params_helper(prefix, name, singleton, polymorphic, parent_index, ivars)
|
197
|
+
params_method_name = ['', prefix, name, :params].compact.join('_')
|
215
198
|
|
216
|
-
|
217
|
-
|
199
|
+
undef_method params_method_name if method_defined? params_method_name
|
200
|
+
|
201
|
+
define_method params_method_name do |*given_args|
|
202
|
+
given_args = given_args.collect { |arg| arg.respond_to?(:permitted?) ? arg.to_h : arg }
|
203
|
+
given_options = given_args.extract_options!
|
204
|
+
|
205
|
+
args = ivars.map do |ivar|
|
206
|
+
ivar.is_a?(Symbol) && ivar.to_s.start_with?('@') ? instance_variable_get(ivar) : ivar
|
207
|
+
end
|
208
|
+
args[parent_index] = parent if parent_index
|
218
209
|
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
def #{prefix}#{name}_path(*given_args)
|
223
|
-
given_options = given_args.extract_options!
|
224
|
-
#{prefix}#{segments}_path(#{ivars})
|
210
|
+
if !(singleton && name != :parent) && args.present? && name != :collection && prefix != :new
|
211
|
+
resource = args.pop
|
212
|
+
args.push(given_args.first || resource)
|
225
213
|
end
|
226
214
|
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
215
|
+
if polymorphic
|
216
|
+
if name == :collection
|
217
|
+
args[parent_index] = given_args.present? ? given_args.first : parent
|
218
|
+
end
|
219
|
+
if (name == :collection || name == :resource && prefix == :new) && !singleton
|
220
|
+
args << (@_resource_class_new ||= resource_class.new)
|
221
|
+
end
|
222
|
+
args.compact! if self.resources_configuration[:polymorphic][:optional]
|
223
|
+
args = [args]
|
231
224
|
end
|
232
|
-
|
233
|
-
|
225
|
+
args << given_options
|
226
|
+
end
|
227
|
+
protected params_method_name
|
228
|
+
end
|
229
|
+
|
230
|
+
def define_helper_method(prefix, name, suffix, segments)
|
231
|
+
method_name = [prefix, name, suffix].compact.join('_')
|
232
|
+
params_method_name = ['', prefix, name, :params].compact.join('_')
|
233
|
+
segments_method = [prefix, segments, suffix].compact.join('_')
|
234
|
+
|
235
|
+
undef_method method_name if method_defined? method_name
|
236
|
+
|
237
|
+
define_method method_name do |*given_args|
|
238
|
+
given_args = send params_method_name, *given_args
|
239
|
+
send segments_method, *given_args
|
240
|
+
end
|
241
|
+
protected method_name
|
242
|
+
end
|
234
243
|
|
235
244
|
end
|
236
245
|
end
|
data/lib/inherited_resources.rb
CHANGED
@@ -1,7 +1,12 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
# This is here because responders don't require it.
|
1
4
|
require 'rails/engine'
|
2
5
|
require 'responders'
|
3
|
-
|
4
|
-
|
6
|
+
|
7
|
+
require_relative 'inherited_resources/engine'
|
8
|
+
require_relative 'inherited_resources/blank_slate'
|
9
|
+
require_relative 'inherited_resources/responder'
|
5
10
|
|
6
11
|
module InheritedResources
|
7
12
|
ACTIONS = [ :index, :show, :new, :edit, :create, :update, :destroy ] unless self.const_defined?(:ACTIONS)
|
@@ -22,20 +27,15 @@ module InheritedResources
|
|
22
27
|
Responders::FlashResponder.flash_keys = array
|
23
28
|
end
|
24
29
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
config.app_generators.scaffold_controller = :inherited_resources_controller
|
29
|
-
else
|
30
|
-
config.generators.scaffold_controller = :inherited_resources_controller
|
31
|
-
end
|
32
|
-
end
|
30
|
+
# Inherit from a different controller. This only has an effect if changed
|
31
|
+
# before InheritedResources::Base is loaded, e.g. in a rails initializer.
|
32
|
+
mattr_accessor(:parent_controller) { '::ApplicationController' }
|
33
33
|
end
|
34
34
|
|
35
|
-
|
35
|
+
ActiveSupport.on_load(:action_controller_base) do
|
36
36
|
# If you cannot inherit from InheritedResources::Base you can call
|
37
37
|
# inherit_resources in your controller to have all the required modules and
|
38
|
-
#
|
38
|
+
# functionality included.
|
39
39
|
def self.inherit_resources
|
40
40
|
InheritedResources::Base.inherit_resources(self)
|
41
41
|
initialize_resources_class_accessors!
|
metadata
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inherited_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- José Valim
|
8
8
|
- Rafael Mendonça França
|
9
|
-
autorequire:
|
9
|
+
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2024-12-07 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: responders
|
@@ -17,71 +17,60 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
20
|
+
version: '2'
|
21
21
|
type: :runtime
|
22
22
|
prerelease: false
|
23
23
|
version_requirements: !ruby/object:Gem::Requirement
|
24
24
|
requirements:
|
25
25
|
- - ">="
|
26
26
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
27
|
+
version: '2'
|
28
28
|
- !ruby/object:Gem::Dependency
|
29
29
|
name: actionpack
|
30
30
|
requirement: !ruby/object:Gem::Requirement
|
31
31
|
requirements:
|
32
32
|
- - ">="
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
35
|
-
- - "<"
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: '5.1'
|
34
|
+
version: '7.0'
|
38
35
|
type: :runtime
|
39
36
|
prerelease: false
|
40
37
|
version_requirements: !ruby/object:Gem::Requirement
|
41
38
|
requirements:
|
42
39
|
- - ">="
|
43
40
|
- !ruby/object:Gem::Version
|
44
|
-
version: '
|
45
|
-
- - "<"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: '5.1'
|
41
|
+
version: '7.0'
|
48
42
|
- !ruby/object:Gem::Dependency
|
49
43
|
name: railties
|
50
44
|
requirement: !ruby/object:Gem::Requirement
|
51
45
|
requirements:
|
52
46
|
- - ">="
|
53
47
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
55
|
-
- - "<"
|
56
|
-
- !ruby/object:Gem::Version
|
57
|
-
version: '5.1'
|
48
|
+
version: '7.0'
|
58
49
|
type: :runtime
|
59
50
|
prerelease: false
|
60
51
|
version_requirements: !ruby/object:Gem::Requirement
|
61
52
|
requirements:
|
62
53
|
- - ">="
|
63
54
|
- !ruby/object:Gem::Version
|
64
|
-
version: '
|
65
|
-
- - "<"
|
66
|
-
- !ruby/object:Gem::Version
|
67
|
-
version: '5.1'
|
55
|
+
version: '7.0'
|
68
56
|
- !ruby/object:Gem::Dependency
|
69
57
|
name: has_scope
|
70
58
|
requirement: !ruby/object:Gem::Requirement
|
71
59
|
requirements:
|
72
|
-
- - "
|
60
|
+
- - ">="
|
73
61
|
- !ruby/object:Gem::Version
|
74
62
|
version: '0.6'
|
75
63
|
type: :runtime
|
76
64
|
prerelease: false
|
77
65
|
version_requirements: !ruby/object:Gem::Requirement
|
78
66
|
requirements:
|
79
|
-
- - "
|
67
|
+
- - ">="
|
80
68
|
- !ruby/object:Gem::Version
|
81
69
|
version: '0.6'
|
82
|
-
description:
|
83
|
-
inherit all restful actions so you just have to focus on what is important.
|
84
|
-
|
70
|
+
description: |
|
71
|
+
Inherited Resources speeds up development by making your controllers inherit all restful actions so you just have to focus on what is important.
|
72
|
+
It makes your controllers more powerful and cleaner at the same time.
|
73
|
+
email:
|
85
74
|
executables: []
|
86
75
|
extensions: []
|
87
76
|
extra_rdoc_files: []
|
@@ -91,7 +80,7 @@ files:
|
|
91
80
|
- app/controllers/inherited_resources/base.rb
|
92
81
|
- lib/generators/rails/USAGE
|
93
82
|
- lib/generators/rails/inherited_resources_controller_generator.rb
|
94
|
-
- lib/generators/rails/templates/controller.rb
|
83
|
+
- lib/generators/rails/templates/controller.rb.tt
|
95
84
|
- lib/inherited_resources.rb
|
96
85
|
- lib/inherited_resources/actions.rb
|
97
86
|
- lib/inherited_resources/base_helpers.rb
|
@@ -99,17 +88,19 @@ files:
|
|
99
88
|
- lib/inherited_resources/blank_slate.rb
|
100
89
|
- lib/inherited_resources/class_methods.rb
|
101
90
|
- lib/inherited_resources/dsl.rb
|
91
|
+
- lib/inherited_resources/engine.rb
|
102
92
|
- lib/inherited_resources/polymorphic_helpers.rb
|
103
93
|
- lib/inherited_resources/responder.rb
|
104
94
|
- lib/inherited_resources/shallow_helpers.rb
|
105
95
|
- lib/inherited_resources/singleton_helpers.rb
|
106
96
|
- lib/inherited_resources/url_helpers.rb
|
107
97
|
- lib/inherited_resources/version.rb
|
108
|
-
homepage:
|
98
|
+
homepage: https://github.com/activeadmin/inherited_resources
|
109
99
|
licenses:
|
110
100
|
- MIT
|
111
|
-
metadata:
|
112
|
-
|
101
|
+
metadata:
|
102
|
+
rubygems_mfa_required: 'true'
|
103
|
+
post_install_message:
|
113
104
|
rdoc_options: []
|
114
105
|
require_paths:
|
115
106
|
- lib
|
@@ -117,16 +108,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
117
108
|
requirements:
|
118
109
|
- - ">="
|
119
110
|
- !ruby/object:Gem::Version
|
120
|
-
version: '
|
111
|
+
version: '3.1'
|
121
112
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
122
113
|
requirements:
|
123
114
|
- - ">="
|
124
115
|
- !ruby/object:Gem::Version
|
125
116
|
version: '0'
|
126
117
|
requirements: []
|
127
|
-
|
128
|
-
|
129
|
-
signing_key:
|
118
|
+
rubygems_version: 3.5.22
|
119
|
+
signing_key:
|
130
120
|
specification_version: 4
|
131
121
|
summary: Inherited Resources speeds up development by making your controllers inherit
|
132
122
|
all restful actions so you just have to focus on what is important.
|