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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: a3deb097f7881768ed33aa684188d8b19eaaad1a
4
- data.tar.gz: dfac24780729a88a781c708c183fda899e4c8b24
2
+ SHA256:
3
+ metadata.gz: f4cb8a8e3e1fc321346443a8264926120e60b5a4e316987143a58a6278114c4c
4
+ data.tar.gz: 942712a75ce52463be67c273ebefa83dced93511bde604efec8cf2223cbdc6c4
5
5
  SHA512:
6
- metadata.gz: 6d0ccce04af931a80d457f25434fe6a7aa035915096ecedb4b2a1c040a2bf84473bbad26e69316820263a4220f846bc6f9e217ca9ca825c06ae74e40af5bb30f
7
- data.tar.gz: c2d60488ae290f43bebe6f2f06178259007619ecf75cdbd52bbb64d55e3136e2470a81e993855f02cc3198cf11d172e2c52e3872de915c00850903373906edca
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](http://img.shields.io/gem/v/inherited_resources.svg)](https://rubygems.org/gems/inherited_resources)
13
- [![Travis CI](http://img.shields.io/travis/activeadmin/inherited_resources/master.svg)](https://travis-ci.org/activeadmin/inherited_resources)
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, :instance_writer => false unless self.respond_to? :resource_class
34
- self.class_attribute :parents_symbols, :resources_configuration, :instance_writer => false
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
@@ -8,4 +8,4 @@ module Rails
8
8
  end
9
9
  end
10
10
  end
11
- end
11
+ 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
@@ -64,4 +64,3 @@ module InheritedResources
64
64
  protected :index!, :show!, :new!, :create!, :edit!, :update!, :destroy!
65
65
  end
66
66
  end
67
-
@@ -22,14 +22,7 @@ module InheritedResources
22
22
  def collection
23
23
  get_collection_ivar || begin
24
24
  c = end_of_association_chain
25
- if defined?(ActiveRecord::DeprecatedFinders)
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 :update_attributes:
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.update_attributes(*attributes)
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
- { :as => self.resources_configuration[:self][:role] }
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
- { :without_protection => self.resources_configuration[:self][:without_protection] }
381
+ { without_protection: self.resources_configuration[:self][:without_protection] }
384
382
  end
385
383
  end
386
384
  end
387
-
@@ -56,11 +56,11 @@ module InheritedResources
56
56
  def parent?
57
57
  true
58
58
  end
59
-
59
+
60
60
  def parent
61
61
  @parent ||= association_chain[-1]
62
62
  end
63
-
63
+
64
64
  def parent_type
65
65
  parent.class.name.underscore.to_sym
66
66
  end
@@ -152,7 +152,10 @@ module InheritedResources
152
152
  polymorphic = options.delete(:polymorphic)
153
153
  finder = options.delete(:finder)
154
154
 
155
- include BelongsToHelpers if self.parents_symbols.empty?
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!(:polymorphic => true)
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!(:singleton => true)
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!(:optional => true)
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, :except => :index
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] || { :symbols => [], :optional => false }
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 @parent_type
105
+ unless instance_variable_defined?(:@parent_type)
106
106
  symbols_for_association_chain
107
107
  end
108
108
 
109
- @parent_type
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
- @parent_types = keys.map(&:to_sym)
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
- # This method hard code url helpers in the class.
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
- 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].inspect
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 << config[:route_name]
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
- # Generate parent url before we add resource instances.
88
- unless parents_symbols.empty?
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
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
- # 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]}"
83
+ collection_ivars = resource_ivars.dup
84
+ collection_segments = resource_segments.dup
99
85
 
100
- # In singleton cases, we do not send the current element instance variable
101
- # because the id is not in the URL. For example, we should call:
102
- #
103
- # project_manager_url(@project)
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
- if polymorphic
125
- resource_ivars << resource_config[:instance_name].inspect
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
- # If route is uncountable then add "_index" suffix to collection index route name
133
- if uncountable
134
- collection_segments << :"#{collection_segments.pop}_index"
135
- end
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
- generate_url_and_path_helpers nil, :collection, collection_segments, collection_ivars
138
- generate_url_and_path_helpers :new, :resource, resource_segments, new_ivars || collection_ivars
139
- generate_url_and_path_helpers nil, :resource, resource_segments, resource_ivars
140
- generate_url_and_path_helpers :edit, :resource, resource_segments, resource_ivars
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
- if resource_config[:custom_actions]
143
- [*resource_config[:custom_actions][:resource]].each do | method |
144
- generate_url_and_path_helpers method, :resource, resource_segments, resource_ivars
145
- end
146
- [*resource_config[:custom_actions][:collection]].each do | method |
147
- generate_url_and_path_helpers method, :resources, collection_segments, collection_ivars
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
- end
151
-
152
- def handle_shallow_resource(prefix, name, segments, ivars) #:nodoc:
153
- return segments, ivars unless self.resources_configuration[:self][:shallow]
154
- case name
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
- else
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
- segments ||= []
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
- unless self.resources_configuration[:self][:route_prefix].blank?
174
- segments.unshift self.resources_configuration[:self][:route_prefix]
166
+ return segments, ivars
175
167
  end
176
168
 
177
- return segments, ivars
178
- end
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
- def generate_url_and_path_helpers(prefix, name, resource_segments, resource_ivars) #:nodoc:
181
- resource_segments, resource_ivars = handle_shallow_resource(prefix, name, resource_segments, resource_ivars)
172
+ ivars = resource_ivars.dup
173
+ singleton = self.resources_configuration[:self][:singleton]
174
+ polymorphic = self.parents_symbols.include?(:polymorphic)
182
175
 
183
- ivars = resource_ivars.dup
184
- singleton = self.resources_configuration[:self][:singleton]
185
- polymorphic = self.parents_symbols.include?(:polymorphic)
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
- # If it's not a singleton, ivars are not empty, not a collection or
188
- # not a "new" named route, we can pass a resource as argument.
189
- #
190
- unless (singleton && name != :parent) || ivars.empty? || name == :collection || prefix == :new
191
- ivars.push "(given_args.first || #{ivars.pop})"
192
- end
181
+ segments = if polymorphic
182
+ :polymorphic
183
+ elsif resource_segments.empty?
184
+ 'root'
185
+ else
186
+ resource_segments.join('_')
187
+ end
193
188
 
194
- # In collection in polymorphic cases, allow an argument to be given as a
195
- # replacemente for the parent.
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
- # When polymorphic is true, the segments must be replace by :polymorphic
204
- # and ivars should be gathered into an array, which is compacted when
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
- prefix = prefix ? "#{prefix}_" : ''
217
- ivars << (ivars.empty? ? 'given_options' : ', given_options')
197
+ undef_method params_method_name if method_defined? params_method_name
218
198
 
219
- given_args_transform = 'given_args = given_args.collect { |arg| arg.respond_to?(:permitted?) ? arg.to_h : arg }'
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
- class_eval <<-URL_HELPERS, __FILE__, __LINE__
222
- protected
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
- undef :#{prefix}#{name}_url if method_defined? :#{prefix}#{name}_url
231
- def #{prefix}#{name}_url(*given_args)
232
- #{given_args_transform}
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
- URL_HELPERS
237
- end
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
@@ -1,3 +1,3 @@
1
1
  module InheritedResources
2
- VERSION = '1.8.0'.freeze
2
+ VERSION = '1.12.0'.freeze
3
3
  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.8.0
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: 2017-12-01 00:00:00.000000000 Z
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: '0'
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: '0'
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: Inherited Resources speeds up development by making your controllers
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: http://github.com/activeadmin/inherited_resources
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.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
- rubyforge_project: inherited_resources
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