pundit-plus 0.1.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 +7 -0
- data/CHANGELOG.md +8 -0
- data/LICENSE +21 -0
- data/README.md +56 -0
- data/Rakefile +8 -0
- data/lib/pundit/plus/custom_exception.rb +24 -0
- data/lib/pundit/plus/version.rb +7 -0
- data/lib/pundit/plus.rb +12 -0
- metadata +81 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 6e24b7b92951d89eacea12daeb0883a4210e1f900d3dd472fd069119f197a978
|
4
|
+
data.tar.gz: 2de203579d764e39b71c72c3bc3dc0c13138ae7d97d87f0b0676ee0925156fd7
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: f6fa345e74e3a2dd1a3756782226fab68a0d1e005f9f993b0273132c18648fe8616c938a2fce78df2ed3d26b3744fe42e08a7ff80876ad3ca0e755f3e9ab3a80
|
7
|
+
data.tar.gz: 29c5545f4294059194b327dbbc7f3b8ff81463e97dcfcc767a30d053ed29e782d7c53bdfe9a67f69e9ed92a4790ec59ebe432510eaff2d62a5b34aafdee7a13e
|
data/CHANGELOG.md
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) 2024 SOFware LLC
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
# Pundit::Plus
|
2
|
+
|
3
|
+
Add some extra features to Pundit.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Install the gem and add to the application's Gemfile by executing:
|
8
|
+
|
9
|
+
$ bundle add pundit-plus
|
10
|
+
|
11
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
12
|
+
|
13
|
+
$ gem install pundit-plus
|
14
|
+
|
15
|
+
## Usage
|
16
|
+
|
17
|
+
This includes [Pundit](https://github.com/varvet/pundit) and [Pundit Matchers](https://github.com/pundit-community/pundit-matchers).
|
18
|
+
|
19
|
+
Follow the instructions for using Pundit and Pundit Matchers.
|
20
|
+
|
21
|
+
Include the `Pundit::Plus` module in your policy classes to add extra features to Pundit. For example:
|
22
|
+
|
23
|
+
```ruby
|
24
|
+
class ApplicationPolicy
|
25
|
+
include Pundit::Plus
|
26
|
+
# this module defines the default exception_from behavior
|
27
|
+
end
|
28
|
+
|
29
|
+
class MyPolicy < ApplicationPolicy
|
30
|
+
# Then you can use your own exception classes
|
31
|
+
class CustomException < Pundit::NotAuthorizedError
|
32
|
+
def initialize(options = {})
|
33
|
+
options[:message] ||= "You are not authorized to perform this action."
|
34
|
+
super(options)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def exeception_from(query:)
|
39
|
+
if query == :show?
|
40
|
+
CustomException
|
41
|
+
else
|
42
|
+
super
|
43
|
+
end
|
44
|
+
end
|
45
|
+
end
|
46
|
+
```
|
47
|
+
|
48
|
+
## Development
|
49
|
+
|
50
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake test` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
51
|
+
|
52
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
53
|
+
|
54
|
+
## Contributing
|
55
|
+
|
56
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/SOFware/pundit-plus.
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "pundit"
|
4
|
+
|
5
|
+
module Pundit
|
6
|
+
module Plus
|
7
|
+
# This module is prepended to Pundit to allow for custom exceptions to be
|
8
|
+
# raised by policies.
|
9
|
+
module CustomException
|
10
|
+
# This method is called by Pundit when a policy raises an exception.
|
11
|
+
#
|
12
|
+
# The default implementation raises the exception that was passed to
|
13
|
+
# `authorize`, but you can override this method in your policy classes to
|
14
|
+
# handle the exception differently.
|
15
|
+
#
|
16
|
+
# To make use of this method define the `exception_from` method in your
|
17
|
+
# policy class.
|
18
|
+
def raise(klass, query:, record:, policy:)
|
19
|
+
super(policy.exception_from(query:), query: query, record: record, policy: policy)
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
Pundit.singleton_class.prepend(Pundit::Plus::CustomException)
|
data/lib/pundit/plus.rb
ADDED
metadata
ADDED
@@ -0,0 +1,81 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: pundit-plus
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Jim Gay
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2024-04-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: pundit
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: pundit-matchers
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
description: Add Pundit to your application with additional features.
|
42
|
+
email:
|
43
|
+
- jim@saturnflyer.com
|
44
|
+
executables: []
|
45
|
+
extensions: []
|
46
|
+
extra_rdoc_files: []
|
47
|
+
files:
|
48
|
+
- CHANGELOG.md
|
49
|
+
- LICENSE
|
50
|
+
- README.md
|
51
|
+
- Rakefile
|
52
|
+
- lib/pundit/plus.rb
|
53
|
+
- lib/pundit/plus/custom_exception.rb
|
54
|
+
- lib/pundit/plus/version.rb
|
55
|
+
homepage: https://github.com/SOFware/pundit-plus
|
56
|
+
licenses:
|
57
|
+
- MIT
|
58
|
+
metadata:
|
59
|
+
homepage_uri: https://github.com/SOFware/pundit-plus
|
60
|
+
source_code_uri: https://github.com/SOFware/pundit-plus
|
61
|
+
changelog_uri: https://github.com/SOFware/pundit-plus/blob/main/CHANGELOG.md
|
62
|
+
post_install_message:
|
63
|
+
rdoc_options: []
|
64
|
+
require_paths:
|
65
|
+
- lib
|
66
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
version: 3.0.0
|
71
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
requirements: []
|
77
|
+
rubygems_version: 3.5.5
|
78
|
+
signing_key:
|
79
|
+
specification_version: 4
|
80
|
+
summary: Pundit with additional features.
|
81
|
+
test_files: []
|