inherited_resources 1.8.0 → 1.12.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/README.md +24 -2
- data/app/controllers/inherited_resources/base.rb +3 -3
- data/lib/generators/rails/inherited_resources_controller_generator.rb +1 -1
- data/lib/generators/rails/templates/{controller.rb → controller.rb.tt} +1 -3
- data/lib/inherited_resources/actions.rb +0 -1
- data/lib/inherited_resources/base_helpers.rb +10 -13
- data/lib/inherited_resources/belongs_to_helpers.rb +2 -2
- data/lib/inherited_resources/class_methods.rb +9 -7
- data/lib/inherited_resources/polymorphic_helpers.rb +6 -5
- data/lib/inherited_resources/url_helpers.rb +168 -165
- data/lib/inherited_resources/version.rb +1 -1
- metadata +29 -23
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: f4cb8a8e3e1fc321346443a8264926120e60b5a4e316987143a58a6278114c4c
|
4
|
+
data.tar.gz: 942712a75ce52463be67c273ebefa83dced93511bde604efec8cf2223cbdc6c4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: fcd578a613128060649285c664854bc289e00d6ae0feed1420aa9f0c5dfa550660de341fe5791372580515dae1d5a5567c5aa068139182db5712b56aae6325d0
|
7
|
+
data.tar.gz: 2d365cf4b2c82c5ed363825136d6efa926c164bb2a3ca9861242258338c8c0de89e69355bde57b5ec8a08ed4e321b2a20407c67f438fce02d391bb33c84ced16
|
data/README.md
CHANGED
@@ -9,8 +9,9 @@ If you are not already using Inherited Resources we suggest instead using Rails'
|
|
9
9
|
|
10
10
|
## Inherited Resources
|
11
11
|
|
12
|
-
[![Version]
|
13
|
-
[![
|
12
|
+
[![Version ][rubygems_badge]][rubygems]
|
13
|
+
[![CircleCI ][circleci_badge]][circleci]
|
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
|
@@ -715,6 +716,13 @@ end
|
|
715
716
|
|
716
717
|
In such case you should remove #permitted_params method because it has greater priority.
|
717
718
|
|
719
|
+
## Funding
|
720
|
+
|
721
|
+
If you want to support us financially, you can [help fund the project
|
722
|
+
through a Tidelift subscription][tidelift]. By buying a Tidelift subscription
|
723
|
+
you make sure your whole dependency stack is properly maintained, while also
|
724
|
+
getting a comprehensive view of outdated dependencies, new releases, security
|
725
|
+
alerts, and licensing compatibility issues.
|
718
726
|
|
719
727
|
## Bugs and Feedback
|
720
728
|
|
@@ -723,3 +731,17 @@ If you discover any bugs, please describe it in the issues tracker, including Ra
|
|
723
731
|
Questions are better handled on StackOverflow.
|
724
732
|
|
725
733
|
MIT License. Copyright (c) 2009-2017 José Valim.
|
734
|
+
|
735
|
+
## Security contact information
|
736
|
+
|
737
|
+
Please use the Tidelift security contact to [report a security vulnerability][Tidelift security contact].
|
738
|
+
Tidelift will coordinate the fix and disclosure.
|
739
|
+
|
740
|
+
[rubygems_badge]: http://img.shields.io/gem/v/inherited_resources.svg
|
741
|
+
[rubygems]: https://rubygems.org/gems/inherited_resources
|
742
|
+
[circleci_badge]: https://circleci.com/gh/activeadmin/inherited_resources.svg?style=svg
|
743
|
+
[circleci]: https://circleci.com/gh/activeadmin/inherited_resources
|
744
|
+
[tidelift_badge]: https://tidelift.com/badges/github/activeadmin/inherited_resources
|
745
|
+
[tidelift]: https://tidelift.com/subscription/pkg/rubygems-inherited-resources?utm_source=rubygems-inherited-resources&utm_medium=referral&utm_campaign=readme
|
746
|
+
|
747
|
+
[Tidelift security contact]: https://tidelift.com/security
|
@@ -30,8 +30,8 @@ module InheritedResources
|
|
30
30
|
:parent_url, :parent_path,
|
31
31
|
:smart_resource_url, :smart_collection_url
|
32
32
|
|
33
|
-
self.class_attribute :resource_class, :
|
34
|
-
self.class_attribute :parents_symbols, :resources_configuration, :
|
33
|
+
self.class_attribute :resource_class, instance_writer: false unless self.respond_to? :resource_class
|
34
|
+
self.class_attribute :parents_symbols, :resources_configuration, instance_writer: false
|
35
35
|
|
36
36
|
protected :resource_class, :parents_symbols, :resources_configuration,
|
37
37
|
:resource_class?, :parents_symbols?, :resources_configuration?
|
@@ -40,4 +40,4 @@ module InheritedResources
|
|
40
40
|
|
41
41
|
inherit_resources(self)
|
42
42
|
end
|
43
|
-
end
|
43
|
+
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
|
@@ -22,14 +22,7 @@ module InheritedResources
|
|
22
22
|
def collection
|
23
23
|
get_collection_ivar || begin
|
24
24
|
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
|
25
|
+
set_collection_ivar(c.respond_to?(:scoped) ? c.scoped : c.all)
|
33
26
|
end
|
34
27
|
end
|
35
28
|
|
@@ -75,14 +68,14 @@ module InheritedResources
|
|
75
68
|
|
76
69
|
# Responsible for updating the resource in :update method. This allow you
|
77
70
|
# to handle how the resource is going to be updated, let's say in a different
|
78
|
-
# way than the usual :
|
71
|
+
# way than the usual :update:
|
79
72
|
#
|
80
73
|
# def update_resource(object, attributes)
|
81
74
|
# object.reset_password!(attributes)
|
82
75
|
# end
|
83
76
|
#
|
84
77
|
def update_resource(object, attributes)
|
85
|
-
object.
|
78
|
+
object.update(*attributes)
|
86
79
|
end
|
87
80
|
|
88
81
|
# Handle the :destroy method for the resource. Overwrite it to call your
|
@@ -139,12 +132,17 @@ module InheritedResources
|
|
139
132
|
end.compact.freeze
|
140
133
|
end
|
141
134
|
|
135
|
+
# rubocop:disable Layout/CommentIndentation
|
136
|
+
# See https://github.com/rubocop-hq/rubocop/issues/6450
|
137
|
+
#
|
142
138
|
# Overwrite this method to provide other interpolation options when
|
143
139
|
# the flash message is going to be set.
|
144
140
|
#
|
145
141
|
# def flash_interpolation_options
|
146
142
|
# { }
|
147
143
|
# end
|
144
|
+
#
|
145
|
+
# rubocop:enable Layout/CommentIndentation
|
148
146
|
|
149
147
|
private
|
150
148
|
|
@@ -372,7 +370,7 @@ module InheritedResources
|
|
372
370
|
|
373
371
|
# getting role for mass-asignment
|
374
372
|
def as_role
|
375
|
-
{ :
|
373
|
+
{ as: self.resources_configuration[:self][:role] }
|
376
374
|
end
|
377
375
|
|
378
376
|
def without_protection_given?
|
@@ -380,8 +378,7 @@ module InheritedResources
|
|
380
378
|
end
|
381
379
|
|
382
380
|
def without_protection
|
383
|
-
{ :
|
381
|
+
{ without_protection: self.resources_configuration[:self][:without_protection] }
|
384
382
|
end
|
385
383
|
end
|
386
384
|
end
|
387
|
-
|
@@ -152,7 +152,10 @@ module InheritedResources
|
|
152
152
|
polymorphic = options.delete(:polymorphic)
|
153
153
|
finder = options.delete(:finder)
|
154
154
|
|
155
|
-
|
155
|
+
if self.parents_symbols.empty?
|
156
|
+
include BelongsToHelpers
|
157
|
+
helper_method :parent, :parent?
|
158
|
+
end
|
156
159
|
|
157
160
|
acts_as_polymorphic! if polymorphic || optional
|
158
161
|
acts_as_shallow! if shallow
|
@@ -218,7 +221,6 @@ module InheritedResources
|
|
218
221
|
else
|
219
222
|
create_resources_url_helpers!
|
220
223
|
end
|
221
|
-
helper_method :parent, :parent?
|
222
224
|
end
|
223
225
|
alias :nested_belongs_to :belongs_to
|
224
226
|
|
@@ -226,7 +228,7 @@ module InheritedResources
|
|
226
228
|
#
|
227
229
|
def polymorphic_belongs_to(*symbols, &block)
|
228
230
|
options = symbols.extract_options!
|
229
|
-
options.merge!(:
|
231
|
+
options.merge!(polymorphic: true)
|
230
232
|
belongs_to(*symbols, options, &block)
|
231
233
|
end
|
232
234
|
|
@@ -234,7 +236,7 @@ module InheritedResources
|
|
234
236
|
#
|
235
237
|
def singleton_belongs_to(*symbols, &block)
|
236
238
|
options = symbols.extract_options!
|
237
|
-
options.merge!(:
|
239
|
+
options.merge!(singleton: true)
|
238
240
|
belongs_to(*symbols, options, &block)
|
239
241
|
end
|
240
242
|
|
@@ -242,7 +244,7 @@ module InheritedResources
|
|
242
244
|
#
|
243
245
|
def optional_belongs_to(*symbols, &block)
|
244
246
|
options = symbols.extract_options!
|
245
|
-
options.merge!(:
|
247
|
+
options.merge!(optional: true)
|
246
248
|
belongs_to(*symbols, options, &block)
|
247
249
|
end
|
248
250
|
|
@@ -296,7 +298,7 @@ module InheritedResources
|
|
296
298
|
unless self.resources_configuration[:self][:singleton]
|
297
299
|
self.resources_configuration[:self][:singleton] = true
|
298
300
|
include SingletonHelpers
|
299
|
-
actions :all, :
|
301
|
+
actions :all, except: :index
|
300
302
|
end
|
301
303
|
end
|
302
304
|
|
@@ -386,7 +388,7 @@ module InheritedResources
|
|
386
388
|
config[:request_name] = self.resource_class.to_s.underscore.gsub('/', '_')
|
387
389
|
|
388
390
|
# Initialize polymorphic, singleton, scopes and belongs_to parameters
|
389
|
-
polymorphic = self.resources_configuration[:polymorphic] || { :
|
391
|
+
polymorphic = self.resources_configuration[:polymorphic] || { symbols: [], optional: false }
|
390
392
|
polymorphic[:symbols] = polymorphic[:symbols].dup
|
391
393
|
self.resources_configuration[:polymorphic] = polymorphic
|
392
394
|
end
|
@@ -102,11 +102,13 @@ module InheritedResources
|
|
102
102
|
# as parent types.
|
103
103
|
#
|
104
104
|
def parent_type
|
105
|
-
unless
|
105
|
+
unless instance_variable_defined?(:@parent_type)
|
106
106
|
symbols_for_association_chain
|
107
107
|
end
|
108
108
|
|
109
|
-
|
109
|
+
if instance_variable_defined?(:@parent_type)
|
110
|
+
@parent_type
|
111
|
+
end
|
110
112
|
end
|
111
113
|
|
112
114
|
def parent_class
|
@@ -118,7 +120,7 @@ module InheritedResources
|
|
118
120
|
#
|
119
121
|
def parent
|
120
122
|
if parent_type
|
121
|
-
p = instance_variable_get("@#{parent_type}")
|
123
|
+
p = instance_variable_defined?("@#{parent_type}") && instance_variable_get("@#{parent_type}")
|
122
124
|
p || instance_variable_set("@#{parent_type}", association_chain[-1])
|
123
125
|
end
|
124
126
|
end
|
@@ -161,7 +163,7 @@ module InheritedResources
|
|
161
163
|
nil
|
162
164
|
else
|
163
165
|
@parent_type = keys[-1].to_sym
|
164
|
-
|
166
|
+
@parent_types = keys.map(&:to_sym)
|
165
167
|
end
|
166
168
|
else
|
167
169
|
symbol
|
@@ -171,4 +173,3 @@ module InheritedResources
|
|
171
173
|
|
172
174
|
end
|
173
175
|
end
|
174
|
-
|
@@ -34,207 +34,210 @@ module InheritedResources
|
|
34
34
|
module UrlHelpers
|
35
35
|
protected
|
36
36
|
|
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.
|
37
|
+
# This method hard code url helpers in the class.
|
66
38
|
#
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
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
|
74
58
|
else
|
75
|
-
resource_segments <<
|
76
|
-
end
|
77
|
-
if !config[:singleton]
|
78
|
-
resource_ivars << :"@#{config[:instance_name]}"
|
59
|
+
resource_segments << resource_config[:route_prefix]
|
79
60
|
end
|
80
61
|
end
|
81
|
-
end
|
82
|
-
|
83
|
-
collection_ivars = resource_ivars.dup
|
84
|
-
collection_segments = resource_segments.dup
|
85
|
-
|
86
62
|
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
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.
|
66
|
+
#
|
67
|
+
self.parents_symbols.each do |symbol|
|
68
|
+
if symbol == :polymorphic
|
69
|
+
resource_ivars << :parent
|
70
|
+
else
|
71
|
+
config = self.resources_configuration[symbol]
|
72
|
+
if config[:singleton] && polymorphic
|
73
|
+
resource_ivars << config[:instance_name]
|
74
|
+
else
|
75
|
+
resource_segments << config[:route_name]
|
76
|
+
end
|
77
|
+
if !config[:singleton]
|
78
|
+
resource_ivars << :"@#{config[:instance_name]}"
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
92
82
|
|
93
|
-
|
94
|
-
|
95
|
-
#
|
96
|
-
collection_segments << resource_config[:route_collection_name]
|
97
|
-
resource_segments << resource_config[:route_instance_name]
|
98
|
-
resource_ivars << :"@#{resource_config[:instance_name]}"
|
83
|
+
collection_ivars = resource_ivars.dup
|
84
|
+
collection_segments = resource_segments.dup
|
99
85
|
|
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
|
86
|
+
# Generate parent url before we add resource instances.
|
87
|
+
unless parents_symbols.empty?
|
88
|
+
generate_url_and_path_helpers nil, :parent, resource_segments, resource_ivars
|
89
|
+
generate_url_and_path_helpers :edit, :parent, resource_segments, resource_ivars
|
90
|
+
end
|
123
91
|
|
124
|
-
|
125
|
-
|
92
|
+
# In singleton cases, we do not send the current element instance variable
|
93
|
+
# because the id is not in the URL. For example, we should call:
|
94
|
+
#
|
95
|
+
# project_manager_url(@project)
|
96
|
+
#
|
97
|
+
# Instead of:
|
98
|
+
#
|
99
|
+
# project_manager_url(@project, @manager)
|
100
|
+
#
|
101
|
+
# Another exception in singleton cases is that collection url does not
|
102
|
+
# exist. In such cases, we create the parent collection url. So in the
|
103
|
+
# manager case above, the collection url will be:
|
104
|
+
#
|
105
|
+
# project_url(@project)
|
106
|
+
#
|
107
|
+
# If the singleton does not have a parent, it will default to root_url.
|
108
|
+
#
|
109
|
+
collection_segments << resource_config[:route_collection_name] unless singleton
|
110
|
+
resource_segments << resource_config[:route_instance_name]
|
111
|
+
resource_ivars << :"@#{resource_config[:instance_name]}" unless singleton
|
112
|
+
|
113
|
+
# Finally, polymorphic cases we have to give hints to the polymorphic url
|
114
|
+
# builder. This works by attaching new ivars as symbols or records.
|
115
|
+
#
|
116
|
+
if polymorphic && singleton
|
117
|
+
resource_ivars << resource_config[:instance_name]
|
126
118
|
new_ivars = resource_ivars
|
127
119
|
end
|
128
|
-
elsif polymorphic
|
129
|
-
collection_ivars << '(@_resource_class_new ||= resource_class.new)'
|
130
|
-
end
|
131
120
|
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
121
|
+
# If route is uncountable then add "_index" suffix to collection index route name
|
122
|
+
if uncountable
|
123
|
+
collection_segments << :"#{collection_segments.pop}_index"
|
124
|
+
end
|
136
125
|
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
126
|
+
generate_url_and_path_helpers nil, :collection, collection_segments, collection_ivars
|
127
|
+
generate_url_and_path_helpers :new, :resource, resource_segments, new_ivars || collection_ivars
|
128
|
+
generate_url_and_path_helpers nil, :resource, resource_segments, resource_ivars
|
129
|
+
generate_url_and_path_helpers :edit, :resource, resource_segments, resource_ivars
|
141
130
|
|
142
|
-
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
131
|
+
if resource_config[:custom_actions]
|
132
|
+
[*resource_config[:custom_actions][:resource]].each do | method |
|
133
|
+
generate_url_and_path_helpers method, :resource, resource_segments, resource_ivars
|
134
|
+
end
|
135
|
+
[*resource_config[:custom_actions][:collection]].each do | method |
|
136
|
+
generate_url_and_path_helpers method, :resources, collection_segments, collection_ivars
|
137
|
+
end
|
148
138
|
end
|
149
139
|
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
|
140
|
+
|
141
|
+
def handle_shallow_resource(prefix, name, segments, ivars) #:nodoc:
|
142
|
+
return segments, ivars unless self.resources_configuration[:self][:shallow]
|
143
|
+
case name
|
144
|
+
when :collection, :resources
|
160
145
|
segments = segments[-2..-1]
|
161
146
|
ivars = [ivars.last]
|
162
|
-
|
147
|
+
when :resource
|
148
|
+
if prefix == :new
|
149
|
+
segments = segments[-2..-1]
|
150
|
+
ivars = [ivars.last]
|
151
|
+
else
|
152
|
+
segments = [segments.last]
|
153
|
+
ivars = [ivars.last]
|
154
|
+
end
|
155
|
+
when :parent
|
163
156
|
segments = [segments.last]
|
164
157
|
ivars = [ivars.last]
|
165
158
|
end
|
166
|
-
when :parent
|
167
|
-
segments = [segments.last]
|
168
|
-
ivars = [ivars.last]
|
169
|
-
end
|
170
159
|
|
171
|
-
|
160
|
+
segments ||= []
|
161
|
+
|
162
|
+
unless self.resources_configuration[:self][:route_prefix].blank?
|
163
|
+
segments.unshift self.resources_configuration[:self][:route_prefix]
|
164
|
+
end
|
172
165
|
|
173
|
-
|
174
|
-
segments.unshift self.resources_configuration[:self][:route_prefix]
|
166
|
+
return segments, ivars
|
175
167
|
end
|
176
168
|
|
177
|
-
|
178
|
-
|
169
|
+
def generate_url_and_path_helpers(prefix, name, resource_segments, resource_ivars) #:nodoc:
|
170
|
+
resource_segments, resource_ivars = handle_shallow_resource(prefix, name, resource_segments, resource_ivars)
|
179
171
|
|
180
|
-
|
181
|
-
|
172
|
+
ivars = resource_ivars.dup
|
173
|
+
singleton = self.resources_configuration[:self][:singleton]
|
174
|
+
polymorphic = self.parents_symbols.include?(:polymorphic)
|
182
175
|
|
183
|
-
|
184
|
-
|
185
|
-
|
176
|
+
# In collection in polymorphic cases, allow an argument to be given as a
|
177
|
+
# replacemente for the parent.
|
178
|
+
#
|
179
|
+
parent_index = ivars.index(:parent) if polymorphic
|
186
180
|
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
|
192
|
-
|
181
|
+
segments = if polymorphic
|
182
|
+
:polymorphic
|
183
|
+
elsif resource_segments.empty?
|
184
|
+
'root'
|
185
|
+
else
|
186
|
+
resource_segments.join('_')
|
187
|
+
end
|
193
188
|
|
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)
|
189
|
+
define_params_helper(prefix, name, singleton, polymorphic, parent_index, ivars)
|
190
|
+
define_helper_method(prefix, name, :path, segments)
|
191
|
+
define_helper_method(prefix, name, :url, segments)
|
201
192
|
end
|
202
193
|
|
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
|
194
|
+
def define_params_helper(prefix, name, singleton, polymorphic, parent_index, ivars)
|
195
|
+
params_method_name = ['', prefix, name, :params].compact.join('_')
|
215
196
|
|
216
|
-
|
217
|
-
ivars << (ivars.empty? ? 'given_options' : ', given_options')
|
197
|
+
undef_method params_method_name if method_defined? params_method_name
|
218
198
|
|
219
|
-
|
199
|
+
define_method params_method_name do |*given_args|
|
200
|
+
given_args = given_args.collect { |arg| arg.respond_to?(:permitted?) ? arg.to_h : arg }
|
201
|
+
given_options = given_args.extract_options!
|
220
202
|
|
221
|
-
|
222
|
-
|
223
|
-
undef :#{prefix}#{name}_path if method_defined? :#{prefix}#{name}_path
|
224
|
-
def #{prefix}#{name}_path(*given_args)
|
225
|
-
#{given_args_transform}
|
226
|
-
given_options = given_args.extract_options!
|
227
|
-
#{prefix}#{segments}_path(#{ivars})
|
203
|
+
args = ivars.map do |ivar|
|
204
|
+
ivar.is_a?(Symbol) && ivar.to_s.start_with?('@') ? instance_variable_get(ivar) : ivar
|
228
205
|
end
|
206
|
+
args[parent_index] = parent if parent_index
|
229
207
|
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
given_options = given_args.extract_options!
|
234
|
-
#{prefix}#{segments}_url(#{ivars})
|
208
|
+
if !(singleton && name != :parent) && args.present? && name != :collection && prefix != :new
|
209
|
+
resource = args.pop
|
210
|
+
args.push(given_args.first || resource)
|
235
211
|
end
|
236
|
-
|
237
|
-
|
212
|
+
|
213
|
+
if polymorphic
|
214
|
+
if name == :collection
|
215
|
+
args[parent_index] = given_args.present? ? given_args.first : parent
|
216
|
+
end
|
217
|
+
if (name == :collection || name == :resource && prefix == :new) && !singleton
|
218
|
+
args << (@_resource_class_new ||= resource_class.new)
|
219
|
+
end
|
220
|
+
args.compact! if self.resources_configuration[:polymorphic][:optional]
|
221
|
+
args = [args]
|
222
|
+
end
|
223
|
+
args << given_options
|
224
|
+
end
|
225
|
+
protected params_method_name
|
226
|
+
end
|
227
|
+
|
228
|
+
def define_helper_method(prefix, name, suffix, segments)
|
229
|
+
method_name = [prefix, name, suffix].compact.join('_')
|
230
|
+
params_method_name = ['', prefix, name, :params].compact.join('_')
|
231
|
+
segments_method = [prefix, segments, suffix].compact.join('_')
|
232
|
+
|
233
|
+
undef_method method_name if method_defined? method_name
|
234
|
+
|
235
|
+
define_method method_name do |*given_args|
|
236
|
+
given_args = send params_method_name, *given_args
|
237
|
+
send segments_method, *given_args
|
238
|
+
end
|
239
|
+
protected method_name
|
240
|
+
end
|
238
241
|
|
239
242
|
end
|
240
243
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: inherited_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.12.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- José Valim
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-12-11 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: responders
|
@@ -17,54 +17,60 @@ dependencies:
|
|
17
17
|
requirements:
|
18
18
|
- - ">="
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '
|
20
|
+
version: '2'
|
21
|
+
- - "<"
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: '4'
|
21
24
|
type: :runtime
|
22
25
|
prerelease: false
|
23
26
|
version_requirements: !ruby/object:Gem::Requirement
|
24
27
|
requirements:
|
25
28
|
- - ">="
|
26
29
|
- !ruby/object:Gem::Version
|
27
|
-
version: '
|
30
|
+
version: '2'
|
31
|
+
- - "<"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '4'
|
28
34
|
- !ruby/object:Gem::Dependency
|
29
35
|
name: actionpack
|
30
36
|
requirement: !ruby/object:Gem::Requirement
|
31
37
|
requirements:
|
32
38
|
- - ">="
|
33
|
-
- !ruby/object:Gem::Version
|
34
|
-
version: '4.2'
|
35
|
-
- - "<="
|
36
39
|
- !ruby/object:Gem::Version
|
37
40
|
version: '5.2'
|
41
|
+
- - "<"
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '6.2'
|
38
44
|
type: :runtime
|
39
45
|
prerelease: false
|
40
46
|
version_requirements: !ruby/object:Gem::Requirement
|
41
47
|
requirements:
|
42
48
|
- - ">="
|
43
|
-
- !ruby/object:Gem::Version
|
44
|
-
version: '4.2'
|
45
|
-
- - "<="
|
46
49
|
- !ruby/object:Gem::Version
|
47
50
|
version: '5.2'
|
51
|
+
- - "<"
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: '6.2'
|
48
54
|
- !ruby/object:Gem::Dependency
|
49
55
|
name: railties
|
50
56
|
requirement: !ruby/object:Gem::Requirement
|
51
57
|
requirements:
|
52
58
|
- - ">="
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: '4.2'
|
55
|
-
- - "<="
|
56
59
|
- !ruby/object:Gem::Version
|
57
60
|
version: '5.2'
|
61
|
+
- - "<"
|
62
|
+
- !ruby/object:Gem::Version
|
63
|
+
version: '6.2'
|
58
64
|
type: :runtime
|
59
65
|
prerelease: false
|
60
66
|
version_requirements: !ruby/object:Gem::Requirement
|
61
67
|
requirements:
|
62
68
|
- - ">="
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
version: '4.2'
|
65
|
-
- - "<="
|
66
69
|
- !ruby/object:Gem::Version
|
67
70
|
version: '5.2'
|
71
|
+
- - "<"
|
72
|
+
- !ruby/object:Gem::Version
|
73
|
+
version: '6.2'
|
68
74
|
- !ruby/object:Gem::Dependency
|
69
75
|
name: has_scope
|
70
76
|
requirement: !ruby/object:Gem::Requirement
|
@@ -79,8 +85,9 @@ dependencies:
|
|
79
85
|
- - "~>"
|
80
86
|
- !ruby/object:Gem::Version
|
81
87
|
version: '0.6'
|
82
|
-
description:
|
83
|
-
inherit all restful actions so you just have to focus on what is important.
|
88
|
+
description: |
|
89
|
+
Inherited Resources speeds up development by making your controllers inherit all restful actions so you just have to focus on what is important.
|
90
|
+
It makes your controllers more powerful and cleaner at the same time.
|
84
91
|
email:
|
85
92
|
executables: []
|
86
93
|
extensions: []
|
@@ -91,7 +98,7 @@ files:
|
|
91
98
|
- app/controllers/inherited_resources/base.rb
|
92
99
|
- lib/generators/rails/USAGE
|
93
100
|
- lib/generators/rails/inherited_resources_controller_generator.rb
|
94
|
-
- lib/generators/rails/templates/controller.rb
|
101
|
+
- lib/generators/rails/templates/controller.rb.tt
|
95
102
|
- lib/inherited_resources.rb
|
96
103
|
- lib/inherited_resources/actions.rb
|
97
104
|
- lib/inherited_resources/base_helpers.rb
|
@@ -106,7 +113,7 @@ files:
|
|
106
113
|
- lib/inherited_resources/singleton_helpers.rb
|
107
114
|
- lib/inherited_resources/url_helpers.rb
|
108
115
|
- lib/inherited_resources/version.rb
|
109
|
-
homepage:
|
116
|
+
homepage: https://github.com/activeadmin/inherited_resources
|
110
117
|
licenses:
|
111
118
|
- MIT
|
112
119
|
metadata: {}
|
@@ -118,15 +125,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
118
125
|
requirements:
|
119
126
|
- - ">="
|
120
127
|
- !ruby/object:Gem::Version
|
121
|
-
version: '2.
|
128
|
+
version: '2.4'
|
122
129
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
130
|
requirements:
|
124
131
|
- - ">="
|
125
132
|
- !ruby/object:Gem::Version
|
126
133
|
version: '0'
|
127
134
|
requirements: []
|
128
|
-
|
129
|
-
rubygems_version: 2.5.1
|
135
|
+
rubygems_version: 3.2.0
|
130
136
|
signing_key:
|
131
137
|
specification_version: 4
|
132
138
|
summary: Inherited Resources speeds up development by making your controllers inherit
|