effective_resources 1.7.6 → 1.7.7
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/lib/effective_resources.rb +8 -11
- data/lib/effective_resources/effective_gem.rb +42 -0
- data/lib/effective_resources/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 43a2e065a385451ee58c4cf054e18ffb3b2d67618aef4c6e3a417b221b7a6839
|
4
|
+
data.tar.gz: fa379b94d613fa510aa5261c44877a344dfff0ac6de0202a64c90d692b9157aa
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0ed3d10e90f30f5a7b4dd9d837fe21ca6d07c557850d1931ec97c839fbb39a78e11fa795331af247cc5fa929fccdf5aec3f6f05dfd8b68d35e3e0682de0c732
|
7
|
+
data.tar.gz: 53d62815fc3e7fa7718fa1094b7fcb721d772631b1ec1899a9ad7a4f601705091b9efba194b59c4ebead8f0a260b9791b0b83cce9d4962a523361abe46697ef0
|
data/lib/effective_resources.rb
CHANGED
@@ -1,25 +1,24 @@
|
|
1
1
|
require 'effective_resources/engine'
|
2
2
|
require 'effective_resources/version'
|
3
|
+
require 'effective_resources/effective_gem'
|
3
4
|
|
4
5
|
module EffectiveResources
|
5
6
|
|
6
|
-
|
7
|
-
|
8
|
-
mattr_accessor :default_submits
|
9
|
-
|
10
|
-
def self.setup
|
11
|
-
yield self
|
7
|
+
def self.config_keys
|
8
|
+
[:authorization_method, :default_submits]
|
12
9
|
end
|
13
10
|
|
11
|
+
include EffectiveGem
|
12
|
+
|
14
13
|
def self.authorized?(controller, action, resource)
|
15
|
-
@
|
14
|
+
@exceptions ||= [Effective::AccessDenied, (CanCan::AccessDenied if defined?(CanCan)), (Pundit::NotAuthorizedError if defined?(Pundit))].compact
|
16
15
|
|
17
16
|
return !!authorization_method unless authorization_method.respond_to?(:call)
|
18
17
|
controller = controller.controller if controller.respond_to?(:controller)
|
19
18
|
|
20
19
|
begin
|
21
20
|
!!(controller || self).instance_exec((controller || self), action, resource, &authorization_method)
|
22
|
-
rescue *@
|
21
|
+
rescue *@exceptions
|
23
22
|
false
|
24
23
|
end
|
25
24
|
end
|
@@ -29,9 +28,7 @@ module EffectiveResources
|
|
29
28
|
end
|
30
29
|
|
31
30
|
def self.default_submits
|
32
|
-
|
33
|
-
(['Save', 'Continue', 'Add New'] & Array(@@default_submits)).inject({}) { |h, v| h[v] = true; h }
|
34
|
-
end
|
31
|
+
(['Save', 'Continue', 'Add New'] & Array(config.default_submits)).inject({}) { |h, v| h[v] = true; h }
|
35
32
|
end
|
36
33
|
|
37
34
|
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
# Effective Engine concern
|
2
|
+
|
3
|
+
module EffectiveGem
|
4
|
+
extend ActiveSupport::Concern
|
5
|
+
|
6
|
+
included do
|
7
|
+
raise("expected self.config_keys method") unless respond_to?(:config_keys)
|
8
|
+
|
9
|
+
config_keys.each do |key|
|
10
|
+
self.class.define_method(key) { config()[key] }
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
module ClassMethods
|
15
|
+
def config(namespace = nil)
|
16
|
+
namespace ||= Tenant.current if defined?(Tenant)
|
17
|
+
@config.dig(namespace) || @config
|
18
|
+
end
|
19
|
+
|
20
|
+
def setup(namespace = nil, &block)
|
21
|
+
@config ||= ActiveSupport::OrderedOptions.new
|
22
|
+
namespace ||= Tenant.current if defined?(Tenant)
|
23
|
+
|
24
|
+
if namespace
|
25
|
+
@config[namespace] ||= ActiveSupport::OrderedOptions.new
|
26
|
+
end
|
27
|
+
|
28
|
+
yield(config(namespace))
|
29
|
+
|
30
|
+
if(unsupported = (config(namespace).keys - config_keys)).present?
|
31
|
+
if unsupported.include?(:authorization_method)
|
32
|
+
raise("config.authorization_method has been removed. This gem will call EffectiveResources.authorization_method instead. Please double check the config.authorization_method setting in config/initializers/effective_resources.rb and remove it from this file.")
|
33
|
+
end
|
34
|
+
|
35
|
+
raise("unsupported config keys: #{unsupported}\n supported keys: #{config_keys}")
|
36
|
+
end
|
37
|
+
|
38
|
+
true
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: effective_resources
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.7.
|
4
|
+
version: 1.7.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Code and Effect
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-02-
|
11
|
+
date: 2021-02-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -180,6 +180,7 @@ files:
|
|
180
180
|
- app/views/effective/resource/_actions_glyphicons.html.haml
|
181
181
|
- config/effective_resources.rb
|
182
182
|
- lib/effective_resources.rb
|
183
|
+
- lib/effective_resources/effective_gem.rb
|
183
184
|
- lib/effective_resources/engine.rb
|
184
185
|
- lib/effective_resources/version.rb
|
185
186
|
- lib/generators/effective_resources/install_generator.rb
|