can_can_dry 0.5.0 → 0.5.1
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/can_can_dry/path_recognizer.rb +53 -32
- data/lib/can_can_dry/version.rb +1 -1
- metadata +5 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d4815527015549ba0d6cf2f3679ad8d44ac7753b9d34831d9ea7552b900d73fe
|
4
|
+
data.tar.gz: e5dff2e70c55ed2e5eb3240a305861142626795c823bd7088f310f583cf0d1df
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ced8842ccc57776aa32462fc71096e22c0456313cb3d27bd115fb765859ea870ca1766af955bdf885c332928ee91945174da58e7fc261b1906291812114036aa
|
7
|
+
data.tar.gz: ab0814157bf16844ee3ad07a95f694a0e8eea7c15771194fd914b575cbecc9f8fd1442e15fac2614995f41f09c01237c2a0ca4bb1c29bd34c8d041145db05ea4
|
@@ -1,55 +1,76 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
+
require 'eac_ruby_utils/core_ext'
|
4
|
+
|
3
5
|
module CanCanDry
|
4
6
|
# Copiado de https://github.com/appirits/awesome_admin_layout
|
5
7
|
# /lib/awesome_admin_layout/recognize_path.rb
|
6
|
-
|
8
|
+
class PathRecognizer
|
7
9
|
class << self
|
8
10
|
def recognize(root_path, path, options = {})
|
9
|
-
|
10
|
-
Rails.application.routes.recognize_path(path, options)
|
11
|
-
rescue ActionController::RoutingError
|
12
|
-
Rails::Engine.subclasses.each do |engine|
|
13
|
-
recognized_path = engine_recognize(engine, path, options)
|
14
|
-
return recognized_path if recognized_path
|
15
|
-
end
|
16
|
-
raise "Path not recognized: \"#{path}\" (Options: #{options})"
|
11
|
+
new(root_path, path, options).recognize_or_raise
|
17
12
|
end
|
18
13
|
|
19
|
-
private
|
20
|
-
|
21
14
|
def remove_root_path(root_path, path)
|
22
15
|
path = path.gsub(/\A#{Regexp.quote(root_path)}/, '')
|
23
16
|
path.gsub(%r{\A/*}, '/')
|
24
17
|
end
|
18
|
+
end
|
19
|
+
|
20
|
+
common_constructor :root_path, :path, :options do
|
21
|
+
self.path = self.class.remove_root_path(root_path, path)
|
22
|
+
end
|
23
|
+
|
24
|
+
def recognize_or_raise
|
25
|
+
recognize || raise("Path not recognized: \"#{path}\" (Options: #{options})")
|
26
|
+
end
|
27
|
+
|
28
|
+
def recognize
|
29
|
+
core_recognize || engines_recognize
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
25
33
|
|
26
|
-
|
27
|
-
|
28
|
-
|
34
|
+
def core_recognize
|
35
|
+
Rails.application.routes.recognize_path(path, options)
|
36
|
+
rescue ActionController::RoutingError
|
37
|
+
nil
|
38
|
+
end
|
29
39
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
end
|
35
|
-
nil
|
40
|
+
def engines_recognize
|
41
|
+
Rails::Engine.subclasses.each do |engine|
|
42
|
+
recognized_path = engine_recognize(engine)
|
43
|
+
return recognized_path if recognized_path
|
36
44
|
end
|
45
|
+
nil
|
46
|
+
end
|
37
47
|
|
38
|
-
|
39
|
-
|
40
|
-
|
48
|
+
def engine_recognize(engine)
|
49
|
+
engine_path = path_for_engine(engine.instance.class)
|
50
|
+
return unless engine_path
|
41
51
|
|
42
|
-
|
52
|
+
begin
|
53
|
+
return engine.instance.routes.recognize_path(engine_path, options)
|
54
|
+
rescue ActionController::RoutingError => e
|
55
|
+
Rails.logger.debug "[#{engine}] ActionController::RoutingError: #{e.message}"
|
43
56
|
end
|
57
|
+
nil
|
58
|
+
end
|
59
|
+
|
60
|
+
def path_for_engine(engine_class)
|
61
|
+
engine_route = Rails.application.routes.routes.find { |r| app_class_for(r) == engine_class }
|
62
|
+
return unless engine_route
|
63
|
+
|
64
|
+
path.gsub(/^#{engine_route.path.spec}/, '')
|
65
|
+
end
|
44
66
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
end
|
67
|
+
def app_class_for(route)
|
68
|
+
if Rails.version >= '4.2'
|
69
|
+
# for Rails 4.2
|
70
|
+
route.app.app
|
71
|
+
else
|
72
|
+
# for Rails 4.1, 4.0, 3.2
|
73
|
+
route.app
|
53
74
|
end
|
54
75
|
end
|
55
76
|
end
|
data/lib/can_can_dry/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: can_can_dry
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Esquilo Azul Company
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-03
|
11
|
+
date: 2020-10-03 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: cancancan
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
33
|
+
version: '0.46'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
40
|
+
version: '0.46'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rails
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -109,8 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
109
109
|
- !ruby/object:Gem::Version
|
110
110
|
version: '0'
|
111
111
|
requirements: []
|
112
|
-
|
113
|
-
rubygems_version: 2.7.7
|
112
|
+
rubygems_version: 3.0.8
|
114
113
|
signing_key:
|
115
114
|
specification_version: 4
|
116
115
|
summary: DRY authorization with CanCanCan.
|