{"id":19134004,"url":"https://github.com/umbrellio/resol","last_synced_at":"2026-03-08T01:06:27.706Z","repository":{"id":43379603,"uuid":"355881247","full_name":"umbrellio/resol","owner":"umbrellio","description":"Gem for creating (any) object patterns","archived":false,"fork":false,"pushed_at":"2025-01-11T08:48:16.000Z","size":104,"stargazers_count":12,"open_issues_count":1,"forks_count":1,"subscribers_count":5,"default_branch":"master","last_synced_at":"2025-11-16T23:10:22.906Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/umbrellio.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":"2021-04-08T11:33:39.000Z","updated_at":"2024-09-25T14:32:30.000Z","dependencies_parsed_at":"2025-04-19T07:40:50.596Z","dependency_job_id":"70e2abd6-21b0-418e-8d86-a272de49c545","html_url":"https://github.com/umbrellio/resol","commit_stats":{"total_commits":24,"total_committers":5,"mean_commits":4.8,"dds":0.375,"last_synced_commit":"ccb98eeea03f27b20a7ad3be678fd03e9c31dfe8"},"previous_names":[],"tags_count":14,"template":false,"template_full_name":null,"purl":"pkg:github/umbrellio/resol","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umbrellio%2Fresol","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umbrellio%2Fresol/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umbrellio%2Fresol/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umbrellio%2Fresol/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/umbrellio","download_url":"https://codeload.github.com/umbrellio/resol/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/umbrellio%2Fresol/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":30240357,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-03-08T00:58:18.660Z","status":"ssl_error","status_checked_at":"2026-03-08T00:55:48.608Z","response_time":53,"last_error":"SSL_read: 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":[],"created_at":"2024-11-09T06:24:42.154Z","updated_at":"2026-03-08T01:06:27.698Z","avatar_url":"https://github.com/umbrellio.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Resol\n\n![https://github.com/umbrellio/resol](https://github.com/umbrellio/resol/actions/workflows/test.yml/badge.svg)\n[![Coverage Status](https://coveralls.io/repos/github/umbrellio/resol/badge.svg?branch=master)](https://coveralls.io/github/umbrellio/resol?branch=master)\n[![Gem Version](https://badge.fury.io/rb/resol.svg)](https://badge.fury.io/rb/resol)\n\nRuby Gem for creating simple service objects and other any object ruby patterns.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'resol'\n```\n\nAnd then execute:\n\n    $ bundle install\n\nOr install it yourself as:\n\n    $ gem install resol\n\n## Usage\n\n### Sample usage\n\n```ruby\nclass FindUser \u003c Resol::Service\n  param :id\n\n  def call\n    user = User.find(id)\n    if user\n      success!(user)\n    else\n      fail!(:not_found)\n    end\n  end\nend\n\n# when user exists\nFindUser.call(1) # =\u003e Resol::Success(\u003cuser object\u003e)\nFindUser.call!(1) # =\u003e \u003cuser object\u003e\n\n# when user doesn't exist\nFindUser.call(100) # =\u003e Resol::Failure(:not_found)\nFindUser.call!(100) # =\u003e raised FindUser::Failure: :not_found\n```\n\nSo method `.call` always returns the [result object](#result-objects)\nand method `.call!` returns a value or throws an error (in case of `fail!` has been called).\n\n#### Params defining\n\n`Resol` supports two gems, which provide abstract initialization flow for classes:\n\n1. [smart_initializer](https://github.com/smart-rb/smart_initializer), which was default provider for a very long time.\n2. [dry-initializer](https://dry-rb.org/gems/dry-initializer/3.1), additional provider with DSL almost identical to the smart_core's DSL.\n\nThere is an _important restriction_ on using different initializers in different services.\nDescendants of a parent, into which initializer logic has already been imported, cannot override the provider\n\nYou can use both providers for a different services:\n\n```ruby\n# Types is a namespace for all types, defined by smart_types.\nclass FirstService \u003c Resol::Service\n  inject_initializer :smartcore_injector\n\n  param :first, Types::String\n  param :second, Types::Integer\nend\n\n# Types is a namespace for all types, defined by dry-types.\nclass SecondService \u003c Resol::Service\n  inject_initializer :dry_injector\n\n  param :first, Types::Strict::String\n  param :second, Types::Strict::Integer\nend\n```\n\nBoth initializers support inheritance. And base features for initialization flow\nlike default value, arguments accessors visibility level, coercible attributes and so on.\n\nList of all supported initializers you can see at `DependencyContainer` definition.\n\n#### Return a result\n\n**Note** – calling `success!`/`fail!` methods interrupts `call` method execution.\n\n- `success!(value)` – finish with a success value\n- `fail!(code, data = nil)` – fail with any error code and optional data\n\n#### Define callbacks\n\nYou can define callbacks to be executed before calling the `#call` method.\n\n```ruby\nclass FindUser \u003c Resol::Service\n  param :id\n\n  before_call :set_user\n\n  def call\n    if user\n      success!(user)\n    else\n      fail!(:not_found)\n    end\n  end\n\n  private\n\n  attr_accessor :user\n\n  def set_user\n    self.user = User.find(id)\n  end\nend\n```\n\n### Result objects\n\nMethods:\n\n- `success?` — returns `true` for success result and `false` for failure result\n- `failure?` — returns `true` for failure result and `false` for success result\n- `value!` — unwraps a result object, returns the value for success result, and throws an error for failure result\n- `value_or(other_value, \u0026block)` — returns a value for success result or `other_value` for failure result (either calls `block` in case it given)\n- `error` — returns `nil` for success result and error object (with code and data) for failure result\n- `or(\u0026block)` — calls block for failure result, for success result does nothing\n- `either(success_proc, failure_proc)` — for success result calls success_proc with result value in args, for failure result calls failure_proc with error in args.\n- `bind` — using with `block` for success result resolve value and pass it to the `block`, used to chain multiple monads. Block can return anything. Failure result ignore block and return `self`.\n- `fmap` — like the `bind`, but wraps value returned by block by success monad.\n\n### Error object\n\nIn case of failure you can get an error object with error code\nand data from `fail!` arguments. This can be done by method `error` on\nthe result object and the returned object will have corresponding\nmethods `code` and `data`.\n\n### Configuration\n\nConfiguration constant references to `SmartCore::Initializer::Configuration`. You can read\nabout available configuration options [here](https://github.com/smart-rb/smart_initializer#configuration).\n\n### Plugin System\n\nResol implements the basic logic of using plugins to extend and change the base service class.\nYou can write your own plugin and applie it by calling `Resol::Service#plugin(plugin_name)`.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `bin/rspec` to run the tests.\nIf you want to check coverage, then set env variable `COVER` to `true` before running `bin/rspec`:\n`COVER=true bin/rspec`.\nYou can also run `bin/console` for an interactive prompt that will allow you to experiment.\n\nTo install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/umbrellio/resol.\n\n## License\n\nThe gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).\n\n## Authors\n\nCreated by [Aleksei Bespalov](https://github.com/nulldef).\n\n\u003ca href=\"https://github.com/umbrellio/\"\u003e\n\u003cimg style=\"float: left;\" src=\"https://umbrellio.github.io/Umbrellio/supported_by_umbrellio.svg\" alt=\"Supported by Umbrellio\" width=\"439\" height=\"72\"\u003e\n\u003c/a\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fumbrellio%2Fresol","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fumbrellio%2Fresol","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fumbrellio%2Fresol/lists"}