{"id":15293300,"url":"https://github.com/akuzko/zen-service","last_synced_at":"2026-01-19T16:00:38.734Z","repository":{"id":56845142,"uuid":"112847047","full_name":"akuzko/zen-service","owner":"akuzko","description":"flexible and highly extensible Service Objects for business logic organization","archived":false,"fork":false,"pushed_at":"2025-12-30T16:48:52.000Z","size":129,"stargazers_count":3,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-01-14T11:28:49.258Z","etag":null,"topics":["flexible","ruby","service-objects"],"latest_commit_sha":null,"homepage":"","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/akuzko.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","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,"zenodo":null}},"created_at":"2017-12-02T14:08:44.000Z","updated_at":"2025-12-30T16:48:05.000Z","dependencies_parsed_at":"2025-04-13T13:11:16.344Z","dependency_job_id":"16d8729f-af72-4d28-8b6f-cfef2f8b393f","html_url":"https://github.com/akuzko/zen-service","commit_stats":null,"previous_names":["akuzko/excom"],"tags_count":13,"template":false,"template_full_name":null,"purl":"pkg:github/akuzko/zen-service","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akuzko%2Fzen-service","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akuzko%2Fzen-service/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akuzko%2Fzen-service/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akuzko%2Fzen-service/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/akuzko","download_url":"https://codeload.github.com/akuzko/zen-service/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/akuzko%2Fzen-service/sbom","scorecard":{"id":176986,"data":{"date":"2025-08-11","repo":{"name":"github.com/akuzko/zen-service","commit":"d6778be0839893946dd518398704dc8177acb173"},"scorecard":{"version":"v5.2.1-40-gf6ed084d","commit":"f6ed084d17c9236477efd66e5b258b9d4cc7b389"},"score":3,"checks":[{"name":"Packaging","score":-1,"reason":"packaging workflow not detected","details":["Warn: no GitHub/GitLab publishing workflow detected."],"documentation":{"short":"Determines if the project is published as a package that others can easily download, install, easily update, and uninstall.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#packaging"}},{"name":"Pinned-Dependencies","score":-1,"reason":"no dependencies found","details":null,"documentation":{"short":"Determines if the project has declared and pinned the dependencies of its build process.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#pinned-dependencies"}},{"name":"Binary-Artifacts","score":10,"reason":"no binaries found in the repo","details":null,"documentation":{"short":"Determines if the project has generated executable (binary) artifacts in the source repository.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#binary-artifacts"}},{"name":"Code-Review","score":0,"reason":"Found 0/30 approved changesets -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project requires human code review before pull requests (aka merge requests) are merged.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#code-review"}},{"name":"Dangerous-Workflow","score":-1,"reason":"no workflows found","details":null,"documentation":{"short":"Determines if the project's GitHub Action workflows avoid dangerous patterns.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#dangerous-workflow"}},{"name":"Token-Permissions","score":-1,"reason":"No tokens found","details":null,"documentation":{"short":"Determines if the project's workflows follow the principle of least privilege.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#token-permissions"}},{"name":"Maintained","score":0,"reason":"0 commit(s) and 0 issue activity found in the last 90 days -- score normalized to 0","details":null,"documentation":{"short":"Determines if the project is \"actively maintained\".","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#maintained"}},{"name":"CII-Best-Practices","score":0,"reason":"no effort to earn an OpenSSF best practices badge detected","details":null,"documentation":{"short":"Determines if the project has an OpenSSF (formerly CII) Best Practices Badge.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#cii-best-practices"}},{"name":"Security-Policy","score":0,"reason":"security policy file not detected","details":["Warn: no security policy file detected","Warn: no security file to analyze","Warn: no security file to analyze","Warn: no security file to analyze"],"documentation":{"short":"Determines if the project has published a security policy.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#security-policy"}},{"name":"Vulnerabilities","score":10,"reason":"0 existing vulnerabilities detected","details":null,"documentation":{"short":"Determines if the project has open, known unfixed vulnerabilities.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#vulnerabilities"}},{"name":"Fuzzing","score":0,"reason":"project is not fuzzed","details":["Warn: no fuzzer integrations found"],"documentation":{"short":"Determines if the project uses fuzzing.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#fuzzing"}},{"name":"License","score":10,"reason":"license file detected","details":["Info: project has a license file: LICENSE.txt:0","Info: FSF or OSI recognized license: MIT License: LICENSE.txt:0"],"documentation":{"short":"Determines if the project has defined a license.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#license"}},{"name":"Signed-Releases","score":-1,"reason":"no releases found","details":null,"documentation":{"short":"Determines if the project cryptographically signs release artifacts.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#signed-releases"}},{"name":"Branch-Protection","score":0,"reason":"branch protection not enabled on development/release branches","details":["Warn: branch protection not enabled for branch 'master'"],"documentation":{"short":"Determines if the default and release branches are protected with GitHub's branch protection settings.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#branch-protection"}},{"name":"SAST","score":0,"reason":"SAST tool is not run on all commits -- score normalized to 0","details":["Warn: 0 commits out of 1 are checked with a SAST tool"],"documentation":{"short":"Determines if the project uses static code analysis.","url":"https://github.com/ossf/scorecard/blob/f6ed084d17c9236477efd66e5b258b9d4cc7b389/docs/checks.md#sast"}}]},"last_synced_at":"2025-08-16T17:53:32.532Z","repository_id":56845142,"created_at":"2025-08-16T17:53:32.532Z","updated_at":"2025-08-16T17:53:32.532Z"},"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":28573281,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-01-19T15:45:05.669Z","status":"ssl_error","status_checked_at":"2026-01-19T15:44:23.317Z","response_time":67,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"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":["flexible","ruby","service-objects"],"created_at":"2024-09-30T16:46:08.793Z","updated_at":"2026-01-19T16:00:38.728Z","avatar_url":"https://github.com/akuzko.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Zen::Service\n\nFlexible and highly extensible Service Objects for business logic organization.\n\n[![Gem Version](https://img.shields.io/gem/v/zen-service.svg)](https://rubygems.org/gems/zen-service)\n[![CI Status](https://github.com/akuzko/zen-service/actions/workflows/ci.yml/badge.svg)](https://github.com/akuzko/zen-service/actions/workflows/ci.yml)\n[![codecov](https://codecov.io/gh/akuzko/zen-service/branch/master/graph/badge.svg)](https://codecov.io/gh/akuzko/zen-service)\n[![Ruby Version](https://img.shields.io/badge/ruby-%3E%3D%203.2-ruby.svg)](https://www.ruby-lang.org)\n[![License](https://img.shields.io/badge/license-MIT-blue.svg)](LICENSE)\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'zen-service'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install zen-service\n\n## Usage\n\nThe most basic usage of `Zen::Service` can be demonstrated with the following example:\n\n```ruby\n# app/services/todos/update.rb\nmodule Todos\n  class Update \u003c ApplicationService # Base class for app services, inherits from Zen::Service\n    attributes :todo, :params\n\n    def call\n      if todo.update(params)\n        [:ok, todo]\n      else\n        [:error, todo.errors.messages]\n      end\n    end\n  end\nend\n\n# app/controllers/todos_controller.rb\nclass TodosController \u003c ApplicationController\n  def update\n    case Todos::Update.call(todo, params: todo_params)\n    in [:ok, todo] then render json: Todos::Show.call(todo)\n    in [:error, errors] then render json: errors, status: :unprocessable_content\n    end\n  end\nend\n```\n\n### Service Attributes\n\n`Zen::Service` instances are initialized with _attributes_. To specify the list of available attributes, use the `attributes`\nclass method. All attributes are optional during initialization. You can omit keys and pass attributes as positional\nparameters—they will be assigned in the order they were declared. However, you cannot:\n\n- Pass more attributes than declared\n- Pass the same attribute multiple times (both as positional and keyword argument)\n- Pass undeclared attributes\n\n```ruby\nclass MyService \u003c Zen::Service\n  attributes :foo, :bar\n\n  def call\n    # Your business logic here\n  end\n\n  def foo\n    super || 5 # Provide default value\n  end\nend\n\n# Different ways to initialize services\ns1 = MyService.new\ns1.foo # =\u003e 5\ns1.bar # =\u003e nil\n\ns2 = MyService.new(6)\ns2.foo # =\u003e 6\ns2.bar # =\u003e nil\n\ns3 = MyService.new(foo: 1, bar: 2)\ns3.foo # =\u003e 1\ns3.bar # =\u003e 2\n\n# Create a new service from an existing one with some attributes changed\ns4 = s3.with_attributes(bar: 3)\ns4.foo # =\u003e 1\ns4.bar # =\u003e 3\n\n# Create a service from another service's attributes\ns5 = MyService.from(s3)\ns5.foo # =\u003e 1\ns5.bar # =\u003e 2\n```\n\n### Service Extensions (Plugins)\n\n`zen-service` is built with extensibility at its core. Even fundamental functionality like callable behavior\nand attributes are implemented as plugins. The base `Zen::Service` class uses two core plugins:\n\n- `:callable` - Provides class methods `.call` and `.[]` that instantiate and call the service\n- `:attributes` - Manages service initialization parameters with runtime validation\n\nIn addition, `zen-service` provides optional built-in plugins:\n\n#### `:persisted_result`\n\nProvides `#result` method that returns the value from the most recent `#call` invocation, along with a\n`#called?` helper method.\n\n**Options:**\n\n- `call_unless_called: false` (default) - When `true`, accessing `service.result` will automatically\n  call `#call` if it hasn't been called yet.\n\n```ruby\nclass MyService \u003c Zen::Service\n  use :persisted_result, call_unless_called: true\n\n  attributes :value\n\n  def call\n    value * 2\n  end\nend\n\nservice = MyService.new(5)\nservice.called? # =\u003e false\nservice.result  # =\u003e 10 (automatically calls #call)\nservice.called? # =\u003e true\n```\n\n#### `:result_yielding`\n\nEnables nested service calls to return block-provided values instead of the nested service's return value.\nUseful for wrapping service calls with cross-cutting concerns like logging or error handling.\n\n```ruby\nclass Logger \u003c Zen::Service\n  use :result_yielding\n\n  # Will result with value return by `yield` expression\n  def call\n    Rails.logger.info(\"Starting operation\")\n    result = yield\n    Rails.logger.info(\"Operation completed: #{result.inspect}\")\n  end\nend\n\nclass UpdateTodo \u003c Zen::Service\n  attributes :todo, :params\n\n  def call\n    Logger.call do\n      todo.update!(params)\n      [:ok, todo]\n    rescue ActiveRecord::RecordInvalid\n      [:error, todo.errors.messages]\n    end\n  end\nend\n```\n\n### Creating Custom Plugins\n\nCreating custom plugins is straightforward. Below is an example of a plugin that transforms results to\ncamelCase notation (using ActiveSupport's core extensions):\n\n```ruby\nmodule CamelizeResult\n  extend Zen::Service::Plugins::Plugin\n\n  def self.used(service_class)\n    service_class.prepend(Extension)\n  end\n\n  def self.camelize(obj)\n    case obj\n    when Array then obj.map { |item| camelize(item) }\n    when Hash then obj.deep_transform_keys { |key| key.to_s.camelize(:lower).to_sym }\n    else obj\n    end\n  end\n\n  module Extension\n    def call\n      CamelizeResult.camelize(super)\n    end\n  end\nend\n\nclass Todos::Show \u003c Zen::Service\n  attributes :todo\n\n  use :camelize_result\n\n  def call\n    {\n      id: todo.id,\n      is_completed: todo.completed?\n    }\n  end\nend\n\nTodos::Show[todo] # =\u003e { id: 1, isCompleted: true }\n```\n\n#### Plugin Registration\n\nPlugins that extend `Zen::Service::Plugins::Plugin` are automatically registered when the module is loaded.\nYou can also register plugins manually:\n\n```ruby\n# Register a plugin module\nZen::Service::Plugins.register(:my_plugin, MyPlugin)\n\n# Register by class name (useful when autoload isn't available yet, e.g., during Rails initialization)\nZen::Service::Plugins.register(:my_plugin, \"MyApp::Services::MyPlugin\")\n```\n\n#### Plugin Lifecycle\n\nWhen using a plugin on a service class:\n\n- **First use**: Both `used` and `configure` callbacks are invoked, and the module is included\n- **Inheritance**: If a plugin was already used by an ancestor class, only `configure` is called,\n  allowing reconfiguration without re-including the module\n\nThis design enables child classes to customize inherited plugin behavior:\n\n```ruby\nclass BaseService \u003c Zen::Service\n  use :persisted_result, call_unless_called: false\nend\n\nclass ChildService \u003c BaseService\n  use :persisted_result, call_unless_called: true  # Reconfigures without re-including\nend\n```\n\n#### Plugin DSL\n\nPlugins can use several DSL methods when extending `Zen::Service::Plugins::Plugin`:\n\n```ruby\nmodule MyPlugin\n  extend Zen::Service::Plugins::Plugin\n\n  # Override the auto-generated registration name\n  register_as :custom_name\n\n  # Set default options\n  default_options foo: 5, bar: false\n\n  # Called when plugin is first used on a class\n  def self.used(service_class, **options, \u0026block)\n    # Include/prepend modules, add class methods, etc.\n  end\n\n  # Called every time the plugin is used (including on child classes)\n  def self.configure(service_class, **options, \u0026block)\n    # Configure behavior based on options\n  end\nend\n```\n\n## Testing\n\nThe gem has 100% test coverage with both line and branch coverage. To run the test suite:\n\n```bash\nbundle exec rspec\n```\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `bundle exec rspec` to run\nthe tests. You can also run `bin/console` for an interactive prompt that allows you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`.\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/akuzko/zen-service.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakuzko%2Fzen-service","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fakuzko%2Fzen-service","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fakuzko%2Fzen-service/lists"}