light-services 0.6.3 → 2.0.0.beta1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.github/config/rubocop_linter_action.yml +4 -0
  3. data/.github/workflows/ci.yml +63 -0
  4. data/.gitignore +3 -4
  5. data/.rspec +1 -0
  6. data/.rubocop.yml +22 -8
  7. data/CHANGELOG.md +1 -0
  8. data/CODE_OF_CONDUCT.md +55 -30
  9. data/Gemfile +16 -2
  10. data/Gemfile.lock +101 -0
  11. data/LICENSE.txt +1 -1
  12. data/README.md +3 -149
  13. data/Rakefile +2 -2
  14. data/bin/console +4 -4
  15. data/lib/light/services.rb +4 -7
  16. data/lib/light/services/base.rb +121 -31
  17. data/lib/light/services/base_with_context.rb +32 -0
  18. data/lib/light/services/class_based_collection/base.rb +88 -0
  19. data/lib/light/services/class_based_collection/mount.rb +33 -0
  20. data/lib/light/services/collection/arguments.rb +34 -0
  21. data/lib/light/services/collection/base.rb +47 -0
  22. data/lib/light/services/collection/outputs.rb +16 -0
  23. data/lib/light/services/config.rb +63 -0
  24. data/lib/light/services/exceptions.rb +3 -2
  25. data/lib/light/services/messages.rb +72 -45
  26. data/lib/light/services/settings/argument.rb +50 -0
  27. data/lib/light/services/settings/output.rb +34 -0
  28. data/lib/light/services/settings/step.rb +62 -0
  29. data/lib/light/services/version.rb +1 -1
  30. data/light-services.gemspec +21 -25
  31. metadata +34 -122
  32. data/.codeclimate.yml +0 -18
  33. data/.ruby-gemset +0 -1
  34. data/.ruby-version +0 -1
  35. data/.travis.yml +0 -33
  36. data/Appraisals +0 -13
  37. data/gemfiles/rails_5_0.gemfile +0 -7
  38. data/gemfiles/rails_5_0.gemfile.lock +0 -151
  39. data/gemfiles/rails_5_1.gemfile +0 -7
  40. data/gemfiles/rails_5_1.gemfile.lock +0 -151
  41. data/gemfiles/rails_5_2.gemfile +0 -7
  42. data/gemfiles/rails_5_2.gemfile.lock +0 -159
  43. data/lib/light/services/callbacks.rb +0 -54
  44. data/lib/light/services/outputs.rb +0 -70
  45. data/lib/light/services/parameters.rb +0 -96
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 86f26dbb1d2ea28fb7cb8c8b9615d93bdc536755f28240a56d562085e37b53e8
4
- data.tar.gz: e96c9fc9bf526e93639f6c8e46252dab105423797e3068cbd2c2fcc9d57db642
3
+ metadata.gz: 9f6aea8958d622cea908db1b8697ab34919a55b8a90ae08dcd1308498e5963ec
4
+ data.tar.gz: d4a1226609083ba01282c7d1bc273e75c394b2d39a2c17cca53792bc7eff74ab
5
5
  SHA512:
6
- metadata.gz: c7aab86f783de54ffecf6b9682c4cc8cdf3046049e314e75bb23fcc24f405dc04a76e07c3f9ca5eb2ae06dbeb9f19a5ead2447953535fba1041260caaf8a7fc6
7
- data.tar.gz: f156cf767647c47ca47a0058d8f9e41d89bda90daed7eecd69fb209fdcbf0d9c45205374a68a85abe8510e812a479c9b68e7621cca9994ef1becbe83fdb51350
6
+ metadata.gz: e1dcc97d1d3cf6d48062a2dcb7061ecaccf602224dfbb68111c83a499614d221c17b3b1c0301ca448e58d27bcbd495d5303b5577fb1facdf16140ac591b40c1c
7
+ data.tar.gz: 0d3d5f2282f56fbe07f786f54c098f9235a5f84906f70aaac1214da61c3fbef847c2af9754228c9b6eb9a682a40f2dd1bb1737755457e67a1a6bb5dc56816ffc
@@ -0,0 +1,4 @@
1
+ versions:
2
+ - rubocop: "0.86"
3
+ - rubocop-rspec: "1.40"
4
+ - rubocop-performance: "1.6"
@@ -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,5 @@
1
1
  /.bundle/
2
2
  /.yardoc
3
- /Gemfile.lock
4
3
  /_yardoc/
5
4
  /coverage/
6
5
  /doc/
@@ -8,6 +7,6 @@
8
7
  /spec/reports/
9
8
  /tmp/
10
9
  /.idea/
11
- /gemfiles/.bundle/
12
- /*.gem
13
- /*.iml
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --format documentation
2
2
  --color
3
+ --require spec_helper
@@ -1,16 +1,30 @@
1
+ require:
2
+ - rubocop-rspec
3
+ - rubocop-performance
4
+
1
5
  AllCops:
2
- TargetRubyVersion: 2.4
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/ClassAndModuleChildren:
8
- Exclude:
9
- - 'spec/**/*'
22
+ Style/StringLiterals:
23
+ EnforcedStyle: double_quotes
10
24
 
11
- Metrics/LineLength:
12
- Max: 120
25
+ Style/GuardClause:
26
+ Enabled: false
13
27
 
14
- Metrics/BlockLength:
28
+ Style/ClassAndModuleChildren:
15
29
  Exclude:
16
- - 'spec/**/*'
30
+ - spec/data/services/**/*.rb
@@ -0,0 +1 @@
1
+ # Changelog
@@ -1,24 +1,41 @@
1
- # Contributor Code of Conduct
1
+ # Contributor Covenant Code of Conduct
2
2
 
3
- As contributors and maintainers of this project, and in the interest of
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
- We are committed to making participation in this project a harassment-free
9
- experience for everyone, regardless of level of experience, gender, gender
10
- identity and expression, sexual orientation, disability, personal appearance,
11
- body size, race, ethnicity, age, religion, or nationality.
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
- * Personal attacks
17
- * Trolling or insulting/derogatory comments
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 other's private information, such as physical or electronic
20
- addresses, without explicit permission
21
- * Other unethical or unprofessional conduct
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
- By adopting this Code of Conduct, project maintainers commit themselves to
30
- fairly and consistently applying these principles to every aspect of managing
31
- this project. Project maintainers who do not follow or enforce the Code of
32
- Conduct may be permanently removed from the project team.
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
- This code of conduct applies both within project spaces and in public spaces
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 a project maintainer at emelianenko.web@gmail.com. All
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. Maintainers are
41
- obligated to maintain confidentiality with regard to the reporter of an
42
- incident.
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
- version 1.3.0, available at
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]: http://contributor-covenant.org
49
- [version]: http://contributor-covenant.org/version/1/3/0/
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 'https://rubygems.org'
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
@@ -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
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2016 Andrew Emelianenko
3
+ Copyright (c) 2020 Andrew Emelianenko
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README.md CHANGED
@@ -1,150 +1,4 @@
1
- # Light::Services
2
-
3
- [![Build Status](https://travis-ci.org/light-ruby/light-services.svg?branch=master)](https://travis-ci.org/light-ruby/light-services)
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