effective_resources 1.0.10 → 1.0.11

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: 7a0f24509e431df9c6c1c7017e3951baf18506cc
4
- data.tar.gz: d3c1ddd4c2c34258b1fe0bb50b76b2e9ff375246
3
+ metadata.gz: 9d9ccd3b1483ba66ad4dbdfd40a2b64ee43ec34d
4
+ data.tar.gz: e0717b61c8a8c49e62d9221d8e938ce8f37c2b5c
5
5
  SHA512:
6
- metadata.gz: d81dae7a2bded26d471caab86e6ee59b511464de9a7c7601b52aa4a1534d2acc9b8a1b79047ccd9d755e701b34e730f1e11d94513f391e8f604549c88ab13ab8
7
- data.tar.gz: 29e5c0e785a0b43db262f4993d013b0cf7113302bd5940cc9bfc918521979cf92a5191398550ee7aaef7836da6b7c09ed1eb8658525232a0d6fe7828fdebfffc
6
+ metadata.gz: 1ad00c6cd0e80ec4145f4e1b708d986649b150f5add0f4a47e68dc063456afd4ad55b5ecfc37ed8b5277c3166a88787c821fcaf6065cd4ae7c912be3f335a5d1
7
+ data.tar.gz: 5e8954119d5bba19d2d2bd816e38312691f7916124af6d20659c0bdd37309942e0c19bc9d5e65b379a133b0630c98f7e648da5a964de79b1eda0a0b34e9b792e
@@ -60,20 +60,23 @@ module EffectiveResourcesHelper
60
60
  raise 'expected first argument to be an ActiveRecord::Base object or Array of objects' unless resource.kind_of?(ActiveRecord::Base) || resource.kind_of?(Class) || resource.kind_of?(Array)
61
61
  raise 'expected attributes to be a Hash' unless atts.kind_of?(Hash)
62
62
 
63
- btn_class = atts.delete(:btn_class)
64
- locals = atts.delete(:locals) || {}
65
- partial = atts.delete(:partial)
66
- spacer_template = locals.delete(:spacer_template)
67
-
68
- effective_resource = (atts.delete(:effective_resource) || find_effective_resource)
69
- namespace = atts.delete(:namespace) || (effective_resource.namespace.to_sym if effective_resource.namespace)
70
-
71
- actions = atts.delete(:actions)
72
- actions ||= (resource.kind_of?(Class) ? effective_resource.resource_klass_actions : effective_resource.resource_actions)
63
+ btn_class = atts[:btn_class]
64
+ locals = atts[:locals] || {}
65
+ partial = atts[:partial]
66
+ spacer_template = locals[:spacer_template]
67
+
68
+ effective_resource = (atts[:effective_resource] || find_effective_resource)
69
+ namespace = atts[:namespace] || (effective_resource.namespace.to_sym if effective_resource.namespace)
70
+
71
+ # Assign actions
72
+ actions = if atts.key?(:actions) # We filter out any actions passed to us that aren't supported
73
+ available = effective_resource.actions # [:new, :edit, ...]
74
+ atts[:actions].inject({}) { |h, (commit, opts)| h[commit] = opts if available.include?(opts[:action]); h }
75
+ else
76
+ (resource.kind_of?(Class) ? effective_resource.resource_klass_actions : effective_resource.resource_actions)
77
+ end
73
78
 
74
- # Filter Actions
75
- action_keys = effective_resource.actions
76
- raise "unknown action for #{effective_resource.name}: #{(atts.keys - action_keys).join(' ')}." if (atts.keys - action_keys).present?
79
+ # Filter out false and proc false
77
80
  actions = actions.select { |_, v| atts[v[:action]].respond_to?(:call) ? instance_exec(&atts[v[:action]]) : (atts[v[:action]] != false) }
78
81
 
79
82
  # Select Partial
@@ -1,3 +1,3 @@
1
1
  module EffectiveResources
2
- VERSION = '1.0.10'.freeze
2
+ VERSION = '1.0.11'.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: 1.0.10
4
+ version: 1.0.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Code and Effect