rails_application_service 0.6.2 → 0.7.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 5cc940286dc1211b1da1d8a01b48cff5ea2eb27c6680421870a05e6be229717b
4
- data.tar.gz: f30bebb401ab83cc2db9c0489ece9e14a3dfb3d951179bbddb6d2f6838a01831
3
+ metadata.gz: f3c13e237ec28b92e52e5c6284d8cbca6b69ed7d93aa9467c40b66e256e19e98
4
+ data.tar.gz: 6670ebb75d5c5486206e87a437f4496054e6936947c3f9818d11dbe8d7726145
5
5
  SHA512:
6
- metadata.gz: 296081b4f58ce03e5a89865da7e842a7b53be4c231ffbc4c931adf04fbf2e8d1e9b80a7f986f82c207597c2e6ff11a77aa6bfef1ddda2a69a1ad3373eab4b4c9
7
- data.tar.gz: 6e2e0b4f148f50d9f5d097b306135d35f92b122abb20a160ef6079411f972d553bc0ec64fa57b8f9413e08ed0264f06713022747d1b800e1de9d1bea8a65d0c2
6
+ metadata.gz: 81062e6edba74efb6af85341f8bc6743676517fc15b1bb367e973e22a3318fe9aeb49f14f335edcff304562eebe9ab99803119da46b2cbeca39f0e0510f46d01
7
+ data.tar.gz: 1bbfdc3d7d7382df7ff1cce32162f1662e09aa64d26172b14ea2981b52dde17b850bbe38b6375eb95aa502c1a0db96ebc01882e542648d5dfb44e7725135852f
data/CHANGELOG.md CHANGED
@@ -5,101 +5,38 @@ All notable changes to this project are documented in this file.
5
5
  The format follows [Keep a Changelog](https://keepachangelog.com/en/1.1.0/),
6
6
  and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
7
7
 
8
- ## [0.6.2] - in progress
9
-
10
- ### Added
11
-
12
- ### Changed
13
- - Simplified docs
14
-
15
- ### Removed
16
-
17
- ### Breaking Changes
18
-
19
- ## [0.6.1] - 2025-06-18
20
-
21
- ### Added
22
-
23
- ### Changed
24
- - Enhanced the changelog
25
-
26
- ### Removed
27
-
28
- ### Breaking Changes
29
-
30
- ## [0.6.0] - 2025-06-18
31
-
32
- ### Added
8
+ ## [0.7.0] - 2026-11-23
33
9
 
34
10
  ### Changed
35
- - Enhanced the changelog
36
-
37
- ### Removed
11
+ - Excluded development files from the packaged gem
38
12
 
39
13
  ### Breaking Changes
14
+ - Ruby 4.0 or later is now required (previously Ruby 2.2)
15
+ - ActiveModel 8.0 or later is now required (previously ActiveModel 4.2)
16
+ - Unimplemented services now raise `ApplicationService::NotImplementedError`, a `StandardError`, instead of Ruby's built-in `NotImplementedError`
40
17
 
41
- ## [0.5.0] - 2025-06-18
42
-
43
- ### Added
18
+ ## [0.6.2] - 2025-08-02
44
19
 
45
20
  ### Changed
46
- - Improved code documentation and README
47
- - Refactored and simplified test specs
48
- - Fixed Rubocop offenses
49
- - Updated dependencies
50
-
51
- ### Removed
21
+ - `ApplicationService::Base` now includes `ActiveModel::Model` instead of `ActiveModel::API`, `ActiveModel::Attributes` and `ActiveModel::Validations`
52
22
 
53
23
  ### Breaking Changes
24
+ - Removed `ActiveModel::Attributes` support: services must declare inputs with `attr_accessor` instead of `attribute`, and inputs are no longer type cast
54
25
 
55
26
  ## [0.4.0] - 2025-06-05
56
27
 
57
28
  ### Added
58
- - Added support for `ActiveModel::API` and `ActiveModel::Attributes`
59
- - Enabled type casting through `ActiveModel::Attributes`
60
- - Added validation via `ActiveModel::Validations`
61
-
62
- ### Changed
63
- - Service initialization now exclusively uses keyword arguments
64
- - Improved error messages and documentation
65
- - Enhanced example code in docstrings
66
-
67
- ### Removed
68
- - Removed support for positional arguments in the `call` method
69
-
70
- ### Breaking Changes
71
- - Services must now use keyword arguments instead of positional arguments
72
- - All existing services using positional arguments need to be updated
73
-
74
- ## [0.3.0] - 2025-02-05
75
-
76
- ### Added
77
-
78
- ### Changed
79
- - Refactored source code and tests
80
-
81
- ### Removed
29
+ - Typed attributes through `ActiveModel::Attributes`
82
30
 
83
31
  ### Breaking Changes
32
+ - Services now take keyword arguments instead of positional arguments
84
33
 
85
34
  ## [0.2.0] - 2025-02-04
86
35
 
87
36
  ### Added
88
-
89
- ### Changed
90
- - Refactored source code and tests
91
-
92
- ### Removed
93
-
94
- ### Breaking Changes
37
+ - Input validation through `ActiveModel::Validations`
95
38
 
96
39
  ## [0.1.0] - 2025-02-04
97
40
 
98
41
  ### Added
99
42
  - Initial release
100
-
101
- ### Changed
102
-
103
- ### Removed
104
-
105
- ### Breaking Changes
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2025 Mário Marroquim
3
+ Copyright (c) 2026 Mário Marroquim
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,8 +1,10 @@
1
1
  # Rails Application Service
2
2
 
3
- Service objects for Rails, the Rails way. This Ruby gem adds service objects to your Rails applications.
3
+ This Ruby gem adds service classes (e.g., use cases, features, or commands) to Ruby on Rails web applications.
4
4
 
5
- ## Installation
5
+ ## Instructions
6
+
7
+ Requires Ruby 4.0 or later and Rails (ActiveModel) 8.0 or later.
6
8
 
7
9
  **1 - Add the gem to your Rails application's Gemfile:**
8
10
 
@@ -22,15 +24,13 @@ bundle install
22
24
  mkdir -p app/services
23
25
  ```
24
26
 
25
- ## Usage
27
+ ## Usage examples
26
28
 
27
- The `ApplicationService::Base` class provides a standard interface for calling service objects. It leverages `ActiveModel` for initialization with keyword arguments and input validation.
29
+ The `ApplicationService::Base` class provides a standard interface for calling services. It leverages `ActiveModel` for initialization with keyword arguments and input validation.
28
30
 
29
31
  ### Basic service example
30
32
 
31
33
  ```ruby
32
- require "application_service"
33
-
34
34
  class MyService < ApplicationService::Base
35
35
  def call
36
36
  # Perform the service action
@@ -43,11 +43,8 @@ my_service = MyService.call # nil
43
43
  ### Example with attributes and validations
44
44
 
45
45
  ```ruby
46
- require "application_service"
47
-
48
46
  class Sum < ApplicationService::Base
49
- attribute :number_a, :integer
50
- attribute :number_b, :integer
47
+ attr_accessor :number_a, :number_b
51
48
 
52
49
  validates :number_a, :number_b, presence: true, numericality: { greater_than: 0 }
53
50
 
@@ -59,36 +56,7 @@ end
59
56
  sum = Sum.call(number_a: 1, number_b: 2) # => 3
60
57
  ```
61
58
 
62
- ### Supported attribute types
63
-
64
- This gem supports the following attribute types through `ActiveModel::Attributes` and custom types defined in `ActiveModel::Type`:
65
-
66
- - `:boolean`
67
- - `:date`
68
- - `:datetime`
69
- - `:decimal`
70
- - `:float`
71
- - `:integer`
72
- - `:string`
73
- - `:time`
74
-
75
- ## Development
76
-
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.
78
-
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).
80
-
81
- ## Contributing
82
-
83
- Bug reports and pull requests are welcome on GitHub at https://github.com/mariomarroquim/rails_application_service. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [code of conduct](https://github.com/mariomarroquim/rails_application_service/blob/main/CODE_OF_CONDUCT.md).
84
-
85
- ## License
86
-
87
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
88
-
89
- ## Code of Conduct
90
-
91
- Everyone interacting in the ApplicationService project's codebases, issue trackers, chat rooms, and mailing lists is expected to follow the [code of conduct](https://github.com/mariomarroquim/rails_application_service/blob/main/CODE_OF_CONDUCT.md).
59
+ `Sum.call` returns `false` when validation fails. A service that does not define `call` raises `ApplicationService::NotImplementedError`.
92
60
 
93
61
  ## Support
94
62
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ApplicationService
4
- VERSION = "0.6.2"
4
+ VERSION = "0.7.0"
5
5
  end
@@ -7,6 +7,12 @@ require "active_model"
7
7
  # Service objects encapsulate business logic and are typically used to
8
8
  # perform a single action or a series of related actions.
9
9
  module ApplicationService
10
+ # Raised when the abstract Base class is instantiated directly, or when a
11
+ # subclass does not implement `call`. Unlike Ruby's built-in
12
+ # NotImplementedError (a ScriptError), it is a StandardError, so a plain
13
+ # `rescue` catches it.
14
+ class NotImplementedError < StandardError; end
15
+
10
16
  # The Base class within the ApplicationService module provides a standard
11
17
  # interface for calling service objects. It leverages ActiveModel for
12
18
  # initialization with keyword arguments and input validation.
@@ -30,22 +36,22 @@ module ApplicationService
30
36
  # Initializes a new instance of the service object.
31
37
  #
32
38
  # @param kwargs [Hash] The attributes to be passed to the service object.
33
- # @raise [NotImplementedError] if an attempt is made to instantiate the Base class directly.
39
+ # @raise [ApplicationService::NotImplementedError] if an attempt is made to instantiate the Base class directly.
34
40
  def initialize(**kwargs)
35
- super
36
-
37
- return unless instance_of?(Base)
41
+ if instance_of?(Base)
42
+ raise NotImplementedError, "#{self.class.name} is an abstract class and cannot be instantiated directly"
43
+ end
38
44
 
39
- raise ::NotImplementedError, "#{self.class.name} is an abstract class and cannot be instantiated directly"
45
+ super
40
46
  end
41
47
 
42
48
  # Instantiates a new service object and invokes its `call` method.
49
+ # Keyword arguments are forwarded to `new` as the service object's attributes.
43
50
  #
44
- # @param kwargs [Hash] The attributes to be passed to the service object.
45
51
  # @return [Object] The result of the service object's call method.
46
52
  # @return [false] If the service object is invalid.
47
- def self.call(**kwargs)
48
- service = new(**kwargs)
53
+ def self.call(**)
54
+ service = new(**)
49
55
  return false unless service.valid?
50
56
 
51
57
  service.call
@@ -53,9 +59,9 @@ module ApplicationService
53
59
 
54
60
  # Encapsulates the implementation to be executed by the service object.
55
61
  #
56
- # @raise [NotImplementedError] if the method is not implemented in a child class.
62
+ # @raise [ApplicationService::NotImplementedError] if the method is not implemented in a child class.
57
63
  def call
58
- raise ::NotImplementedError, "The `call` method must be implemented in #{self.class.name}"
64
+ raise NotImplementedError, "The `call` method must be implemented in #{self.class.name || self.class.inspect}"
59
65
  end
60
66
  end
61
67
  end
metadata CHANGED
@@ -1,68 +1,66 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rails_application_service
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.2
4
+ version: 0.7.0
5
5
  platform: ruby
6
6
  authors:
7
- - Mário Marroquim
8
- bindir: exe
7
+ - Mário Marroquim
8
+ bindir: bin
9
9
  cert_chain: []
10
- date: 2025-08-02 00:00:00.000000000 Z
10
+ date: 1980-01-02 00:00:00.000000000 Z
11
11
  dependencies:
12
- - !ruby/object:Gem::Dependency
13
- name: activemodel
14
- requirement: !ruby/object:Gem::Requirement
15
- requirements:
16
- - - ">="
17
- - !ruby/object:Gem::Version
18
- version: '4.2'
19
- type: :runtime
20
- prerelease: false
21
- version_requirements: !ruby/object:Gem::Requirement
22
- requirements:
23
- - - ">="
24
- - !ruby/object:Gem::Version
25
- version: '4.2'
26
- description: This Ruby gem adds service objects to Rails applications.
12
+ - !ruby/object:Gem::Dependency
13
+ name: activemodel
14
+ requirement: !ruby/object:Gem::Requirement
15
+ requirements:
16
+ -
17
+ - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: "8.0"
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ -
25
+ - ">="
26
+ - !ruby/object:Gem::Version
27
+ version: "8.0"
28
+ description: "This Ruby gem adds service classes (e.g., use cases, features, or commands) to Rails apps."
27
29
  email:
28
- - mariomarroquim@gmail.com
30
+ - mariomarroquim@gmail.com
29
31
  executables: []
30
32
  extensions: []
31
33
  extra_rdoc_files: []
32
34
  files:
33
- - ".rspec"
34
- - ".rubocop.yml"
35
- - ".ruby-version"
36
- - CHANGELOG.md
37
- - CODE_OF_CONDUCT.md
38
- - LICENSE.txt
39
- - README.md
40
- - Rakefile
41
- - lib/application_service.rb
42
- - lib/application_service/version.rb
43
- - sig/application_service.rbs
44
- homepage: https://github.com/mariomarroquim/rails_application_service
35
+ - CHANGELOG.md
36
+ - LICENSE.txt
37
+ - README.md
38
+ - lib/application_service.rb
39
+ - lib/application_service/version.rb
40
+ homepage: "https://github.com/mariomarroquim/rails_application_service"
45
41
  licenses:
46
- - MIT
42
+ - MIT
47
43
  metadata:
48
- homepage_uri: https://github.com/mariomarroquim/rails_application_service
49
- changelog_uri: https://github.com/mariomarroquim/rails_application_service/CHANGELOG.md
50
- rubygems_mfa_required: 'true'
44
+ homepage_uri: "https://github.com/mariomarroquim/rails_application_service"
45
+ changelog_uri: "https://github.com/mariomarroquim/rails_application_service/blob/main/CHANGELOG.md"
46
+ rubygems_mfa_required: "true"
51
47
  rdoc_options: []
52
48
  require_paths:
53
- - lib
49
+ - lib
54
50
  required_ruby_version: !ruby/object:Gem::Requirement
55
51
  requirements:
56
- - - ">="
57
- - !ruby/object:Gem::Version
58
- version: '2.2'
52
+ -
53
+ - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "4.0"
59
56
  required_rubygems_version: !ruby/object:Gem::Requirement
60
57
  requirements:
61
- - - ">="
62
- - !ruby/object:Gem::Version
63
- version: '0'
58
+ -
59
+ - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: "0"
64
62
  requirements: []
65
- rubygems_version: 3.6.6
63
+ rubygems_version: 4.1.0
66
64
  specification_version: 4
67
- summary: Service objects for Rails - the Rails way.
65
+ summary: Add service classes to Ruby on Rails web applications.
68
66
  test_files: []
data/.rspec DELETED
@@ -1,3 +0,0 @@
1
- --format documentation
2
- --color
3
- --require spec_helper
data/.rubocop.yml DELETED
@@ -1,10 +0,0 @@
1
- AllCops:
2
- NewCops: enable
3
- TargetRubyVersion: 2.2
4
- SuggestExtensions: false
5
-
6
- Style/StringLiterals:
7
- EnforcedStyle: double_quotes
8
-
9
- Style/StringLiteralsInInterpolation:
10
- EnforcedStyle: double_quotes
data/.ruby-version DELETED
@@ -1 +0,0 @@
1
- 3.4.1
data/CODE_OF_CONDUCT.md DELETED
@@ -1,132 +0,0 @@
1
- # Contributor Covenant Code of Conduct
2
-
3
- ## Our Pledge
4
-
5
- We as members, contributors, and leaders pledge to make participation in our
6
- community a harassment-free experience for everyone, regardless of age, body
7
- size, visible or invisible disability, ethnicity, sex characteristics, gender
8
- identity and expression, level of experience, education, socio-economic status,
9
- nationality, personal appearance, race, caste, color, religion, or sexual
10
- identity and orientation.
11
-
12
- We pledge to act and interact in ways that contribute to an open, welcoming,
13
- diverse, inclusive, and healthy community.
14
-
15
- ## Our Standards
16
-
17
- Examples of behavior that contributes to a positive environment for our
18
- community include:
19
-
20
- * Demonstrating empathy and kindness toward other people
21
- * Being respectful of differing opinions, viewpoints, and experiences
22
- * Giving and gracefully accepting constructive feedback
23
- * Accepting responsibility and apologizing to those affected by our mistakes,
24
- and learning from the experience
25
- * Focusing on what is best not just for us as individuals, but for the overall
26
- community
27
-
28
- Examples of unacceptable behavior include:
29
-
30
- * The use of sexualized language or imagery, and sexual attention or advances of
31
- any kind
32
- * Trolling, insulting or derogatory comments, and personal or political attacks
33
- * Public or private harassment
34
- * Publishing others' private information, such as a physical or email address,
35
- without their explicit permission
36
- * Other conduct which could reasonably be considered inappropriate in a
37
- professional setting
38
-
39
- ## Enforcement Responsibilities
40
-
41
- Community leaders are responsible for clarifying and enforcing our standards of
42
- acceptable behavior and will take appropriate and fair corrective action in
43
- response to any behavior that they deem inappropriate, threatening, offensive,
44
- or harmful.
45
-
46
- Community leaders have the right and responsibility to remove, edit, or reject
47
- comments, commits, code, wiki edits, issues, and other contributions that are
48
- not aligned to this Code of Conduct, and will communicate reasons for moderation
49
- decisions when appropriate.
50
-
51
- ## Scope
52
-
53
- This Code of Conduct applies within all community spaces, and also applies when
54
- an individual is officially representing the community in public spaces.
55
- Examples of representing our community include using an official email address,
56
- posting via an official social media account, or acting as an appointed
57
- representative at an online or offline event.
58
-
59
- ## Enforcement
60
-
61
- Instances of abusive, harassing, or otherwise unacceptable behavior may be
62
- reported to the community leaders responsible for enforcement at
63
- [INSERT CONTACT METHOD].
64
- All complaints will be reviewed and investigated promptly and fairly.
65
-
66
- All community leaders are obligated to respect the privacy and security of the
67
- reporter of any incident.
68
-
69
- ## Enforcement Guidelines
70
-
71
- Community leaders will follow these Community Impact Guidelines in determining
72
- the consequences for any action they deem in violation of this Code of Conduct:
73
-
74
- ### 1. Correction
75
-
76
- **Community Impact**: Use of inappropriate language or other behavior deemed
77
- unprofessional or unwelcome in the community.
78
-
79
- **Consequence**: A private, written warning from community leaders, providing
80
- clarity around the nature of the violation and an explanation of why the
81
- behavior was inappropriate. A public apology may be requested.
82
-
83
- ### 2. Warning
84
-
85
- **Community Impact**: A violation through a single incident or series of
86
- actions.
87
-
88
- **Consequence**: A warning with consequences for continued behavior. No
89
- interaction with the people involved, including unsolicited interaction with
90
- those enforcing the Code of Conduct, for a specified period of time. This
91
- includes avoiding interactions in community spaces as well as external channels
92
- like social media. Violating these terms may lead to a temporary or permanent
93
- ban.
94
-
95
- ### 3. Temporary Ban
96
-
97
- **Community Impact**: A serious violation of community standards, including
98
- sustained inappropriate behavior.
99
-
100
- **Consequence**: A temporary ban from any sort of interaction or public
101
- communication with the community for a specified period of time. No public or
102
- private interaction with the people involved, including unsolicited interaction
103
- with those enforcing the Code of Conduct, is allowed during this period.
104
- Violating these terms may lead to a permanent ban.
105
-
106
- ### 4. Permanent Ban
107
-
108
- **Community Impact**: Demonstrating a pattern of violation of community
109
- standards, including sustained inappropriate behavior, harassment of an
110
- individual, or aggression toward or disparagement of classes of individuals.
111
-
112
- **Consequence**: A permanent ban from any sort of public interaction within the
113
- community.
114
-
115
- ## Attribution
116
-
117
- This Code of Conduct is adapted from the [Contributor Covenant][homepage],
118
- version 2.1, available at
119
- [https://www.contributor-covenant.org/version/2/1/code_of_conduct.html][v2.1].
120
-
121
- Community Impact Guidelines were inspired by
122
- [Mozilla's code of conduct enforcement ladder][Mozilla CoC].
123
-
124
- For answers to common questions about this code of conduct, see the FAQ at
125
- [https://www.contributor-covenant.org/faq][FAQ]. Translations are available at
126
- [https://www.contributor-covenant.org/translations][translations].
127
-
128
- [homepage]: https://www.contributor-covenant.org
129
- [v2.1]: https://www.contributor-covenant.org/version/2/1/code_of_conduct.html
130
- [Mozilla CoC]: https://github.com/mozilla/diversity
131
- [FAQ]: https://www.contributor-covenant.org/faq
132
- [translations]: https://www.contributor-covenant.org/translations
data/Rakefile DELETED
@@ -1,12 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- require "bundler/gem_tasks"
4
- require "rspec/core/rake_task"
5
-
6
- RSpec::Core::RakeTask.new(:spec)
7
-
8
- require "rubocop/rake_task"
9
-
10
- RuboCop::RakeTask.new
11
-
12
- task default: %i[spec rubocop]
@@ -1,4 +0,0 @@
1
- module ApplicationService
2
- VERSION: String
3
- # See the writing guide of rbs: https://github.com/ruby/rbs#guides
4
- end