{"id":13878694,"url":"https://github.com/markets/serviz","last_synced_at":"2025-04-12T08:08:44.609Z","repository":{"id":54389781,"uuid":"212819607","full_name":"markets/serviz","owner":"markets","description":"📐 Command object Interface for Ruby ","archived":false,"fork":false,"pushed_at":"2024-05-05T17:01:23.000Z","size":24,"stargazers_count":30,"open_issues_count":0,"forks_count":1,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-04-12T08:05:48.653Z","etag":null,"topics":["command-pattern","minimal","ruby","service-object"],"latest_commit_sha":null,"homepage":"https://rubygems.org/gems/serviz","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/markets.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-10-04T13:19:42.000Z","updated_at":"2025-03-24T11:32:17.000Z","dependencies_parsed_at":"2024-01-13T20:37:55.083Z","dependency_job_id":"23f81053-09ea-4e4a-a0ba-bc0b141d6764","html_url":"https://github.com/markets/serviz","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markets%2Fserviz","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markets%2Fserviz/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markets%2Fserviz/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/markets%2Fserviz/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/markets","download_url":"https://codeload.github.com/markets/serviz/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248537138,"owners_count":21120709,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["command-pattern","minimal","ruby","service-object"],"created_at":"2024-08-06T08:01:56.957Z","updated_at":"2025-04-12T08:08:44.581Z","avatar_url":"https://github.com/markets.png","language":"Ruby","readme":"# Serviz\n\n[![Gem](https://img.shields.io/gem/v/serviz.svg?style=flat-square)](https://rubygems.org/gems/serviz)\n[![Build Status](https://github.com/markets/serviz/actions/workflows/ci.yml/badge.svg?branch=master)](https://github.com/markets/serviz/actions)\n[![Maintainability](https://api.codeclimate.com/v1/badges/871bdafe6ca410b4b64a/maintainability)](https://codeclimate.com/github/markets/serviz/maintainability)\n\n\u003e Minimalistic Service Class Interface for Ruby\n\n`Serviz` provides a minimal interface to unify and homogenize your *Service* or *Command* objects in your Ruby code.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'serviz'\n```\n\nAnd then execute:\n\n    \u003e bundle install\n\nOr install it yourself as:\n\n    \u003e gem install serviz\n\n## Usage\n\n- Your class should inherit from `Serviz::Base`\n- Your class should implement a `#call` method\n- Return the _result_ via `self.result=`\n- Add _errors_ via `self.errors\u003c\u003c`\n- Check the status via the provided `#success?` or `#failure?` methods\n\n### Example\n\nFirst, you should create a _Serviz_ class:\n\n```ruby\nclass RegisterUser \u003c Serviz::Base\n  def initialize(user)\n    @user = user\n  end\n\n  def call\n    if @user.valid?\n      @user.register_and_notify\n\n      self.result = @user\n    else\n      self.errors \u003c\u003c 'Invalid user'\n    end\n  end\nend\n```\n\nNow, you can run it by using the `call` method:\n\n```ruby\noperation = RegisterUser.call(user)\n\nif operation.success?\n  user = operation.result\n  puts \"Success! #{user.name} registered!\"\nelse\n  puts \"Error! #{operation.error_messages}\"\nend\n```\n\nAs you can see in the example above, you can use the `success?` method to check if your operation succeed. You can also use the `ok?` alias.\n\nIn case you want to check if the run failed, you can use the `failure?` method (or the alias `error?`):\n\n```ruby\nif operation.failure?\n  puts \"Error! Please try again ...\"\n  return\nend\n```\n\n### Block syntax\n\nYou may like to use the _block_ syntax:\n\n```ruby\nRegisterUser.call(user) do |operation|\n  puts \"Success!\" if operation.ok?\nend\n```\n\n## Development\n\nAny kind of feedback, bug report or enhancement are really welcome!\n\nTo contribute, just fork the repo, hack on it and send a pull request. Don't forget to add specs for behaviour changes and run the test suite:\n\n    \u003e bundle exec rspec\n\n## License\n\nCopyright (c) Marc Anguera. `Serviz` is released under the [MIT](LICENSE) License.\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkets%2Fserviz","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fmarkets%2Fserviz","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fmarkets%2Fserviz/lists"}