can_can_dry 0.4.1 → 0.5.0

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
  SHA256:
3
- metadata.gz: f6d616a9b6ad397897fac85697703891c64d112c1f35d1a0dccd1440d1ef104a
4
- data.tar.gz: f0ee05bb9187e61f33137e0b3ae8b86c5a9b262ed02cbf31afd02587814afaec
3
+ metadata.gz: 3bf8f9e250599a1c4ab7da0ca8f4bfc8ea294f8ff8d6399ba113e4b93400aa3c
4
+ data.tar.gz: 4ea554e0a534db616f0bfc1b544d5624ec7bbe163d2471f7d0217aefd136f211
5
5
  SHA512:
6
- metadata.gz: '0170885cc2ebe41ba704a6a47a3b9f4dc4e7281f2591defe4460981169abe4176f1f244041c41df44ec054eebb9af4775885cc1fbf62b6f2bcb546b7ffab667d'
7
- data.tar.gz: 4845274bc917347ce95087f940d8e154ec928f5062a7e2f488d254406d581c220b30a13bc218ad914e85ad7b3e75fad3384f40a1c06d8adba91f1389d9f16d4a
6
+ metadata.gz: 39f056216e6f56005d170b8d8fda89bc02bf4dc101527631f7969c178417d8da8f52583d97cffffe6cdd16ceb8e5538e53f16def4223b186c5a1c8e57bf01c39
7
+ data.tar.gz: 64f39a8c9c27ca887a0113418d9fcb71757b38fdc13cae2300ec75eefbea57efba4580ab6ee47b362487043407eff22ef7b5cedf6501a09be37bb3392aa28940
@@ -0,0 +1,59 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CanCanDryHelper
4
+ def ability_mapping
5
+ @ability_mapping ||= ::AbilityMapping.new # rubocop:disable Rails/HelperInstanceVariable
6
+ end
7
+
8
+ def can_by_path?(path, method = :get)
9
+ can_by_can_args(ability_mapping.can_args_by_path(main_app.root_path, path, method))
10
+ end
11
+
12
+ def can_by_path_hash?(path_hash)
13
+ can_by_can_args(ability_mapping.can_args_by_path_hash(path_hash))
14
+ end
15
+
16
+ def link_or_text(name = nil, options = nil, html_options = nil)
17
+ link_or_default(name, name, options, html_options)
18
+ end
19
+
20
+ def link_or_nil(name = nil, options = nil, html_options = nil)
21
+ link_or_default(name, nil, options, html_options)
22
+ end
23
+
24
+ private
25
+
26
+ def link_or_default(name, default, options, html_options)
27
+ if can_by_link_options?(options, html_options)
28
+ link_to(name, options, html_options)
29
+ else
30
+ default
31
+ end
32
+ end
33
+
34
+ def can_by_link_options?(options, html_options)
35
+ can_by_path?(url_for(options), link_method(options, html_options))
36
+ end
37
+
38
+ def link_method(*hashs)
39
+ hashs.each do |h|
40
+ return h[:method] if h.is_a?(Hash) && h[:method]
41
+ end
42
+ :get
43
+ end
44
+
45
+ def can_by_can_args(can_args_args)
46
+ assert_can_method
47
+ can_args_args.each do |c|
48
+ next if c.empty?
49
+ return true if can?(*c)
50
+ end
51
+ false
52
+ end
53
+
54
+ def assert_can_method
55
+ return if respond_to?('can?')
56
+
57
+ singleton_class.include(::CanCanDry::NoControllerCanCanAdditions)
58
+ end
59
+ end
@@ -12,10 +12,7 @@ module CanCanDry
12
12
  require_dependency 'can_can_dry/ability_mapping'
13
13
  require_dependency 'can_can_dry/ability_mapping/path_mapping_not_found'
14
14
  require_dependency 'can_can_dry/ability_mapping/action_mapping_not_found'
15
- require_dependency 'can_can_dry/helpers/can_can_dry_helper'
15
+ require_dependency 'can_can_dry/engine'
16
16
  require_dependency 'can_can_dry/no_controller_can_can_additions'
17
17
  require_dependency 'can_can_dry/path_recognizer'
18
-
19
- require_dependency 'action_view'
20
- ActionView::Base.include CanCanDry::Helpers::CanCanDryHelper
21
18
  end
@@ -4,8 +4,12 @@ module CanCanDry
4
4
  module AbilityMappingSets
5
5
  module Devise
6
6
  def map_devise
7
+ map_resources 'Devise::Confirmation'
8
+ map_resources 'Devise::OmniauthCallback'
9
+ map_resources 'Devise::Registration'
7
10
  map_resources 'Devise::Session'
8
11
  map_resources 'Devise::Password'
12
+ map_resources 'Devise::Unlock'
9
13
  end
10
14
  end
11
15
  end
@@ -4,6 +4,7 @@ module CanCanDry
4
4
  module AbilityMappingSets
5
5
  module DeviseInvitable
6
6
  def map_devise_invitable
7
+ map_resources 'Devise::Invitations'
7
8
  map_resources 'DeviseInvitable::Registration'
8
9
  end
9
10
  end
@@ -1,10 +1,12 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_dependency 'can_can_dry/helpers/can_can_dry_helper'
4
-
5
3
  module CanCanDry
6
4
  module ControllerAuthorization
7
- include CanCanDry::Helpers::CanCanDryHelper
5
+ extend ::ActiveSupport::Concern
6
+
7
+ included do
8
+ include ::CanCanDryHelper
9
+ end
8
10
 
9
11
  def authorize_by_ability_mapping
10
12
  raise CanCan::AccessDenied, "Falhou ao tentar acessar #{path_hash}" unless
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CanCanDry
4
+ class Engine < ::Rails::Engine; end
5
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module CanCanDry
4
- VERSION = '0.4.1'
4
+ VERSION = '0.5.0'
5
5
  end
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.4.1
4
+ version: 0.5.0
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-22 00:00:00.000000000 Z
11
+ date: 2020-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: cancancan
@@ -72,6 +72,7 @@ executables: []
72
72
  extensions: []
73
73
  extra_rdoc_files: []
74
74
  files:
75
+ - app/helpers/can_can_dry_helper.rb
75
76
  - lib/can_can_dry.rb
76
77
  - lib/can_can_dry/ability_mapping.rb
77
78
  - lib/can_can_dry/ability_mapping/action_mapping_not_found.rb
@@ -80,7 +81,7 @@ files:
80
81
  - lib/can_can_dry/ability_mapping_sets/devise.rb
81
82
  - lib/can_can_dry/ability_mapping_sets/devise_invitable.rb
82
83
  - lib/can_can_dry/controller_authorization.rb
83
- - lib/can_can_dry/helpers/can_can_dry_helper.rb
84
+ - lib/can_can_dry/engine.rb
84
85
  - lib/can_can_dry/no_controller_can_can_additions.rb
85
86
  - lib/can_can_dry/path_recognizer.rb
86
87
  - lib/can_can_dry/railtie.rb
@@ -1,63 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- module CanCanDry
4
- module Helpers
5
- module CanCanDryHelper
6
- def ability_mapping
7
- @ability_mapping ||= ::AbilityMapping.new
8
- end
9
-
10
- def can_by_path?(path, method = :get)
11
- can_by_can_args(ability_mapping.can_args_by_path(main_app.root_path, path, method))
12
- end
13
-
14
- def can_by_path_hash?(path_hash)
15
- can_by_can_args(ability_mapping.can_args_by_path_hash(path_hash))
16
- end
17
-
18
- def link_or_text(name = nil, options = nil, html_options = nil)
19
- link_or_default(name, name, options, html_options)
20
- end
21
-
22
- def link_or_nil(name = nil, options = nil, html_options = nil)
23
- link_or_default(name, nil, options, html_options)
24
- end
25
-
26
- private
27
-
28
- def link_or_default(name, default, options, html_options)
29
- if can_by_link_options?(options, html_options)
30
- link_to(name, options, html_options)
31
- else
32
- default
33
- end
34
- end
35
-
36
- def can_by_link_options?(options, html_options)
37
- can_by_path?(url_for(options), link_method(options, html_options))
38
- end
39
-
40
- def link_method(*hashs)
41
- hashs.each do |h|
42
- return h[:method] if h.is_a?(Hash) && h[:method]
43
- end
44
- :get
45
- end
46
-
47
- def can_by_can_args(can_args_args)
48
- assert_can_method
49
- can_args_args.each do |c|
50
- next if c.empty?
51
- return true if can?(*c)
52
- end
53
- false
54
- end
55
-
56
- def assert_can_method
57
- return if respond_to?('can?')
58
-
59
- singleton_class.include(::CanCanDry::NoControllerCanCanAdditions)
60
- end
61
- end
62
- end
63
- end