{"id":13878695,"url":"https://github.com/smart-rb/smart_operation","last_synced_at":"2025-07-16T14:32:47.956Z","repository":{"id":56896210,"uuid":"233698370","full_name":"smart-rb/smart_operation","owner":"smart-rb","description":"Smart implementation of the most-used programming pattern - Service Object. Powered by smart_injection, smart_container, smart_types and smart_initializer.","archived":false,"fork":false,"pushed_at":"2022-11-23T11:20:16.000Z","size":56,"stargazers_count":23,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-09-20T14:10:42.346Z","etag":null,"topics":["ddd","ruby-ddd","ruby-service-object","service-object","smart-rb"],"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/smart-rb.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-01-13T21:35:00.000Z","updated_at":"2024-05-18T15:49:18.000Z","dependencies_parsed_at":"2022-08-20T17:10:18.459Z","dependency_job_id":null,"html_url":"https://github.com/smart-rb/smart_operation","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smart-rb%2Fsmart_operation","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smart-rb%2Fsmart_operation/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smart-rb%2Fsmart_operation/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/smart-rb%2Fsmart_operation/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/smart-rb","download_url":"https://codeload.github.com/smart-rb/smart_operation/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":226138849,"owners_count":17579496,"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":["ddd","ruby-ddd","ruby-service-object","service-object","smart-rb"],"created_at":"2024-08-06T08:01:56.977Z","updated_at":"2024-11-24T07:31:15.196Z","avatar_url":"https://github.com/smart-rb.png","language":"Ruby","funding_links":[],"categories":["Ruby"],"sub_categories":[],"readme":"# SmartCore::Operation \u0026middot; \u003ca target=\"_blank\" href=\"https://github.com/Cado-Labs\"\u003e\u003cimg src=\"https://github.com/Cado-Labs/cado-labs-logos/raw/main/cado_labs_badge.svg\" alt=\"Supported by Cado Labs\" style=\"max-width: 100%; height: 20px\"\u003e\u003c/a\u003e \u0026middot; [![Gem Version](https://badge.fury.io/rb/smart_operation.svg)](https://badge.fury.io/rb/smart_operation)\n\nSmart implementation of the most-used programming pattern - Service Object. Powered by smart_injection, smart_container, smart_types and smart_initializer.\n\n\u003e previous generation: https://github.com/0exp/smart_core\n\n---\n\n\u003cp\u003e\n  \u003ca href=\"https://github.com/Cado-Labs\"\u003e\n    \u003cimg src=\"https://github.com/Cado-Labs/cado-labs-logos/blob/main/cado_labs_supporting.svg\" alt=\"Supported by Cado Labs\" /\u003e\n  \u003c/a\u003e\n\u003c/p\u003e\n\n---\n\n## Main features\n\n- multifunctional constructor DSL (powerd by [smart_initializer](https://github.com/smart-rb/smart_initializer) and [smart_types](https://github.com/smart-rb/smart_types));\n- result object interface (`Success`, `Failure`, `Fatal`, `Callback`);\n- `call.new.call` invocation behavior;\n- support for dependency injection (powered by [smart_injection](https://github.com/smart-rb/smart_injection) and [smart_container](https://github.com/smart-rb/smart_container));\n\n---\n\n## Installation\n\n```ruby\ngem 'smart_operation'\n```\n\n```shell\nbundle install\n# --- or ---\ngem install smart_types\n```\n\n```ruby\nrequire 'smart_core/operation'\n```\n\n---\n\n## Synopsis\n\n```ruby\nclass CreateUser \u003c SmartCore::Operation\n  register_container(ReposContainer)\n\n  import({ user_repo: 'business.users' }, access: :private)\n\n  option :name, 'value.string'\n  option :password, 'value.string'\n  option :age, 'value.integer'\n\n  def call\n    user = user_repo.create({ name: name, password: password, age: age })\n    Success(user: user) # or Callback { puts 'wow o.O' }\n  end\nend\n\nCreateUser.call(name: 'Rustam', password: 'test123', age: 28) do |result|\n  result.success?  { puts 'success!' }\n  result.failure?  { puts 'failure!' }\n  result.fatal?    { puts 'fatal!' }\n  result.callback? { result.call } # or some_object.instance_eval(\u0026result.callback)\nend # NOTE: returns \u003cresult\u003e object, but invokes the correspinding block\n\n# COMING SOON:\nCreateUser.exec(name: 'Rustam', password: 'test123', age: 28) do |result|\n  # ...the same code as above...\nend # NOTE: returns the result of the corresponding invoked block object\n```\n\nPre-requisits:\n\n```ruby\nclass UserRepo\n  def create(user_creds)\n     # ... some code\n  end\nend\n\nReposContainer = SmartCore::Container.define do\n  namespace(:business) do\n    register(:users) { UserRepo.new }\n  end\nend\n```\n\n---\n\n## Roadmap\n\n- method memoization logic (with abilities to refresh memoized methods);\n- pattern matching for result objects (`Success`, `Failure`, `Fatal`, `Callback`);\n- migrate to `Github Actions`;\n- parametrized `.call` methods (`ServiceObject.with(attrs_a).call(attrs_b)` =\u003e `ServiceObject.new(attrs_b).call(attrs_a)` or something another);\n- think about default exception classes and interfaces to support a basic domain-specific exception class definitioning (common practice);\n- generators: an ability to invoke result block in repeatable `yield`-like style :thinking: (think about Fibers, js-like generators and similar) (for example: `.generator(call_attrs) do |result| # repeatable result block invokation for each \"yield\" from an inside \"generator\" method)`;\n\n---\n\n## Build\n\n- run tests:\n\n```shell\nbundle exec rspec\n```\n\n- run code style checks:\n\n```shell\nbundle exec rubocop\n```\n\n- run code style checks with auto-correction:\n\n```shell\nbundle exec rubocop -A\n```\n\n---\n\n## Contributing\n\n- Fork it ( https://github.com/smart-rb/smart_operation )\n- Create your feature branch (`git checkout -b feature/my-new-feature`)\n- Commit your changes (`git commit -am '[feature_context] Add some feature'`)\n- Push to the branch (`git push origin feature/my-new-feature`)\n- Create new Pull Request\n\n## License\n\nReleased under MIT License.\n\n## Supporting\n\n\u003ca href=\"https://github.com/Cado-Labs\"\u003e\n  \u003cimg src=\"https://github.com/Cado-Labs/cado-labs-logos/blob/main/cado_labs_logo.png\" alt=\"Supported by Cado Labs\" /\u003e\n\u003c/a\u003e\n\n## Authors\n\n[Rustam Ibragimov](https://github.com/0exp)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmart-rb%2Fsmart_operation","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsmart-rb%2Fsmart_operation","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsmart-rb%2Fsmart_operation/lists"}