Custom RuboCop cops for enforcing Cuseum service class conventions.
Add this line to your application's Gemfile:
gem 'rubocop-cuseum', github: 'cuseum/rubocop-cuseum'And then execute:
$ bundle install
Or install it yourself as:
$ gem install rubocop-cuseum
Put this into your .rubocop.yml:
require:
- rubocop-cuseumEnsures that service classes have at most one public method.
# good - zero public methods
class UserService < BaseService
private
def process_user
# ...
end
end
# good - one public method
class UserService < BaseService
def call
# ...
end
private
def process_user
# ...
end
end
# bad - multiple public methods
class UserService < BaseService
def call
# ...
end
def execute # ← should be private
# ...
end
endEnsures that service classes inherit from BaseService directly or indirectly.
# good - direct inheritance
class UserService < BaseService
def call
# ...
end
end
# good - indirect inheritance through ApplicationService
class UserService < ApplicationService
def call
# ...
end
end
# bad - no inheritance from BaseService
class UserService
def call
# ...
end
endEnsures that any public method in service classes is named "call".
# good - public method named "call"
class UserService < BaseService
def call
# ...
end
private
def process_user
# ...
end
end
# bad - public method with wrong name
class UserService < BaseService
def execute # ← should be "call"
# ...
end
endAfter checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests.
Bug reports and pull requests are welcome on GitHub at https://github.com/cuseum/rubocop-cuseum.
The gem is available as open source under the terms of the MIT License.