inherited_resources 1.14.0 → 2.0.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 +4 -4
- data/README.md +5 -5
- data/app/controllers/inherited_resources/base.rb +1 -0
- data/lib/generators/rails/inherited_resources_controller_generator.rb +2 -0
- data/lib/inherited_resources/actions.rb +3 -1
- data/lib/inherited_resources/base_helpers.rb +9 -7
- data/lib/inherited_resources/belongs_to_helpers.rb +5 -3
- data/lib/inherited_resources/blank_slate.rb +3 -1
- data/lib/inherited_resources/class_methods.rb +10 -8
- data/lib/inherited_resources/dsl.rb +2 -0
- data/lib/inherited_resources/engine.rb +2 -0
- data/lib/inherited_resources/polymorphic_helpers.rb +4 -2
- data/lib/inherited_resources/responder.rb +5 -0
- data/lib/inherited_resources/shallow_helpers.rb +3 -1
- data/lib/inherited_resources/singleton_helpers.rb +2 -0
- data/lib/inherited_resources/url_helpers.rb +2 -0
- data/lib/inherited_resources/version.rb +2 -1
- data/lib/inherited_resources.rb +3 -1
- metadata +3 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9a09c7a051f4bb54bd49bdbf51a1a3c0c59d270f78d8fe30f678b3308c19d949
|
|
4
|
+
data.tar.gz: de365970fd390bd077e8cf91fd2793783c7df68b08c224a3ad775ad052606ab0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: e3c2ce831127a24065c97cf8a3fb6857307dd216e27a45e341eb3d41d3d7bf4d8fe6b5d2eda5de913bfc34c52a35bb62cd785f6408298ff039fd5f791d00ca40
|
|
7
|
+
data.tar.gz: fc3908d187aac0c3b96b84a303ff450121f94c7fa8345f6f21650b531eab0be9f0fc20bbec3c0d237d2a416b172d0e43fe7345015bb12ef6651ede85399babfe
|
data/README.md
CHANGED
|
@@ -5,7 +5,7 @@ has been transferred to the ActiveAdmin organization for maintenance. New featu
|
|
|
5
5
|
requests are not encouraged.
|
|
6
6
|
|
|
7
7
|
If you are not already using Inherited Resources we suggest instead using Rails'
|
|
8
|
-
`respond_with` feature alongside the [responders gem](https://github.com/
|
|
8
|
+
`respond_with` feature alongside the [responders gem](https://github.com/heartcombo/responders).
|
|
9
9
|
|
|
10
10
|
## Inherited Resources
|
|
11
11
|
|
|
@@ -22,7 +22,7 @@ code by following fat models and skinny controllers convention. There are
|
|
|
22
22
|
two screencasts available besides this README:
|
|
23
23
|
|
|
24
24
|
* http://railscasts.com/episodes/230-inherited-resources
|
|
25
|
-
*
|
|
25
|
+
* https://www.akitaonrails.com/2009/09/01/screencast-real-thin-restful-controllers-with-inherited-resources
|
|
26
26
|
|
|
27
27
|
## Installation
|
|
28
28
|
|
|
@@ -49,7 +49,7 @@ $ gem install inherited_resources
|
|
|
49
49
|
Since Inherited Resources 1.0, has_scope is not part of its core anymore but
|
|
50
50
|
a gem dependency. Be sure to check the documentation to see how you can use it:
|
|
51
51
|
|
|
52
|
-
- <
|
|
52
|
+
- <https://github.com/heartcombo/has_scope>
|
|
53
53
|
|
|
54
54
|
And it can be installed as:
|
|
55
55
|
|
|
@@ -64,7 +64,7 @@ but is set as Inherited Resources dependency and it's used by default by
|
|
|
64
64
|
InheritedResources controllers. Be sure to check the documentation to see
|
|
65
65
|
how it will change your application:
|
|
66
66
|
|
|
67
|
-
- <
|
|
67
|
+
- <https://github.com/heartcombo/responders>
|
|
68
68
|
|
|
69
69
|
And it can be installed with:
|
|
70
70
|
|
|
@@ -737,7 +737,7 @@ MIT License. Copyright (c) 2009-2017 José Valim.
|
|
|
737
737
|
Please use the Tidelift security contact to [report a security vulnerability][Tidelift security contact].
|
|
738
738
|
Tidelift will coordinate the fix and disclosure.
|
|
739
739
|
|
|
740
|
-
[rubygems_badge]:
|
|
740
|
+
[rubygems_badge]: https://img.shields.io/gem/v/inherited_resources.svg
|
|
741
741
|
[rubygems]: https://rubygems.org/gems/inherited_resources
|
|
742
742
|
[actions_badge]: https://github.com/activeadmin/inherited_resources/workflows/ci/badge.svg
|
|
743
743
|
[actions]: https://github.com/activeadmin/inherited_resources/actions
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# Whenever base is required load the dumb responder since it's used inside actions.
|
|
2
4
|
require 'inherited_resources/blank_slate'
|
|
3
5
|
|
|
@@ -54,7 +56,7 @@ module InheritedResources
|
|
|
54
56
|
|
|
55
57
|
# Responsible for saving the resource on :create method. Overwriting this
|
|
56
58
|
# allow you to control the way resource is saved. Let's say you have a
|
|
57
|
-
#
|
|
59
|
+
# PasswordsController who is responsible for finding an user by email and
|
|
58
60
|
# sent password instructions for him. Instead of overwriting the entire
|
|
59
61
|
# :create method, you could do something:
|
|
60
62
|
#
|
|
@@ -133,7 +135,7 @@ module InheritedResources
|
|
|
133
135
|
end
|
|
134
136
|
|
|
135
137
|
# rubocop:disable Layout/CommentIndentation
|
|
136
|
-
# See https://github.com/rubocop
|
|
138
|
+
# See https://github.com/rubocop/rubocop/issues/6450
|
|
137
139
|
#
|
|
138
140
|
# Overwrite this method to provide other interpolation options when
|
|
139
141
|
# the flash message is going to be set.
|
|
@@ -215,7 +217,7 @@ module InheritedResources
|
|
|
215
217
|
#
|
|
216
218
|
def get_resource_ivar #:nodoc:
|
|
217
219
|
if instance_variable_defined?(:"@#{resource_instance_name}")
|
|
218
|
-
instance_variable_get("@#{resource_instance_name}")
|
|
220
|
+
instance_variable_get(:"@#{resource_instance_name}")
|
|
219
221
|
else
|
|
220
222
|
nil
|
|
221
223
|
end
|
|
@@ -224,14 +226,14 @@ module InheritedResources
|
|
|
224
226
|
# Set resource ivar based on the current resource controller.
|
|
225
227
|
#
|
|
226
228
|
def set_resource_ivar(resource) #:nodoc:
|
|
227
|
-
instance_variable_set("@#{resource_instance_name}", resource)
|
|
229
|
+
instance_variable_set(:"@#{resource_instance_name}", resource)
|
|
228
230
|
end
|
|
229
231
|
|
|
230
232
|
# Get collection ivar based on the current resource controller.
|
|
231
233
|
#
|
|
232
234
|
def get_collection_ivar #:nodoc:
|
|
233
235
|
if instance_variable_defined?(:"@#{resource_collection_name}")
|
|
234
|
-
instance_variable_get("@#{resource_collection_name}")
|
|
236
|
+
instance_variable_get(:"@#{resource_collection_name}")
|
|
235
237
|
else
|
|
236
238
|
nil
|
|
237
239
|
end
|
|
@@ -240,7 +242,7 @@ module InheritedResources
|
|
|
240
242
|
# Set collection ivar based on the current resource controller.
|
|
241
243
|
#
|
|
242
244
|
def set_collection_ivar(collection) #:nodoc:
|
|
243
|
-
instance_variable_set("@#{resource_collection_name}", collection)
|
|
245
|
+
instance_variable_set(:"@#{resource_collection_name}", collection)
|
|
244
246
|
end
|
|
245
247
|
|
|
246
248
|
# Used to allow to specify success and failure within just one block:
|
|
@@ -368,7 +370,7 @@ module InheritedResources
|
|
|
368
370
|
self.resources_configuration[:self][:role].present?
|
|
369
371
|
end
|
|
370
372
|
|
|
371
|
-
# getting role for mass-
|
|
373
|
+
# getting role for mass-assignment
|
|
372
374
|
def as_role
|
|
373
375
|
{ as: self.resources_configuration[:self][:role] }
|
|
374
376
|
end
|
|
@@ -1,9 +1,11 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module InheritedResources
|
|
2
4
|
|
|
3
5
|
# = belongs_to
|
|
4
6
|
#
|
|
5
7
|
# Let's suppose that we have some tasks that belongs to projects. To specify
|
|
6
|
-
# this
|
|
8
|
+
# this association in your controllers, just do:
|
|
7
9
|
#
|
|
8
10
|
# class TasksController < InheritedResources::Base
|
|
9
11
|
# belongs_to :project
|
|
@@ -77,7 +79,7 @@ module InheritedResources
|
|
|
77
79
|
|
|
78
80
|
def get_parent_ivar(instance_name) #:nodoc:
|
|
79
81
|
instance_variable_defined?(:"@#{instance_name}") &&
|
|
80
|
-
instance_variable_get("@#{instance_name}")
|
|
82
|
+
instance_variable_get(:"@#{instance_name}")
|
|
81
83
|
end
|
|
82
84
|
|
|
83
85
|
def set_parent_instance(parent_config, chain) #:nodoc:
|
|
@@ -97,7 +99,7 @@ module InheritedResources
|
|
|
97
99
|
parent = parent.send(parent_config[:finder], params[parent_config[:param]])
|
|
98
100
|
end
|
|
99
101
|
|
|
100
|
-
instance_variable_set("@#{parent_config[:instance_name]}", parent)
|
|
102
|
+
instance_variable_set(:"@#{parent_config[:instance_name]}", parent)
|
|
101
103
|
end
|
|
102
104
|
|
|
103
105
|
# Maps parents_symbols to build association chain. In this case, it
|
|
@@ -1,8 +1,10 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module InheritedResources
|
|
2
4
|
# An object from BlankSlate simply discards all messages sent to it.
|
|
3
5
|
class BlankSlate
|
|
4
6
|
instance_methods.each do |m|
|
|
5
|
-
undef_method m unless
|
|
7
|
+
undef_method m unless /^(__|object_id)/.match?(m)
|
|
6
8
|
end
|
|
7
9
|
|
|
8
10
|
def method_missing(*args)
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module InheritedResources
|
|
2
4
|
module ClassMethods
|
|
3
5
|
|
|
@@ -25,7 +27,7 @@ module InheritedResources
|
|
|
25
27
|
#
|
|
26
28
|
# * <tt>:route_instance_name</tt> - The name of the singular route. Defaults to :instance_name.
|
|
27
29
|
#
|
|
28
|
-
# * <tt>:route_prefix</tt> - The route prefix which is
|
|
30
|
+
# * <tt>:route_prefix</tt> - The route prefix which is automatically set in namespaced
|
|
29
31
|
# controllers. Default to :admin on Admin::ProjectsController.
|
|
30
32
|
#
|
|
31
33
|
# * <tt>:singleton</tt> - Tells if this controller is singleton or not.
|
|
@@ -53,7 +55,7 @@ module InheritedResources
|
|
|
53
55
|
config[:request_name] = begin
|
|
54
56
|
request_name = self.resource_class
|
|
55
57
|
request_name = request_name.model_name.param_key if request_name.respond_to?(:model_name)
|
|
56
|
-
request_name.to_s.underscore.
|
|
58
|
+
request_name.to_s.underscore.tr('/', '_')
|
|
57
59
|
end
|
|
58
60
|
options.delete(:resource_class) and options.delete(:class_name)
|
|
59
61
|
end
|
|
@@ -65,7 +67,7 @@ module InheritedResources
|
|
|
65
67
|
create_resources_url_helpers!
|
|
66
68
|
end
|
|
67
69
|
|
|
68
|
-
# Defines
|
|
70
|
+
# Defines which actions will be inherited from the inherited controller.
|
|
69
71
|
# Syntax is borrowed from resource_controller.
|
|
70
72
|
#
|
|
71
73
|
# actions :index, :show, :edit
|
|
@@ -215,7 +217,7 @@ module InheritedResources
|
|
|
215
217
|
config[:finder] = finder || :find
|
|
216
218
|
end
|
|
217
219
|
|
|
218
|
-
if
|
|
220
|
+
if block
|
|
219
221
|
class_eval(&block)
|
|
220
222
|
else
|
|
221
223
|
create_resources_url_helpers!
|
|
@@ -227,7 +229,7 @@ module InheritedResources
|
|
|
227
229
|
#
|
|
228
230
|
def polymorphic_belongs_to(*symbols, &block)
|
|
229
231
|
options = symbols.extract_options!
|
|
230
|
-
options
|
|
232
|
+
options[:polymorphic] = true
|
|
231
233
|
belongs_to(*symbols, options, &block)
|
|
232
234
|
end
|
|
233
235
|
|
|
@@ -235,7 +237,7 @@ module InheritedResources
|
|
|
235
237
|
#
|
|
236
238
|
def singleton_belongs_to(*symbols, &block)
|
|
237
239
|
options = symbols.extract_options!
|
|
238
|
-
options
|
|
240
|
+
options[:singleton] = true
|
|
239
241
|
belongs_to(*symbols, options, &block)
|
|
240
242
|
end
|
|
241
243
|
|
|
@@ -243,7 +245,7 @@ module InheritedResources
|
|
|
243
245
|
#
|
|
244
246
|
def optional_belongs_to(*symbols, &block)
|
|
245
247
|
options = symbols.extract_options!
|
|
246
|
-
options
|
|
248
|
+
options[:optional] = true
|
|
247
249
|
belongs_to(*symbols, options, &block)
|
|
248
250
|
end
|
|
249
251
|
|
|
@@ -384,7 +386,7 @@ module InheritedResources
|
|
|
384
386
|
# Forum::Thread#create will properly pick up the request parameter
|
|
385
387
|
# which will be forum_thread, and not thread
|
|
386
388
|
# Additionally make this work orthogonally with instance_name
|
|
387
|
-
config[:request_name] = self.resource_class.to_s.underscore.
|
|
389
|
+
config[:request_name] = self.resource_class.to_s.underscore.tr('/', '_')
|
|
388
390
|
|
|
389
391
|
# Initialize polymorphic, singleton, scopes and belongs_to parameters
|
|
390
392
|
polymorphic = self.resources_configuration[:polymorphic] || { symbols: [], optional: false }
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module InheritedResources
|
|
2
4
|
|
|
3
5
|
# = polymorphic associations
|
|
@@ -120,8 +122,8 @@ module InheritedResources
|
|
|
120
122
|
#
|
|
121
123
|
def parent
|
|
122
124
|
if parent_type
|
|
123
|
-
p = instance_variable_defined?("@#{parent_type}") && instance_variable_get("@#{parent_type}")
|
|
124
|
-
p || instance_variable_set("@#{parent_type}", association_chain[-1])
|
|
125
|
+
p = instance_variable_defined?(:"@#{parent_type}") && instance_variable_get(:"@#{parent_type}")
|
|
126
|
+
p || instance_variable_set(:"@#{parent_type}", association_chain[-1])
|
|
125
127
|
end
|
|
126
128
|
end
|
|
127
129
|
|
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
module InheritedResources
|
|
2
4
|
# Shallow provides a functionality that goes on pair with Rails' shallow.
|
|
3
5
|
# It is very similar to "optional" but it actually finds all the parents
|
|
@@ -33,7 +35,7 @@ module InheritedResources
|
|
|
33
35
|
end
|
|
34
36
|
|
|
35
37
|
def load_parents(instance, parent_symbols)
|
|
36
|
-
parent_symbols.
|
|
38
|
+
parent_symbols.reverse_each do |parent|
|
|
37
39
|
instance = instance.send(parent)
|
|
38
40
|
config = resources_configuration[parent]
|
|
39
41
|
params[config[:param]] = instance.to_param
|
data/lib/inherited_resources.rb
CHANGED
|
@@ -1,3 +1,5 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
1
3
|
# This is here because responders don't require it.
|
|
2
4
|
require 'rails/engine'
|
|
3
5
|
require 'responders'
|
|
@@ -28,7 +30,7 @@ end
|
|
|
28
30
|
ActiveSupport.on_load(:action_controller_base) do
|
|
29
31
|
# If you cannot inherit from InheritedResources::Base you can call
|
|
30
32
|
# inherit_resources in your controller to have all the required modules and
|
|
31
|
-
#
|
|
33
|
+
# functionality included.
|
|
32
34
|
def self.inherit_resources
|
|
33
35
|
InheritedResources::Base.inherit_resources(self)
|
|
34
36
|
initialize_resources_class_accessors!
|
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:
|
|
4
|
+
version: 2.0.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: 2024-09-15 00:00:00.000000000 Z
|
|
13
13
|
dependencies:
|
|
14
14
|
- !ruby/object:Gem::Dependency
|
|
15
15
|
name: responders
|
|
@@ -115,7 +115,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
115
115
|
- !ruby/object:Gem::Version
|
|
116
116
|
version: '0'
|
|
117
117
|
requirements: []
|
|
118
|
-
rubygems_version: 3.
|
|
118
|
+
rubygems_version: 3.5.18
|
|
119
119
|
signing_key:
|
|
120
120
|
specification_version: 4
|
|
121
121
|
summary: Inherited Resources speeds up development by making your controllers inherit
|