effective_resources 0.8.25 → 0.8.26

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
2
  SHA1:
3
- metadata.gz: f57a417ad564ad29d28a1412c0904dd625c2f29a
4
- data.tar.gz: 52f253bcaffbb82d52608f3896710d0ffe303d9a
3
+ metadata.gz: a06e3e88a6bf810728238c3e946eb7cca8d91360
4
+ data.tar.gz: 2dc0d2c0e88675f7f355ec8a0c172faa5c5cd98d
5
5
  SHA512:
6
- metadata.gz: 6c508fa5e22d48790095424fcdd57a7e33fceb3b5f497527759438387ebe5fd9cb1519676af99fdcffbdb2525e172a623dd0c51f58286a3f9cb5c6ae08636b43
7
- data.tar.gz: 539d90c320493b985b4ba963d11fabfbb97977f58b76cf1d3918fb1fc7945af59822694d61a87e83b5622b1348d9868e15648c89aec7fe650370e6eb602393b2
6
+ metadata.gz: 6df911c7b05cf356999d037a0fe8873fc06a100e0bf3dffbe4b82343a9d876893a3ceac152c60c64e52391b660e09b3d3e59440403063a02cf2ee7e5552e0e2a
7
+ data.tar.gz: 0b3c9d1df71cecc5e0299587423e381e931b9a3bb730c0b636c02240dfbbe5fa2a87a8e4b9aa41ce0b6b5a76916d0dc2b93cf649cee0ba8098399128d3de10d6
@@ -38,15 +38,27 @@ module EffectiveResourcesHelper
38
38
  end
39
39
  end
40
40
 
41
- # resource: resource is an
42
- # show: true, edit: true, destroy: true
43
- def render_resource_actions(resource, effective_resource: nil, namespace: nil, partial: nil, **atts, &block)
44
- effective_resource ||= atts.delete(:resource)
45
- effective_resource ||= controller.class.effective_resource if controller.class.respond_to?(:effective_resource)
46
- effective_resource ||= Effective::Resource.new(controller_path)
47
- raise 'Expected resource: value to be an Effective::Resource instance' unless effective_resource.kind_of?(Effective::Resource)
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
- namespace ||= effective_resource.namespace.to_sym if effective_resource.namespace
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 = effective_resource.resource_actions - atts.reject { |_, v| v }.keys + atts.select { |_, v| v }.keys
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: resource, effective_resource: effective_resource, namespace: namespace, actions: actions }
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
- raise 'expected attributes to be a Hash. Try passing action: action if rendering custom action' unless atts.kind_of?(Hash)
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.present?), resource.name.to_sym => instance_variable_get('@' + resource.name)}.compact.merge(atts)
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]) + member_actions
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
@@ -1,7 +1,7 @@
1
1
  module Effective
2
2
  module Resources
3
3
  module Instance
4
- attr_reader :instance
4
+ attr_accessor :instance
5
5
 
6
6
  # This is written for use by effective_logging and effective_trash
7
7
 
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '0.8.25'.freeze
2
+ VERSION = '0.8.26'.freeze
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: effective_resources
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.25
4
+ version: 0.8.26
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect