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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 03db109061a1b24bfcb06bfc8d914b722199b904
4
- data.tar.gz: 2bf410b8133cbf11d26f0d6184a26a7200544005
2
+ SHA256:
3
+ metadata.gz: a7a43b4aa765bf23215cacb33f020c970a8b39b378ad1edae4f957261c33f9ef
4
+ data.tar.gz: f98a4d38498a2d7fd15a90c2a81989e095b666aaf00c1e4cb33c45c0e2ecacec
5
5
  SHA512:
6
- metadata.gz: 7f087d2234213f9a4b82465fe0c5c75740e641ac1471a9c8d4499ee216146bfb5c73ad488449e74c1a980496ee48a40f9c018b20bb50891d3e1d49bcefffe785
7
- data.tar.gz: 2599459d549f58c04218463532a1cdcd23e729dc082fb52b6b3be9da1f95b2dd50a34e5e37e697f7cf7a54ff773766735cdd63bc547464e89975f0c543b6bc80
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](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
@@ -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, :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
 
@@ -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.9.0'.freeze
2
+ VERSION = '1.10.0.rc1'.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.9.0
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: 2018-08-10 00:00:00.000000000 Z
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: '4.2'
34
+ version: '5.0'
35
35
  - - "<"
36
36
  - !ruby/object:Gem::Version
37
- version: '5.3'
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: '4.2'
44
+ version: '5.0'
45
45
  - - "<"
46
46
  - !ruby/object:Gem::Version
47
- version: '5.3'
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: '4.2'
54
+ version: '5.0'
55
55
  - - "<"
56
56
  - !ruby/object:Gem::Version
57
- version: '5.3'
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: '4.2'
64
+ version: '5.0'
65
65
  - - "<"
66
66
  - !ruby/object:Gem::Version
67
- version: '5.3'
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: Inherited Resources speeds up development by making your controllers
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: http://github.com/activeadmin/inherited_resources
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: '0'
127
+ version: 1.3.1
127
128
  requirements: []
128
- rubyforge_project: inherited_resources
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