inherited_resources 1.9.0 → 1.10.0.rc1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +17 -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 +8 -11
- 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 +22 -22
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a7a43b4aa765bf23215cacb33f020c970a8b39b378ad1edae4f957261c33f9ef
|
4
|
+
data.tar.gz: f98a4d38498a2d7fd15a90c2a81989e095b666aaf00c1e4cb33c45c0e2ecacec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d63e330bc594a3a7d1b7d848df74f67752016369295c8134bc73e146a3ffc8e36b43d3c90919cdaddfb38cb73724d72b27ef628bb72e59f13852a26138b5714d
|
7
|
+
data.tar.gz: e2f2005557761dfa210dab2fcf337ec4d62b86fe7a729cfaa770f9abe015e14ebf3e00e7af2c5827dd7f2b1f153cd2881395bd0158f8eddc15386ea54750528d
|
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
|
@@ -723,3 +724,17 @@ If you discover any bugs, please describe it in the issues tracker, including Ra
|
|
723
724
|
Questions are better handled on StackOverflow.
|
724
725
|
|
725
726
|
MIT License. Copyright (c) 2009-2017 José Valim.
|
727
|
+
|
728
|
+
## Security contact information
|
729
|
+
|
730
|
+
Please use the Tidelift security contact to [report a security vulnerability][Tidelift security contact].
|
731
|
+
Tidelift will coordinate the fix and disclosure.
|
732
|
+
|
733
|
+
[rubygems_badge]: http://img.shields.io/gem/v/inherited_resources.svg
|
734
|
+
[rubygems]: https://rubygems.org/gems/inherited_resources
|
735
|
+
[circleci_badge]: https://circleci.com/gh/activeadmin/inherited_resources.svg?style=svg
|
736
|
+
[circleci]: https://circleci.com/gh/activeadmin/inherited_resources
|
737
|
+
[tidelift_badge]: https://tidelift.com/badges/github/activeadmin/inherited_resources
|
738
|
+
[tidelift]: https://tidelift.com/subscription/pkg/rubygems-inherited-resources?utm_source=rubygems-inherited-resources&utm_medium=readme
|
739
|
+
|
740
|
+
[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
|
|
@@ -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.10.0.rc1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- José Valim
|
@@ -9,62 +9,62 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2019-03-24 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: responders
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
requirements:
|
18
|
-
- - "
|
18
|
+
- - "~>"
|
19
19
|
- !ruby/object:Gem::Version
|
20
|
-
version: '0'
|
20
|
+
version: '2.0'
|
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: '0'
|
27
|
+
version: '2.0'
|
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: '
|
34
|
+
version: '5.0'
|
35
35
|
- - "<"
|
36
36
|
- !ruby/object:Gem::Version
|
37
|
-
version: '
|
37
|
+
version: '6.0'
|
38
38
|
type: :runtime
|
39
39
|
prerelease: false
|
40
40
|
version_requirements: !ruby/object:Gem::Requirement
|
41
41
|
requirements:
|
42
42
|
- - ">="
|
43
43
|
- !ruby/object:Gem::Version
|
44
|
-
version: '
|
44
|
+
version: '5.0'
|
45
45
|
- - "<"
|
46
46
|
- !ruby/object:Gem::Version
|
47
|
-
version: '
|
47
|
+
version: '6.0'
|
48
48
|
- !ruby/object:Gem::Dependency
|
49
49
|
name: railties
|
50
50
|
requirement: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
52
|
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
|
-
version: '
|
54
|
+
version: '5.0'
|
55
55
|
- - "<"
|
56
56
|
- !ruby/object:Gem::Version
|
57
|
-
version: '
|
57
|
+
version: '6.0'
|
58
58
|
type: :runtime
|
59
59
|
prerelease: false
|
60
60
|
version_requirements: !ruby/object:Gem::Requirement
|
61
61
|
requirements:
|
62
62
|
- - ">="
|
63
63
|
- !ruby/object:Gem::Version
|
64
|
-
version: '
|
64
|
+
version: '5.0'
|
65
65
|
- - "<"
|
66
66
|
- !ruby/object:Gem::Version
|
67
|
-
version: '
|
67
|
+
version: '6.0'
|
68
68
|
- !ruby/object:Gem::Dependency
|
69
69
|
name: has_scope
|
70
70
|
requirement: !ruby/object:Gem::Requirement
|
@@ -79,8 +79,9 @@ dependencies:
|
|
79
79
|
- - "~>"
|
80
80
|
- !ruby/object:Gem::Version
|
81
81
|
version: '0.6'
|
82
|
-
description:
|
83
|
-
inherit all restful actions so you just have to focus on what is important.
|
82
|
+
description: |
|
83
|
+
Inherited Resources speeds up development by making your controllers inherit all restful actions so you just have to focus on what is important.
|
84
|
+
It makes your controllers more powerful and cleaner at the same time.
|
84
85
|
email:
|
85
86
|
executables: []
|
86
87
|
extensions: []
|
@@ -91,7 +92,7 @@ files:
|
|
91
92
|
- app/controllers/inherited_resources/base.rb
|
92
93
|
- lib/generators/rails/USAGE
|
93
94
|
- lib/generators/rails/inherited_resources_controller_generator.rb
|
94
|
-
- lib/generators/rails/templates/controller.rb
|
95
|
+
- lib/generators/rails/templates/controller.rb.tt
|
95
96
|
- lib/inherited_resources.rb
|
96
97
|
- lib/inherited_resources/actions.rb
|
97
98
|
- lib/inherited_resources/base_helpers.rb
|
@@ -106,7 +107,7 @@ files:
|
|
106
107
|
- lib/inherited_resources/singleton_helpers.rb
|
107
108
|
- lib/inherited_resources/url_helpers.rb
|
108
109
|
- lib/inherited_resources/version.rb
|
109
|
-
homepage:
|
110
|
+
homepage: https://github.com/activeadmin/inherited_resources
|
110
111
|
licenses:
|
111
112
|
- MIT
|
112
113
|
metadata: {}
|
@@ -121,12 +122,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
121
122
|
version: '2.3'
|
122
123
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
123
124
|
requirements:
|
124
|
-
- - "
|
125
|
+
- - ">"
|
125
126
|
- !ruby/object:Gem::Version
|
126
|
-
version:
|
127
|
+
version: 1.3.1
|
127
128
|
requirements: []
|
128
|
-
|
129
|
-
rubygems_version: 2.6.14
|
129
|
+
rubygems_version: 3.0.3
|
130
130
|
signing_key:
|
131
131
|
specification_version: 4
|
132
132
|
summary: Inherited Resources speeds up development by making your controllers inherit
|