rails_application_service 0.5.0 → 0.6.1
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 +4 -4
- data/CHANGELOG.md +29 -24
- data/README.md +13 -10
- data/lib/application_service/version.rb +1 -1
- data/lib/application_service.rb +10 -11
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e47161deb51bec3466f37eb936845b0464f67d803962ebc65b5a88eb2b0d0770
|
4
|
+
data.tar.gz: 5e42179ec517d0c2ef2779bc46b8fe9c7c000f8fe595466edee79186074ca9d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e45cf7ad68739ec61369f2c7aca8e8fbe9845f6fede5c663939eaf8dd68aba0c22c1a8cabd65423915a0976252e2269326f2ed8c9b0d391d5c8ddfc739bcc507
|
7
|
+
data.tar.gz: afe771aeb70c7b7153ed2bb7d6872a9f4ce814bf3485d6dd6077d269d31717f4b2a7461311abada17538451f50376a8c155ef02ee2305044315d1f73856e6f88
|
data/CHANGELOG.md
CHANGED
@@ -1,55 +1,60 @@
|
|
1
|
-
#
|
1
|
+
# Changelog
|
2
2
|
|
3
|
-
All notable changes to this project
|
3
|
+
All notable changes to this project are documented in this file.
|
4
4
|
|
5
|
-
The format
|
6
|
-
and this project adheres to [Semantic Versioning](
|
5
|
+
The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
|
6
|
+
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
7
7
|
|
8
|
-
## [
|
8
|
+
## [0.6.1] - 2025-06-18
|
9
9
|
|
10
|
-
|
11
|
-
|
10
|
+
### Added
|
11
|
+
|
12
|
+
### Changed
|
13
|
+
- Enhanced the changelog
|
14
|
+
|
15
|
+
### Removed
|
16
|
+
|
17
|
+
### Breaking Changes
|
18
|
+
|
19
|
+
## [0.6.0] - 2025-06-18
|
12
20
|
|
13
21
|
### Added
|
14
|
-
- [PROJECTNAME-XXXX](http://tickets.projectname.com/browse/PROJECTNAME-XXXX)
|
15
|
-
MINOR Ticket title goes here.
|
16
|
-
- [PROJECTNAME-YYYY](http://tickets.projectname.com/browse/PROJECTNAME-YYYY)
|
17
|
-
PATCH Ticket title goes here.
|
18
22
|
|
19
23
|
### Changed
|
24
|
+
- Enhanced the changelog
|
20
25
|
|
21
26
|
### Removed
|
22
27
|
|
23
28
|
### Breaking Changes
|
24
29
|
|
25
|
-
## [0.5.0] - 2025-06-
|
30
|
+
## [0.5.0] - 2025-06-18
|
26
31
|
|
27
32
|
### Added
|
28
33
|
|
29
34
|
### Changed
|
30
|
-
-
|
31
|
-
-
|
32
|
-
- Rubocop offenses
|
33
|
-
-
|
35
|
+
- Improved code documentation and README
|
36
|
+
- Refactored and simplified test specs
|
37
|
+
- Fixed Rubocop offenses
|
38
|
+
- Updated dependencies
|
34
39
|
|
35
40
|
### Removed
|
36
41
|
|
37
42
|
### Breaking Changes
|
38
43
|
|
39
|
-
## [0.4.0] - 2025-06-
|
44
|
+
## [0.4.0] - 2025-06-05
|
40
45
|
|
41
46
|
### Added
|
42
|
-
-
|
43
|
-
-
|
44
|
-
-
|
47
|
+
- Added support for `ActiveModel::API` and `ActiveModel::Attributes`
|
48
|
+
- Enabled type casting through `ActiveModel::Attributes`
|
49
|
+
- Added validation via `ActiveModel::Validations`
|
45
50
|
|
46
51
|
### Changed
|
47
|
-
- Service initialization now uses keyword arguments
|
52
|
+
- Service initialization now exclusively uses keyword arguments
|
48
53
|
- Improved error messages and documentation
|
49
54
|
- Enhanced example code in docstrings
|
50
55
|
|
51
56
|
### Removed
|
52
|
-
-
|
57
|
+
- Removed support for positional arguments in the `call` method
|
53
58
|
|
54
59
|
### Breaking Changes
|
55
60
|
- Services must now use keyword arguments instead of positional arguments
|
@@ -60,7 +65,7 @@ straightforward as possible.
|
|
60
65
|
### Added
|
61
66
|
|
62
67
|
### Changed
|
63
|
-
-
|
68
|
+
- Refactored source code and tests
|
64
69
|
|
65
70
|
### Removed
|
66
71
|
|
@@ -71,7 +76,7 @@ straightforward as possible.
|
|
71
76
|
### Added
|
72
77
|
|
73
78
|
### Changed
|
74
|
-
-
|
79
|
+
- Refactored source code and tests
|
75
80
|
|
76
81
|
### Removed
|
77
82
|
|
data/README.md
CHANGED
@@ -1,22 +1,23 @@
|
|
1
1
|
# Rails Application Service
|
2
2
|
|
3
|
-
Service objects for Rails
|
3
|
+
Service objects for Rails, the Rails way. This Ruby gem adds service objects to your Rails applications.
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
**1 - Add the gem to
|
7
|
+
**1 - Add the gem to your Rails application's Gemfile:**
|
8
8
|
|
9
9
|
```bash
|
10
10
|
bundle add rails_application_service
|
11
11
|
```
|
12
12
|
|
13
|
-
**2 - Install the gem
|
13
|
+
**2 - Install the gem by running:**
|
14
14
|
|
15
15
|
```bash
|
16
16
|
bundle install
|
17
17
|
```
|
18
18
|
|
19
|
-
**3 - Create an `app/services`
|
19
|
+
**3 - Create an `app/services` directory in your Rails application:**
|
20
|
+
|
20
21
|
```bash
|
21
22
|
mkdir -p app/services
|
22
23
|
```
|
@@ -25,7 +26,8 @@ mkdir -p app/services
|
|
25
26
|
|
26
27
|
The `ApplicationService::Base` class provides a standard interface for calling service objects with robust type handling and validations. It leverages `ActiveModel::API` for initialization with keyword arguments, `ActiveModel::Attributes` for type casting, and `ActiveModel::Validations` for input validation.
|
27
28
|
|
28
|
-
###
|
29
|
+
### Basic service example
|
30
|
+
|
29
31
|
```ruby
|
30
32
|
require "application_service"
|
31
33
|
|
@@ -38,7 +40,8 @@ end
|
|
38
40
|
my_service = MyService.call # nil
|
39
41
|
```
|
40
42
|
|
41
|
-
### Example
|
43
|
+
### Example with attributes and validations
|
44
|
+
|
42
45
|
```ruby
|
43
46
|
require "application_service"
|
44
47
|
|
@@ -56,9 +59,9 @@ end
|
|
56
59
|
sum = Sum.call(number_a: 1, number_b: 2) # => 3
|
57
60
|
```
|
58
61
|
|
59
|
-
###
|
62
|
+
### Supported attribute types
|
60
63
|
|
61
|
-
This gem supports the following attribute types through `ActiveModel::Attributes` and
|
64
|
+
This gem supports the following attribute types through `ActiveModel::Attributes` and custom types defined in `ActiveModel::Type`:
|
62
65
|
|
63
66
|
- `:boolean`
|
64
67
|
- `:date`
|
@@ -71,9 +74,9 @@ This gem supports the following attribute types through `ActiveModel::Attributes
|
|
71
74
|
|
72
75
|
## Development
|
73
76
|
|
74
|
-
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to
|
77
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to execute the tests. You can also run `bin/console` for an interactive prompt to experiment.
|
75
78
|
|
76
|
-
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`,
|
79
|
+
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`, then run `bundle exec rake release`. This will create a git tag for the version, push git commits and the tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
77
80
|
|
78
81
|
## Contributing
|
79
82
|
|
data/lib/application_service.rb
CHANGED
@@ -46,24 +46,23 @@ module ApplicationService
|
|
46
46
|
|
47
47
|
# Initializes a new instance of the service object.
|
48
48
|
#
|
49
|
-
# @param kwargs [Hash]
|
50
|
-
# @raise [NotImplementedError] if an attempt is made to instantiate the Base class directly
|
49
|
+
# @param kwargs [Hash] The attributes to be passed to the service object.
|
50
|
+
# @raise [NotImplementedError] if an attempt is made to instantiate the Base class directly.
|
51
51
|
def initialize(**kwargs)
|
52
52
|
super
|
53
53
|
|
54
|
-
|
55
|
-
|
56
|
-
|
54
|
+
if instance_of?(Base)
|
55
|
+
raise ::NotImplementedError, "#{self.class.name} is an abstract class and cannot be instantiated directly"
|
56
|
+
end
|
57
57
|
end
|
58
58
|
|
59
|
-
#
|
59
|
+
# Instantiates a new service object and invokes its `call` method.
|
60
60
|
#
|
61
|
-
# @param kwargs [Hash]
|
62
|
-
# @return [Object]
|
63
|
-
# @return [false]
|
61
|
+
# @param kwargs [Hash] The attributes to be passed to the service object.
|
62
|
+
# @return [Object] The result of the service object's call method.
|
63
|
+
# @return [false] If the service object is invalid.
|
64
64
|
def self.call(**kwargs)
|
65
65
|
service = new(**kwargs)
|
66
|
-
|
67
66
|
return false unless service.valid?
|
68
67
|
|
69
68
|
service.call
|
@@ -71,7 +70,7 @@ module ApplicationService
|
|
71
70
|
|
72
71
|
# Encapsulates the implementation to be executed by the service object.
|
73
72
|
#
|
74
|
-
# @raise [NotImplementedError] if the method is not implemented in a child class
|
73
|
+
# @raise [NotImplementedError] if the method is not implemented in a child class.
|
75
74
|
def call
|
76
75
|
raise ::NotImplementedError, "The `call` method must be implemented in #{self.class.name}"
|
77
76
|
end
|