can_can_dry 0.3.1 → 0.5.2

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
  SHA256:
3
- metadata.gz: 3f376cdbeb98a1137714aa74e1e0f9b84de1ecaf6b1d85f8bbcaa1902d6bc610
4
- data.tar.gz: 4e0272959e2e2ba9aebe2d1544884f293222aadb7385f4a3531522845633fb8b
3
+ metadata.gz: 641996c1b0d83e0326372e3d03089e3eab575aac26d24a1231c1584c02da4a6e
4
+ data.tar.gz: 4a3295f1716eedd9fe68f27385dc09f8d0eafb30b5c7858226759059770c0f41
5
5
  SHA512:
6
- metadata.gz: 525ecb1249278e808dab39fa4634a83f3ac78d9ed9aaf9537a1666627ba05f3a84c88af784093a6d0012da43e90adf8e28daf12738b486b5f1365b0a0bc9bc60
7
- data.tar.gz: 55d148c30ab64a8465967f01e2e5d35d50cbc600348b62d5721cc63436631a16966b243ce6a6ca6a49e407e53cf263910ede7494ff973b620975eec9d5746e3a
6
+ metadata.gz: cadf863b92f82dd6b51b3f2d5077fe19a3e53377b1a302bbbcc4c6689be0254598b56dfb3819f9c306f0cc6bae7bd39df0f3666012f735bb87a629fb3184c5e4
7
+ data.tar.gz: 9854af3fec63e520d5cfb9748a9cd06567e6b79049d19293f1eb68973fe2e3b0f2a43ffa5a8224a0e5c67efdf68d9ebc4d0b800bf2c389a89fdf8b09cc3490d2
@@ -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
data/lib/can_can_dry.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'active_support/dependencies'
2
4
  require 'cancancan'
3
5
 
@@ -10,10 +12,7 @@ module CanCanDry
10
12
  require_dependency 'can_can_dry/ability_mapping'
11
13
  require_dependency 'can_can_dry/ability_mapping/path_mapping_not_found'
12
14
  require_dependency 'can_can_dry/ability_mapping/action_mapping_not_found'
13
- require_dependency 'can_can_dry/helpers/can_can_dry_helper'
15
+ require_dependency 'can_can_dry/engine'
14
16
  require_dependency 'can_can_dry/no_controller_can_can_additions'
15
17
  require_dependency 'can_can_dry/path_recognizer'
16
-
17
- require_dependency 'action_view'
18
- ActionView::Base.send :include, CanCanDry::Helpers::CanCanDryHelper
19
18
  end
@@ -1,11 +1,15 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
1
5
  module CanCanDry
2
6
  module AbilityMapping
3
7
  RESOURCES_ACTION_MAPPING = {
4
- read: %w(index show),
5
- create: %w(new create),
6
- update: %w(update edit),
7
- destroy: %w(destroy)
8
- }
8
+ read: %w[index show],
9
+ create: %w[new create],
10
+ update: %w[update edit],
11
+ destroy: %w[destroy]
12
+ }.freeze
9
13
  ALL_ACTION = 'ALL'
10
14
 
11
15
  def mapping
@@ -38,6 +42,7 @@ module CanCanDry
38
42
  if can_args.count == 1
39
43
  raise "\"can_args\" deve ter 0 ou 2 ou mais elementos (can_args.count=#{can_args.count})"
40
44
  end
45
+
41
46
  mapping[controller] ||= {}
42
47
  mapping[controller][action] ||= []
43
48
  mapping[controller][action] << can_args
@@ -45,8 +50,8 @@ module CanCanDry
45
50
 
46
51
  def can_args_by_path(root_path, path, method)
47
52
  can_args_by_path_hash(recognize_path(root_path, path, method))
48
- rescue ActionMappingNotFound => ex
49
- raise PathMappingNotFound.new(path, method, ex)
53
+ rescue ActionMappingNotFound => e
54
+ raise PathMappingNotFound.new(path, method, e)
50
55
  end
51
56
 
52
57
  def can_args_by_path_hash(path_hash)
@@ -59,7 +64,7 @@ module CanCanDry
59
64
  def replace_model_by_record(can_args_args, id)
60
65
  can_args_args.map do |can_args|
61
66
  ca = can_args.dup
62
- ca[1] = ca[1].find_by_id(id) if id && ca[1].respond_to?(:find_by_id)
67
+ ca[1] = ca[1].find_by(id: id) if id && ca[1].respond_to?(:find_by_id)
63
68
  ca
64
69
  end
65
70
  end
@@ -70,15 +75,47 @@ module CanCanDry
70
75
  end
71
76
 
72
77
  def find_can_args_list(controller, action)
73
- controller = ActiveSupport::Inflector.camelize(controller)
74
- raise ActionMappingNotFound.new(controller, action) unless mapping[controller]
75
- return mapping[controller][action] if mapping[controller][action]
76
- return mapping[controller][ALL_ACTION] if mapping[controller][ALL_ACTION]
77
- raise ActionMappingNotFound.new(controller, action)
78
+ FindCanArgsList.new(mapping, controller, action).find
78
79
  end
79
80
 
80
81
  def recognize_path(root_path, path, method)
81
82
  ::CanCanDry::PathRecognizer.recognize(root_path, path, method: method)
82
83
  end
84
+
85
+ class FindCanArgsList
86
+ ALL_ACTION = ::CanCanDry::AbilityMapping::ALL_ACTION
87
+ common_constructor :mapping, :controller, :action
88
+
89
+ set_callback :initialize, :after do
90
+ @controller = ::ActiveSupport::Inflector.camelize(controller)
91
+ end
92
+
93
+ def find
94
+ validate
95
+ find_by_action || find_by_all_action || raise_mapping_not_found
96
+ end
97
+
98
+ private
99
+
100
+ def find_by_action
101
+ return mapping[controller][action] if mapping[controller][action]
102
+ end
103
+
104
+ def find_by_all_action
105
+ return mapping[controller][ALL_ACTION] if mapping[controller][ALL_ACTION]
106
+ end
107
+
108
+ def mapping_has_controller?
109
+ mapping[controller]
110
+ end
111
+
112
+ def raise_mapping_not_found
113
+ raise(ActionMappingNotFound.new(controller, action))
114
+ end
115
+
116
+ def validate
117
+ raise ActionMappingNotFound.new(controller, action) unless mapping_has_controller?
118
+ end
119
+ end
83
120
  end
84
121
  end
@@ -1,6 +1,8 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CanCanDry
2
4
  module AbilityMapping
3
- class ActionMappingNotFound < Exception
5
+ class ActionMappingNotFound < RuntimeError
4
6
  def initialize(controller, action)
5
7
  super('Nenhum mapeamento de controle de acesso encontrado ' \
6
8
  "para a action \"#{controller}##{action}\"")
@@ -1,8 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CanCanDry
2
4
  module AbilityMapping
3
- class PathMappingNotFound < Exception
4
- def initialize(path, method, ex)
5
- super("Falha ao tentar recuperar mapeamento \"#{path}\", método=#{method}: #{ex}")
5
+ class PathMappingNotFound < RuntimeError
6
+ def initialize(path, method, error)
7
+ super("Falha ao tentar recuperar mapeamento \"#{path}\", método=#{method}: #{error}")
6
8
  end
7
9
  end
8
10
  end
@@ -1,12 +1,13 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module CanCanDry
3
4
  module AbilityMappingSets
4
5
  module ActiveScaffold
5
6
  ACTIVE_SCAFFOLD_MAPPING = {
6
- read: [:browse, :index, :mark, :render_field, :show, :show_search],
7
- create: [:create, :new],
8
- update: [:add_existing, :edit, :edit_associated, :new_existing, :update, :update_column],
9
- destroy: [:destroy, :destroy_existing]
7
+ read: %i[browse index mark render_field show show_search],
8
+ create: %i[create new],
9
+ update: %i[add_existing edit edit_associated new_existing update update_column],
10
+ destroy: %i[destroy destroy_existing]
10
11
  }.freeze
11
12
 
12
13
  def map_active_scaffold(controller, entity)
@@ -1,9 +1,15 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CanCanDry
2
4
  module AbilityMappingSets
3
5
  module Devise
4
6
  def map_devise
7
+ map_resources 'Devise::Confirmation'
8
+ map_resources 'Devise::OmniauthCallback'
9
+ map_resources 'Devise::Registration'
5
10
  map_resources 'Devise::Session'
6
11
  map_resources 'Devise::Password'
12
+ map_resources 'Devise::Unlock'
7
13
  end
8
14
  end
9
15
  end
@@ -1,7 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CanCanDry
2
4
  module AbilityMappingSets
3
5
  module DeviseInvitable
4
6
  def map_devise_invitable
7
+ map_resources 'Devise::Invitations'
5
8
  map_resources 'DeviseInvitable::Registration'
6
9
  end
7
10
  end
@@ -1,18 +1,22 @@
1
- require_dependency 'can_can_dry/helpers/can_can_dry_helper'
1
+ # frozen_string_literal: true
2
2
 
3
3
  module CanCanDry
4
4
  module ControllerAuthorization
5
- include CanCanDry::Helpers::CanCanDryHelper
5
+ extend ::ActiveSupport::Concern
6
+
7
+ included do
8
+ include ::CanCanDryHelper
9
+ end
6
10
 
7
11
  def authorize_by_ability_mapping
8
- fail CanCan::AccessDenied, "Falhou ao tentar acessar #{path_hash}" unless
12
+ raise CanCan::AccessDenied, "Falhou ao tentar acessar #{path_hash}" unless
9
13
  can_by_path_hash?(path_hash)
10
14
  end
11
15
 
12
16
  private
13
17
 
14
18
  def path_hash
15
- params.select { |k, _v| %w(controller action id).include?(k) }
19
+ params.select { |k, _v| %w[controller action id].include?(k) }
16
20
  end
17
21
 
18
22
  def ability_mapping
@@ -0,0 +1,5 @@
1
+ # frozen_string_literal: true
2
+
3
+ module CanCanDry
4
+ class Engine < ::Rails::Engine; end
5
+ end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  module CanCanDry
3
4
  # A substitute for CanCan::ControllerAdditions when no controller is present.
4
5
  module NoControllerCanCanAdditions
@@ -1,51 +1,76 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'eac_ruby_utils/core_ext'
4
+
1
5
  module CanCanDry
2
6
  # Copiado de https://github.com/appirits/awesome_admin_layout
3
7
  # /lib/awesome_admin_layout/recognize_path.rb
4
- module PathRecognizer
8
+ class PathRecognizer
5
9
  class << self
6
10
  def recognize(root_path, path, options = {})
7
- path = remove_root_path(root_path, path)
8
- return Rails.application.routes.recognize_path(path, options)
9
- rescue ActionController::RoutingError
10
- Rails::Engine.subclasses.each do |engine|
11
- recognized_path = engine_recognize(engine, path, options)
12
- return recognized_path if recognized_path
13
- end
14
- raise "Path not recognized: \"#{path}\" (Options: #{options})"
11
+ new(root_path, path, options).recognize_or_raise
15
12
  end
16
13
 
17
- private
18
-
19
14
  def remove_root_path(root_path, path)
20
15
  path = path.gsub(/\A#{Regexp.quote(root_path)}/, '')
21
16
  path.gsub(%r{\A/*}, '/')
22
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
23
31
 
24
- def engine_recognize(engine, path, options)
25
- engine_path = path_for_engine(engine.instance.class, path)
26
- return unless engine_path
27
- begin
28
- return engine.instance.routes.recognize_path(engine_path, options)
29
- rescue ActionController::RoutingError => e
30
- Rails.logger.debug "[#{engine}] ActionController::RoutingError: #{e.message}"
31
- end
32
- nil
32
+ private
33
+
34
+ def core_recognize
35
+ Rails.application.routes.recognize_path(path, options)
36
+ rescue ActionController::RoutingError
37
+ nil
38
+ end
39
+
40
+ def engines_recognize
41
+ Rails::Engine.subclasses.each do |engine|
42
+ recognized_path = engine_recognize(engine)
43
+ return recognized_path if recognized_path
33
44
  end
45
+ nil
46
+ end
47
+
48
+ def engine_recognize(engine)
49
+ engine_path = path_for_engine(engine.instance.class)
50
+ return unless engine_path
34
51
 
35
- def path_for_engine(engine_class, path)
36
- engine_route = Rails.application.routes.routes.find { |r| app_class_for(r) == engine_class }
37
- return unless engine_route
38
- path.gsub(/^#{engine_route.path.spec}/, '')
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}"
39
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
40
66
 
41
- def app_class_for(route)
42
- if Rails.version =~ /\A4\.2\./
43
- # for Rails 4.2
44
- route.app.app
45
- else
46
- # for Rails 4.1, 4.0, 3.2
47
- route.app
48
- 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
49
74
  end
50
75
  end
51
76
  end
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CanCanDry
2
4
  require 'rails'
3
5
 
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module CanCanDry
2
- VERSION = '0.3.1'
4
+ VERSION = '0.5.2'
3
5
  end
@@ -1,4 +1,5 @@
1
1
  # frozen_string_literal: true
2
+
2
3
  namespace :can_can_dry do
3
4
  desc 'Mostra o mapeamento de CanCanDry'
4
5
  task ability_mapping: :environment do
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'can_can_dry/path_recognizer'
4
+
5
+ RSpec.describe ::CanCanDry::PathRecognizer do
6
+ describe '#remove_root_path' do
7
+ [%w[/path/to/action /prefix/ /prefix/path/to/action],
8
+ %w[/path/to/action /prefix /prefix/path/to/action],
9
+ %w[/path / /path],
10
+ ['/path', '', '/path'],
11
+ %w[/unknown/path /abc /unknown/path]].each do |s|
12
+ it do
13
+ expect(described_class.send(:remove_root_path, s[1], s[2])).to eq(s[0])
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,3 @@
1
+ # frozen_string_literal: true
2
+
3
+ ::EacRubyGemSupport::Rspec.default.describe_rubocop
@@ -0,0 +1,103 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file was generated by the `rspec --init` command. Conventionally, all
4
+ # specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
5
+ # The generated `.rspec` file contains `--require spec_helper` which will cause
6
+ # this file to always be loaded, without a need to explicitly require it in any
7
+ # files.
8
+ #
9
+ # Given that it is always loaded, you are encouraged to keep this file as
10
+ # light-weight as possible. Requiring heavyweight dependencies from this file
11
+ # will add to the boot time of your test suite on EVERY test run, even for an
12
+ # individual file that may not need all of that loaded. Instead, consider making
13
+ # a separate helper file that requires the additional dependencies and performs
14
+ # the additional setup, and require it from the spec files that actually need
15
+ # it.
16
+ #
17
+ # See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
18
+ RSpec.configure do |config|
19
+ # rspec-expectations config goes here. You can use an alternate
20
+ # assertion/expectation library such as wrong or the stdlib/minitest
21
+ # assertions if you prefer.
22
+ config.expect_with :rspec do |expectations|
23
+ # This option will default to `true` in RSpec 4. It makes the `description`
24
+ # and `failure_message` of custom matchers include text for helper methods
25
+ # defined using `chain`, e.g.:
26
+ # be_bigger_than(2).and_smaller_than(4).description
27
+ # # => "be bigger than 2 and smaller than 4"
28
+ # ...rather than:
29
+ # # => "be bigger than 2"
30
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
31
+ end
32
+
33
+ # rspec-mocks config goes here. You can use an alternate test double
34
+ # library (such as bogus or mocha) by changing the `mock_with` option here.
35
+ config.mock_with :rspec do |mocks|
36
+ # Prevents you from mocking or stubbing a method that does not exist on
37
+ # a real object. This is generally recommended, and will default to
38
+ # `true` in RSpec 4.
39
+ mocks.verify_partial_doubles = true
40
+ end
41
+
42
+ # This option will default to `:apply_to_host_groups` in RSpec 4 (and will
43
+ # have no way to turn it off -- the option exists only for backwards
44
+ # compatibility in RSpec 3). It causes shared context metadata to be
45
+ # inherited by the metadata hash of host groups and examples, rather than
46
+ # triggering implicit auto-inclusion in groups with matching metadata.
47
+ config.shared_context_metadata_behavior = :apply_to_host_groups
48
+
49
+ # The settings below are suggested to provide a good initial experience
50
+ # with RSpec, but feel free to customize to your heart's content.
51
+ # # This allows you to limit a spec run to individual examples or groups
52
+ # # you care about by tagging them with `:focus` metadata. When nothing
53
+ # # is tagged with `:focus`, all examples get run. RSpec also provides
54
+ # # aliases for `it`, `describe`, and `context` that include `:focus`
55
+ # # metadata: `fit`, `fdescribe` and `fcontext`, respectively.
56
+ # config.filter_run_when_matching :focus
57
+ #
58
+ # # Allows RSpec to persist some state between runs in order to support
59
+ # # the `--only-failures` and `--next-failure` CLI options. We recommend
60
+ # # you configure your source control system to ignore this file.
61
+ # config.example_status_persistence_file_path = "spec/examples.txt"
62
+ #
63
+ # # Limits the available syntax to the non-monkey patched syntax that is
64
+ # # recommended. For more details, see:
65
+ # # - http://rspec.info/blog/2012/06/rspecs-new-expectation-syntax/
66
+ # # - http://www.teaisaweso.me/blog/2013/05/27/rspecs-new-message-expectation-syntax/
67
+ # # - http://rspec.info/blog/2014/05/notable-changes-in-rspec-3/#zero-monkey-patching-mode
68
+ # config.disable_monkey_patching!
69
+ #
70
+ # # This setting enables warnings. It's recommended, but in some cases may
71
+ # # be too noisy due to issues in dependencies.
72
+ # config.warnings = true
73
+ #
74
+ # # Many RSpec users commonly either run the entire suite or an individual
75
+ # # file, and it's useful to allow more verbose output when running an
76
+ # # individual spec file.
77
+ # if config.files_to_run.one?
78
+ # # Use the documentation formatter for detailed output,
79
+ # # unless a formatter has already been configured
80
+ # # (e.g. via a command-line flag).
81
+ # config.default_formatter = "doc"
82
+ # end
83
+ #
84
+ # # Print the 10 slowest examples and example groups at the
85
+ # # end of the spec run, to help surface which specs are running
86
+ # # particularly slow.
87
+ # config.profile_examples = 10
88
+ #
89
+ # # Run specs in random order to surface order dependencies. If you find an
90
+ # # order dependency and want to debug it, you can fix the order by providing
91
+ # # the seed, which is printed after each run.
92
+ # # --seed 1234
93
+ # config.order = :random
94
+ #
95
+ # # Seed global randomization in this process using the `--seed` CLI option.
96
+ # # Setting this allows you to use `--seed` to deterministically reproduce
97
+ # # test failures related to randomization by passing the same `--seed` value
98
+ # # as the one that triggered the failure.
99
+ # Kernel.srand config.seed
100
+
101
+ require 'eac_ruby_gem_support/rspec'
102
+ ::EacRubyGemSupport::Rspec.setup(::File.expand_path('..', __dir__), config)
103
+ end
metadata CHANGED
@@ -1,64 +1,78 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: can_can_dry
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.1
4
+ version: 0.5.2
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-01-18 00:00:00.000000000 Z
11
+ date: 2021-06-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: rails
14
+ name: cancancan
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - ">="
18
18
  - !ruby/object:Gem::Version
19
- version: 4.2.1
19
+ version: 1.13.0
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - ">="
25
25
  - !ruby/object:Gem::Version
26
- version: 4.2.1
26
+ version: 1.13.0
27
27
  - !ruby/object:Gem::Dependency
28
- name: cancancan
28
+ name: eac_ruby_utils
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0.46'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0.46'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rails
29
43
  requirement: !ruby/object:Gem::Requirement
30
44
  requirements:
31
45
  - - ">="
32
46
  - !ruby/object:Gem::Version
33
- version: 1.13.0
47
+ version: 4.2.1
34
48
  type: :runtime
35
49
  prerelease: false
36
50
  version_requirements: !ruby/object:Gem::Requirement
37
51
  requirements:
38
52
  - - ">="
39
53
  - !ruby/object:Gem::Version
40
- version: 1.13.0
54
+ version: 4.2.1
41
55
  - !ruby/object:Gem::Dependency
42
- name: rake
56
+ name: eac_ruby_gem_support
43
57
  requirement: !ruby/object:Gem::Requirement
44
58
  requirements:
45
- - - ">="
59
+ - - "~>"
46
60
  - !ruby/object:Gem::Version
47
- version: 12.1.0
61
+ version: '0.2'
48
62
  type: :development
49
63
  prerelease: false
50
64
  version_requirements: !ruby/object:Gem::Requirement
51
65
  requirements:
52
- - - ">="
66
+ - - "~>"
53
67
  - !ruby/object:Gem::Version
54
- version: 12.1.0
68
+ version: '0.2'
55
69
  description:
56
70
  email:
57
71
  executables: []
58
72
  extensions: []
59
73
  extra_rdoc_files: []
60
74
  files:
61
- - Rakefile
75
+ - app/helpers/can_can_dry_helper.rb
62
76
  - lib/can_can_dry.rb
63
77
  - lib/can_can_dry/ability_mapping.rb
64
78
  - lib/can_can_dry/ability_mapping/action_mapping_not_found.rb
@@ -67,15 +81,15 @@ files:
67
81
  - lib/can_can_dry/ability_mapping_sets/devise.rb
68
82
  - lib/can_can_dry/ability_mapping_sets/devise_invitable.rb
69
83
  - lib/can_can_dry/controller_authorization.rb
70
- - lib/can_can_dry/helpers/can_can_dry_helper.rb
84
+ - lib/can_can_dry/engine.rb
71
85
  - lib/can_can_dry/no_controller_can_can_additions.rb
72
86
  - lib/can_can_dry/path_recognizer.rb
73
87
  - lib/can_can_dry/railtie.rb
74
88
  - lib/can_can_dry/version.rb
75
89
  - lib/tasks/can_can_dry.rake
76
- - test/can_can_dry_test.rb
77
- - test/lib/can_can_dry/path_recognizer_test.rb
78
- - test/test_helper.rb
90
+ - spec/lib/can_can_dry/path_recognizer_spec.rb
91
+ - spec/lib/rubocop_check_spec.rb
92
+ - spec/spec_helper.rb
79
93
  homepage: https://github.com/esquilo-azul/can_can_dry
80
94
  licenses: []
81
95
  metadata:
@@ -95,12 +109,11 @@ required_rubygems_version: !ruby/object:Gem::Requirement
95
109
  - !ruby/object:Gem::Version
96
110
  version: '0'
97
111
  requirements: []
98
- rubyforge_project:
99
- rubygems_version: 2.7.7
112
+ rubygems_version: 3.0.9
100
113
  signing_key:
101
114
  specification_version: 4
102
115
  summary: DRY authorization with CanCanCan.
103
116
  test_files:
104
- - test/test_helper.rb
105
- - test/can_can_dry_test.rb
106
- - test/lib/can_can_dry/path_recognizer_test.rb
117
+ - spec/lib/can_can_dry/path_recognizer_spec.rb
118
+ - spec/lib/rubocop_check_spec.rb
119
+ - spec/spec_helper.rb
data/Rakefile DELETED
@@ -1,17 +0,0 @@
1
- begin
2
- require 'bundler/setup'
3
- rescue LoadError
4
- puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
5
- end
6
-
7
- Bundler::GemHelper.install_tasks
8
- require 'rake/testtask'
9
-
10
- Rake::TestTask.new(:test) do |t|
11
- t.libs << 'lib'
12
- t.libs << 'test'
13
- t.pattern = 'test/**/*_test.rb'
14
- t.verbose = false
15
- end
16
-
17
- task default: :test
@@ -1,60 +0,0 @@
1
- module CanCanDry
2
- module Helpers
3
- module CanCanDryHelper
4
- def ability_mapping
5
- @ability_mapping ||= ::AbilityMapping.new
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
- singleton_class.include(::CanCanDry::NoControllerCanCanAdditions)
57
- end
58
- end
59
- end
60
- end
@@ -1,8 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'test_helper'
3
-
4
- class CanCanDryTest < ActiveSupport::TestCase
5
- test 'truth' do
6
- assert_kind_of Module, CanCanDry
7
- end
8
- end
@@ -1,16 +0,0 @@
1
- # frozen_string_literal: true
2
- require 'test_helper'
3
-
4
- module CanCanDry
5
- class PathRecognizerTest < ActiveSupport::TestCase
6
- test 'remove_root_path' do
7
- [%w(/path/to/action /prefix/ /prefix/path/to/action),
8
- %w(/path/to/action /prefix /prefix/path/to/action),
9
- %w(/path / /path),
10
- ['/path', '', '/path'],
11
- %w(/unknown/path /abc /unknown/path)].each do |s|
12
- assert_equal s[0], ::CanCanDry::PathRecognizer.send(:remove_root_path, s[1], s[2]), s
13
- end
14
- end
15
- end
16
- end
data/test/test_helper.rb DELETED
@@ -1,4 +0,0 @@
1
- # frozen_string_literal: true
2
- ENV['RAILS_ENV'] = 'test'
3
- require 'minitest/autorun'
4
- require 'can_can_dry'