effective_resources 0.8.25 → 0.8.26
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
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a06e3e88a6bf810728238c3e946eb7cca8d91360
|
4
|
+
data.tar.gz: 2dc0d2c0e88675f7f355ec8a0c172faa5c5cd98d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6df911c7b05cf356999d037a0fe8873fc06a100e0bf3dffbe4b82343a9d876893a3ceac152c60c64e52391b660e09b3d3e59440403063a02cf2ee7e5552e0e2a
|
7
|
+
data.tar.gz: 0b3c9d1df71cecc5e0299587423e381e931b9a3bb730c0b636c02240dfbbe5fa2a87a8e4b9aa41ce0b6b5a76916d0dc2b93cf649cee0ba8098399128d3de10d6
|
@@ -38,15 +38,27 @@ module EffectiveResourcesHelper
|
|
38
38
|
end
|
39
39
|
end
|
40
40
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
41
|
+
def render_resource_crud_actions(resource, instance = nil, atts = {}, &block)
|
42
|
+
(atts = instance; instance = nil) if instance.kind_of?(Hash) && atts.blank?
|
43
|
+
render_resource_actions(resource, instance, atts.merge(crud: true), &block)
|
44
|
+
end
|
45
|
+
|
46
|
+
# resource is an Effective::Resource
|
47
|
+
# instance is an ActiveRecord thing
|
48
|
+
# atts are crud: true|false, locals: {}, namespace:, partial:
|
49
|
+
# anything else are actions, edit: true, show: false, destroy: false and member GET actions
|
50
|
+
def render_resource_actions(resource, instance = nil, atts = {}, &block)
|
51
|
+
(atts = instance; instance = nil) if instance.kind_of?(Hash) && atts.blank?
|
52
|
+
raise 'expected first argument to be an Effective::Resource' unless resource.kind_of?(Effective::Resource)
|
53
|
+
raise 'expected attributes to be a Hash' unless atts.kind_of?(Hash)
|
54
|
+
|
55
|
+
instance = instance || instance_variable_get('@' + resource.name) || resource.instance
|
56
|
+
raise "unable to find resource instance. Either pass the instance as the second argument, or assign @#{resource.name}" unless instance
|
48
57
|
|
49
|
-
|
58
|
+
crud = atts.delete(:crud) || false
|
59
|
+
locals = atts.delete(:locals) || {}
|
60
|
+
namespace = atts.delete(:namespace) || (resource.namespace.to_sym if resource.namespace)
|
61
|
+
partial = atts.delete(:partial)
|
50
62
|
|
51
63
|
partial = case partial
|
52
64
|
when String
|
@@ -57,20 +69,28 @@ module EffectiveResourcesHelper
|
|
57
69
|
'effective/resource/actions'
|
58
70
|
end + '.html'.freeze
|
59
71
|
|
60
|
-
actions =
|
72
|
+
actions = (crud ? resource.resource_crud_actions : resource.resource_actions)
|
73
|
+
raise "unknown action for #{resource.name}: #{unknown}." if (unknown = (atts.keys - actions)).present?
|
74
|
+
|
75
|
+
actions = actions - atts.reject { |_, v| v }.keys + atts.select { |_, v| v }.keys
|
61
76
|
actions = actions.uniq.select { |action| EffectiveResources.authorized?(controller, action, resource) }
|
62
77
|
|
63
|
-
locals = { resource:
|
78
|
+
locals = { resource: instance, effective_resource: resource, namespace: namespace, actions: actions }.compact.merge(locals)
|
64
79
|
|
65
80
|
block_given? ? render((partial), locals) { yield } : render((partial), locals)
|
66
81
|
end
|
67
82
|
|
68
83
|
# When called from /admin/things/new.html.haml this will render 'admin/things/form', or 'things/form', or 'thing/form'
|
69
|
-
def render_resource_form(resource, atts = {})
|
70
|
-
|
84
|
+
def render_resource_form(resource, instance = nil, atts = {})
|
85
|
+
(atts = instance; instance = nil) if instance.kind_of?(Hash) && atts.blank?
|
86
|
+
raise 'expected first argument to be an Effective::Resource' unless resource.kind_of?(Effective::Resource)
|
87
|
+
raise 'expected attributes to be a Hash' unless atts.kind_of?(Hash)
|
88
|
+
|
89
|
+
instance = instance || instance_variable_get('@' + resource.name) || resource.instance
|
90
|
+
raise "unable to find resource instance. Either pass the instance as the second argument, or assign @#{resource.name}" unless instance
|
71
91
|
|
72
92
|
action = atts.delete(:action)
|
73
|
-
atts = {:namespace => (resource.namespace.to_sym if resource.namespace
|
93
|
+
atts = { :namespace => (resource.namespace.to_sym if resource.namespace), resource.name.to_sym => instance }.compact.merge(atts)
|
74
94
|
|
75
95
|
if lookup_context.template_exists?("form_#{action}", controller._prefixes, :partial)
|
76
96
|
render "form_#{action}", atts
|
@@ -72,7 +72,11 @@ module Effective
|
|
72
72
|
# Used by render_resource_actions helper
|
73
73
|
# All the actions we can actually make a link to
|
74
74
|
def resource_actions
|
75
|
-
(routes.keys & [:show, :edit, :destroy]) +
|
75
|
+
(routes.keys & [:show, :edit, :destroy]) + member_get_actions
|
76
|
+
end
|
77
|
+
|
78
|
+
def resource_crud_actions
|
79
|
+
(routes.keys & [:show, :edit, :destroy])
|
76
80
|
end
|
77
81
|
|
78
82
|
# GET actions
|