light-services 0.6.2 → 2.0.0.rc2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/config/rubocop_linter_action.yml +4 -0
- data/.github/workflows/ci.yml +63 -0
- data/.gitignore +11 -4
- data/.rspec +1 -0
- data/.rubocop.yml +22 -8
- data/CHANGELOG.md +1 -0
- data/CODE_OF_CONDUCT.md +55 -30
- data/Gemfile +16 -2
- data/Gemfile.lock +101 -0
- data/LICENSE.txt +1 -1
- data/README.md +3 -149
- data/Rakefile +2 -2
- data/bin/console +4 -4
- data/lib/light/services.rb +4 -7
- data/lib/light/services/base.rb +142 -30
- data/lib/light/services/base_with_context.rb +33 -0
- data/lib/light/services/class_based_collection/base.rb +88 -0
- data/lib/light/services/class_based_collection/mount.rb +33 -0
- data/lib/light/services/collection/arguments.rb +34 -0
- data/lib/light/services/collection/base.rb +47 -0
- data/lib/light/services/collection/outputs.rb +16 -0
- data/lib/light/services/config.rb +63 -0
- data/lib/light/services/exceptions.rb +3 -2
- data/lib/light/services/messages.rb +68 -44
- data/lib/light/services/settings/argument.rb +50 -0
- data/lib/light/services/settings/output.rb +34 -0
- data/lib/light/services/settings/step.rb +71 -0
- data/lib/light/services/version.rb +1 -1
- data/light-services.gemspec +21 -24
- metadata +28 -129
- data/.codeclimate.yml +0 -18
- data/.ruby-gemset +0 -1
- data/.ruby-version +0 -1
- data/.travis.yml +0 -36
- data/Appraisals +0 -25
- data/gemfiles/rails_4_0.gemfile +0 -7
- data/gemfiles/rails_4_0.gemfile.lock +0 -115
- data/gemfiles/rails_4_1.gemfile +0 -7
- data/gemfiles/rails_4_1.gemfile.lock +0 -118
- data/gemfiles/rails_4_2.gemfile +0 -7
- data/gemfiles/rails_4_2.gemfile.lock +0 -144
- data/gemfiles/rails_5_0.gemfile +0 -7
- data/gemfiles/rails_5_0.gemfile.lock +0 -151
- data/gemfiles/rails_5_1.gemfile +0 -7
- data/gemfiles/rails_5_1.gemfile.lock +0 -151
- data/gemfiles/rails_5_2.gemfile +0 -7
- data/gemfiles/rails_5_2.gemfile.lock +0 -159
- data/lib/light/services/callbacks.rb +0 -54
- data/lib/light/services/outputs.rb +0 -70
- data/lib/light/services/parameters.rb +0 -96
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 87f3143772cbfb27b9714d3d92542d07fb949e3ee99213f8e6674e70e3aed4a2
|
4
|
+
data.tar.gz: 0f5443f6e200c0421c9c176610c7068d7dde55b9d23799ed6713411c04c83088
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2c6adacbe7c8e00c5dc5891a65d86644cdc583805966f3792528aa802540f8e9c81333a3d72cbe8d55383a05799e33a804881ed6554d9d3e695e9c2192fc725c
|
7
|
+
data.tar.gz: 2f672d7d41608a9b6f19fa8368c1774f82e7f98075df042efcc15a502f60fd4498eac4b02190615aeba01dcd8e3ad930d38799ec2741ae250382b37d46d153b9
|
@@ -0,0 +1,63 @@
|
|
1
|
+
name: CI
|
2
|
+
on: push
|
3
|
+
|
4
|
+
jobs:
|
5
|
+
rubocop:
|
6
|
+
name: Rubocop
|
7
|
+
runs-on: ubuntu-latest
|
8
|
+
steps:
|
9
|
+
- name: Git Checkout
|
10
|
+
uses: actions/checkout@v2
|
11
|
+
|
12
|
+
- name: Rubocop
|
13
|
+
uses: andrewmcodes/rubocop-linter-action@v3.2.0
|
14
|
+
env:
|
15
|
+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
16
|
+
|
17
|
+
rspec:
|
18
|
+
name: RSpec
|
19
|
+
runs-on: ubuntu-latest
|
20
|
+
strategy:
|
21
|
+
matrix:
|
22
|
+
ruby: [2.5, 2.6, 2.7, head, debug]
|
23
|
+
steps:
|
24
|
+
- name: Git Checkout
|
25
|
+
uses: actions/checkout@v2
|
26
|
+
|
27
|
+
- name: Install dependencies
|
28
|
+
run: sudo apt-get install libsqlite3-dev
|
29
|
+
|
30
|
+
- name: Setup Ruby
|
31
|
+
uses: ruby/setup-ruby@v1.38.0
|
32
|
+
with:
|
33
|
+
ruby-version: ${{ matrix.ruby }}
|
34
|
+
bundler-cache: true
|
35
|
+
|
36
|
+
- name: RSpec
|
37
|
+
run: bundle exec rspec
|
38
|
+
|
39
|
+
codecov:
|
40
|
+
name: Code Coverage
|
41
|
+
runs-on: ubuntu-latest
|
42
|
+
env:
|
43
|
+
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
|
44
|
+
steps:
|
45
|
+
- name: Git Checkout
|
46
|
+
uses: actions/checkout@v2
|
47
|
+
|
48
|
+
- name: Install dependencies
|
49
|
+
run: sudo apt-get install libsqlite3-dev
|
50
|
+
|
51
|
+
- name: Setup Ruby
|
52
|
+
uses: ruby/setup-ruby@v1.38.0
|
53
|
+
with:
|
54
|
+
ruby-version: head
|
55
|
+
bundler-cache: true
|
56
|
+
|
57
|
+
- name: RSpec
|
58
|
+
run: bundle exec rspec
|
59
|
+
|
60
|
+
- name: Code Coverage
|
61
|
+
uses: codecov/codecov-action@v1
|
62
|
+
with:
|
63
|
+
token: ${{ secrets.CODECOV_TOKEN }}
|
data/.gitignore
CHANGED
@@ -1,6 +1,6 @@
|
|
1
|
+
# Common
|
1
2
|
/.bundle/
|
2
3
|
/.yardoc
|
3
|
-
/Gemfile.lock
|
4
4
|
/_yardoc/
|
5
5
|
/coverage/
|
6
6
|
/doc/
|
@@ -8,6 +8,13 @@
|
|
8
8
|
/spec/reports/
|
9
9
|
/tmp/
|
10
10
|
/.idea/
|
11
|
-
|
12
|
-
|
13
|
-
|
11
|
+
|
12
|
+
# RSpec failure tracking
|
13
|
+
.rspec_status
|
14
|
+
|
15
|
+
# Ignore IDE files
|
16
|
+
/.idea
|
17
|
+
*.iml
|
18
|
+
|
19
|
+
# Ignore gem files
|
20
|
+
*.gem
|
data/.rspec
CHANGED
data/.rubocop.yml
CHANGED
@@ -1,16 +1,30 @@
|
|
1
|
+
require:
|
2
|
+
- rubocop-rspec
|
3
|
+
- rubocop-performance
|
4
|
+
|
1
5
|
AllCops:
|
2
|
-
|
6
|
+
NewCops: enable
|
7
|
+
|
8
|
+
Layout/MultilineMethodCallIndentation:
|
9
|
+
EnforcedStyle: indented
|
10
|
+
|
11
|
+
Metrics/BlockLength:
|
12
|
+
Exclude:
|
13
|
+
- spec/**/*_spec.rb
|
14
|
+
|
15
|
+
Security/Eval:
|
16
|
+
Exclude:
|
17
|
+
- spec/light/services/error_spec.rb
|
3
18
|
|
4
19
|
Style/Documentation:
|
5
20
|
Enabled: false
|
6
21
|
|
7
|
-
Style/
|
8
|
-
|
9
|
-
- 'spec/**/*'
|
22
|
+
Style/StringLiterals:
|
23
|
+
EnforcedStyle: double_quotes
|
10
24
|
|
11
|
-
|
12
|
-
|
25
|
+
Style/GuardClause:
|
26
|
+
Enabled: false
|
13
27
|
|
14
|
-
|
28
|
+
Style/ClassAndModuleChildren:
|
15
29
|
Exclude:
|
16
|
-
-
|
30
|
+
- spec/data/services/**/*.rb
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
# Changelog
|
data/CODE_OF_CONDUCT.md
CHANGED
@@ -1,24 +1,41 @@
|
|
1
|
-
# Contributor Code of Conduct
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
2
|
|
3
|
-
|
4
|
-
fostering an open and welcoming community, we pledge to respect all people who
|
5
|
-
contribute through reporting issues, posting feature requests, updating
|
6
|
-
documentation, submitting pull requests or patches, and other activities.
|
3
|
+
## Our Pledge
|
7
4
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
12
22
|
|
13
23
|
Examples of unacceptable behavior by participants include:
|
14
24
|
|
15
|
-
* The use of sexualized language or imagery
|
16
|
-
|
17
|
-
* Trolling
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
18
28
|
* Public or private harassment
|
19
|
-
* Publishing
|
20
|
-
|
21
|
-
* Other
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
22
39
|
|
23
40
|
Project maintainers have the right and responsibility to remove, edit, or
|
24
41
|
reject comments, commits, code, wiki edits, issues, and other contributions
|
@@ -26,24 +43,32 @@ that are not aligned to this Code of Conduct, or to ban temporarily or
|
|
26
43
|
permanently any contributor for other behaviors that they deem inappropriate,
|
27
44
|
threatening, offensive, or harmful.
|
28
45
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
33
54
|
|
34
|
-
|
35
|
-
when an individual is representing the project or its community.
|
55
|
+
## Enforcement
|
36
56
|
|
37
57
|
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
38
|
-
reported by contacting
|
58
|
+
reported by contacting the project team at emelianenko.web@gmail.com. All
|
39
59
|
complaints will be reviewed and investigated and will result in a response that
|
40
|
-
is deemed necessary and appropriate to the circumstances.
|
41
|
-
obligated to maintain confidentiality with regard to the reporter of an
|
42
|
-
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
43
69
|
|
44
|
-
This Code of Conduct is adapted from the [Contributor Covenant][homepage],
|
45
|
-
|
46
|
-
[http://contributor-covenant.org/version/1/3/0/][version]
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [https://contributor-covenant.org/version/1/4][version]
|
47
72
|
|
48
|
-
[homepage]:
|
49
|
-
[version]:
|
73
|
+
[homepage]: https://contributor-covenant.org
|
74
|
+
[version]: https://contributor-covenant.org/version/1/4/
|
data/Gemfile
CHANGED
@@ -1,6 +1,20 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
source
|
3
|
+
source "https://rubygems.org"
|
4
4
|
|
5
|
-
# Specify your gem's dependencies in light-services.gemspec
|
6
5
|
gemspec
|
6
|
+
|
7
|
+
group :test do
|
8
|
+
gem "activerecord", "~> 6.0"
|
9
|
+
gem "database_cleaner-active_record", "~> 1.8"
|
10
|
+
gem "sqlite3", "~> 1.4"
|
11
|
+
|
12
|
+
gem "codecov", "~> 0.1.17"
|
13
|
+
gem "rake", "~> 13.0"
|
14
|
+
gem "rspec", "~> 3.9"
|
15
|
+
gem "simplecov", "~> 0.18"
|
16
|
+
|
17
|
+
gem "rubocop", "~> 0.86", require: false
|
18
|
+
gem "rubocop-performance", "~> 1.6", require: false
|
19
|
+
gem "rubocop-rspec", "~> 1.40", require: false
|
20
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,101 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
light-services (2.0.0.beta1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
activemodel (6.0.3.2)
|
10
|
+
activesupport (= 6.0.3.2)
|
11
|
+
activerecord (6.0.3.2)
|
12
|
+
activemodel (= 6.0.3.2)
|
13
|
+
activesupport (= 6.0.3.2)
|
14
|
+
activesupport (6.0.3.2)
|
15
|
+
concurrent-ruby (~> 1.0, >= 1.0.2)
|
16
|
+
i18n (>= 0.7, < 2)
|
17
|
+
minitest (~> 5.1)
|
18
|
+
tzinfo (~> 1.1)
|
19
|
+
zeitwerk (~> 2.2, >= 2.2.2)
|
20
|
+
ast (2.4.1)
|
21
|
+
codecov (0.1.17)
|
22
|
+
json
|
23
|
+
simplecov
|
24
|
+
url
|
25
|
+
concurrent-ruby (1.1.6)
|
26
|
+
database_cleaner (1.8.5)
|
27
|
+
database_cleaner-active_record (1.8.0)
|
28
|
+
activerecord
|
29
|
+
database_cleaner (~> 1.8.0)
|
30
|
+
diff-lcs (1.4.2)
|
31
|
+
docile (1.3.2)
|
32
|
+
i18n (1.8.3)
|
33
|
+
concurrent-ruby (~> 1.0)
|
34
|
+
json (2.3.0)
|
35
|
+
minitest (5.14.1)
|
36
|
+
parallel (1.19.2)
|
37
|
+
parser (2.7.1.4)
|
38
|
+
ast (~> 2.4.1)
|
39
|
+
rainbow (3.0.0)
|
40
|
+
rake (13.0.1)
|
41
|
+
regexp_parser (1.7.1)
|
42
|
+
rexml (3.2.4)
|
43
|
+
rspec (3.9.0)
|
44
|
+
rspec-core (~> 3.9.0)
|
45
|
+
rspec-expectations (~> 3.9.0)
|
46
|
+
rspec-mocks (~> 3.9.0)
|
47
|
+
rspec-core (3.9.2)
|
48
|
+
rspec-support (~> 3.9.3)
|
49
|
+
rspec-expectations (3.9.2)
|
50
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
51
|
+
rspec-support (~> 3.9.0)
|
52
|
+
rspec-mocks (3.9.1)
|
53
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
54
|
+
rspec-support (~> 3.9.0)
|
55
|
+
rspec-support (3.9.3)
|
56
|
+
rubocop (0.86.0)
|
57
|
+
parallel (~> 1.10)
|
58
|
+
parser (>= 2.7.0.1)
|
59
|
+
rainbow (>= 2.2.2, < 4.0)
|
60
|
+
regexp_parser (>= 1.7)
|
61
|
+
rexml
|
62
|
+
rubocop-ast (>= 0.0.3, < 1.0)
|
63
|
+
ruby-progressbar (~> 1.7)
|
64
|
+
unicode-display_width (>= 1.4.0, < 2.0)
|
65
|
+
rubocop-ast (0.0.3)
|
66
|
+
parser (>= 2.7.0.1)
|
67
|
+
rubocop-performance (1.6.1)
|
68
|
+
rubocop (>= 0.71.0)
|
69
|
+
rubocop-rspec (1.40.0)
|
70
|
+
rubocop (>= 0.68.1)
|
71
|
+
ruby-progressbar (1.10.1)
|
72
|
+
simplecov (0.18.5)
|
73
|
+
docile (~> 1.1)
|
74
|
+
simplecov-html (~> 0.11)
|
75
|
+
simplecov-html (0.12.2)
|
76
|
+
sqlite3 (1.4.2)
|
77
|
+
thread_safe (0.3.6)
|
78
|
+
tzinfo (1.2.7)
|
79
|
+
thread_safe (~> 0.1)
|
80
|
+
unicode-display_width (1.7.0)
|
81
|
+
url (0.3.2)
|
82
|
+
zeitwerk (2.3.1)
|
83
|
+
|
84
|
+
PLATFORMS
|
85
|
+
ruby
|
86
|
+
|
87
|
+
DEPENDENCIES
|
88
|
+
activerecord (~> 6.0)
|
89
|
+
codecov (~> 0.1.17)
|
90
|
+
database_cleaner-active_record (~> 1.8)
|
91
|
+
light-services!
|
92
|
+
rake (~> 13.0)
|
93
|
+
rspec (~> 3.9)
|
94
|
+
rubocop (~> 0.86)
|
95
|
+
rubocop-performance (~> 1.6)
|
96
|
+
rubocop-rspec (~> 1.40)
|
97
|
+
simplecov (~> 0.18)
|
98
|
+
sqlite3 (~> 1.4)
|
99
|
+
|
100
|
+
BUNDLED WITH
|
101
|
+
2.1.4
|
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,150 +1,4 @@
|
|
1
|
-
# Light
|
2
|
-
|
3
|
-
[![
|
4
|
-
[![Code Climate](https://codeclimate.com/github/light-ruby/light-services/badges/gpa.svg)](https://codeclimate.com/github/light-ruby/light-services)
|
5
|
-
[![Test Coverage](https://api.codeclimate.com/v1/badges/ed8713a891f19318bd7c/test_coverage)](https://codeclimate.com/github/light-ruby/light-services/test_coverage)
|
6
|
-
|
7
|
-
Implementation of Service Object Pattern for Ruby/Rails. Compatible with Rails 5.1 and 5.0, 4.2, 4.1, 4.0.
|
8
|
-
|
9
|
-
Service Object Pattern – What is it? Check it here:
|
10
|
-
- [Wikipedia](https://en.wikipedia.org/wiki/Service_layer_pattern)
|
11
|
-
- [Essential RubyOnRails patterns — part 1: Service Objects](https://medium.com/selleo/essential-rubyonrails-patterns-part-1-service-objects-1af9f9573ca1)
|
12
|
-
|
13
|
-
## Installation
|
14
|
-
|
15
|
-
Add this line to your application's Gemfile:
|
16
|
-
|
17
|
-
```ruby
|
18
|
-
gem 'light-services', '~> 0.6'
|
19
|
-
```
|
20
|
-
|
21
|
-
And then execute:
|
22
|
-
|
23
|
-
$ bundle
|
24
|
-
|
25
|
-
Or install it yourself as:
|
26
|
-
|
27
|
-
$ gem install light-service
|
28
|
-
|
29
|
-
## Usage
|
30
|
-
|
31
|
-
#### Examples of usage:
|
32
|
-
|
33
|
-
**Change state of the record:**
|
34
|
-
```ruby
|
35
|
-
class Painting::Publish < ApplicationService
|
36
|
-
# Parameters
|
37
|
-
param :painting, type: Painting
|
38
|
-
param :user, type: User
|
39
|
-
|
40
|
-
# Callbacks
|
41
|
-
before :authorize
|
42
|
-
after :send_email_notification
|
43
|
-
|
44
|
-
def run
|
45
|
-
painting.publish!
|
46
|
-
end
|
47
|
-
|
48
|
-
private
|
49
|
-
|
50
|
-
def authorize
|
51
|
-
pundit_authorize!(painting, user, :publish?)
|
52
|
-
end
|
53
|
-
|
54
|
-
def send_email_notification
|
55
|
-
PaintingMailer.publish_email(painting).deliver_now
|
56
|
-
end
|
57
|
-
end
|
58
|
-
```
|
59
|
-
|
60
|
-
**Create a new record:**
|
61
|
-
```ruby
|
62
|
-
class Owner::Create < ApplicationService
|
63
|
-
# Parameters
|
64
|
-
param :params, type: ActionController::Parameters
|
65
|
-
param :user, type: User
|
66
|
-
|
67
|
-
# Outputs
|
68
|
-
output :owner
|
69
|
-
|
70
|
-
# Callbacks
|
71
|
-
before :assign_attributes
|
72
|
-
before :authorize
|
73
|
-
before :validate
|
74
|
-
|
75
|
-
def run
|
76
|
-
owner.save!
|
77
|
-
end
|
78
|
-
|
79
|
-
private
|
80
|
-
|
81
|
-
def assign_attributes
|
82
|
-
self.owner = Owner.new(owner_params)
|
83
|
-
end
|
84
|
-
|
85
|
-
def authorize
|
86
|
-
pundit_authorize!(owner, user, :create?)
|
87
|
-
end
|
88
|
-
|
89
|
-
def validate
|
90
|
-
return if owner.valid?
|
91
|
-
errors.from_record(owner)
|
92
|
-
end
|
93
|
-
|
94
|
-
def owner_params
|
95
|
-
params
|
96
|
-
.require(:owner)
|
97
|
-
.permit(:name)
|
98
|
-
end
|
99
|
-
end
|
100
|
-
```
|
101
|
-
|
102
|
-
**Integration with Pundit:**
|
103
|
-
```ruby
|
104
|
-
class ApplicationService < Light::Services::Base
|
105
|
-
def pundit_authorize!(record, user, action = nil)
|
106
|
-
action = convert_action(action, :show?)
|
107
|
-
policy = Pundit.policy!(user, record)
|
108
|
-
|
109
|
-
return true if policy.public_send(action)
|
110
|
-
|
111
|
-
Rails.logger.info "Pundit: not allowed to #{action} this #{record.inspect}"
|
112
|
-
raise Pundit::NotAuthorizedError, query: action, policy: policy, record: record
|
113
|
-
end
|
114
|
-
|
115
|
-
def pundit_scope!(scope, user, action = nil)
|
116
|
-
action = convert_action(action, :index?)
|
117
|
-
pundit_authorize!(scope, user, action)
|
118
|
-
|
119
|
-
Pundit.policy_scope!(user, scope)
|
120
|
-
end
|
121
|
-
|
122
|
-
private
|
123
|
-
|
124
|
-
def convert_action(action, default)
|
125
|
-
action = action.to_s
|
126
|
-
|
127
|
-
return default if action.blank?
|
128
|
-
return action if action.ends_with?('?')
|
129
|
-
|
130
|
-
action + '?'
|
131
|
-
end
|
132
|
-
end
|
133
|
-
|
134
|
-
```
|
135
|
-
|
136
|
-
## Development
|
137
|
-
|
138
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
139
|
-
|
140
|
-
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 tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
141
|
-
|
142
|
-
## Contributing
|
143
|
-
|
144
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/[USERNAME]/light-service. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.
|
145
|
-
|
146
|
-
|
147
|
-
## License
|
148
|
-
|
149
|
-
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
1
|
+
# Light Services
|
2
|
+
![CI](https://github.com/light-ruby/light-services/workflows/CI/badge.svg)
|
3
|
+
[![Codecov](https://codecov.io/gh/light-ruby/light-services/branch/master/graph/badge.svg)](https://codecov.io/gh/light-ruby/light-services)
|
150
4
|
|