{"id":13880176,"url":"https://github.com/guideline-tech/subroutine","last_synced_at":"2026-01-18T10:46:12.638Z","repository":{"id":27984971,"uuid":"31478781","full_name":"guideline-tech/subroutine","owner":"guideline-tech","description":"Subroutine makes it easy to write encapsulated, feature-driven code. It handles the boilerplate of inputs, outputs, type casting, and validation and lets you focus on the important functional code.","archived":false,"fork":false,"pushed_at":"2024-04-07T15:13:48.000Z","size":214,"stargazers_count":40,"open_issues_count":1,"forks_count":13,"subscribers_count":9,"default_branch":"main","last_synced_at":"2024-04-07T17:51:14.802Z","etag":null,"topics":["encapsulation","form-objects","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/guideline-tech.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.MD","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":".github/CODEOWNERS","security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2015-02-28T22:20:28.000Z","updated_at":"2024-05-17T16:32:16.339Z","dependencies_parsed_at":"2022-07-12T20:30:31.926Z","dependency_job_id":"9ecbf9e2-8d29-447f-8f74-e3fc2445f7de","html_url":"https://github.com/guideline-tech/subroutine","commit_stats":{"total_commits":112,"total_committers":11,"mean_commits":"10.181818181818182","dds":0.3035714285714286,"last_synced_commit":"829f16f94430817d7815d3adf13c70779ecdb2e4"},"previous_names":["mnelson/subroutine"],"tags_count":24,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guideline-tech%2Fsubroutine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guideline-tech%2Fsubroutine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guideline-tech%2Fsubroutine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guideline-tech%2Fsubroutine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guideline-tech","download_url":"https://codeload.github.com/guideline-tech/subroutine/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":225964910,"owners_count":17552426,"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":["encapsulation","form-objects","ruby","service-objects"],"created_at":"2024-08-06T08:02:50.212Z","updated_at":"2026-01-18T10:46:12.597Z","avatar_url":"https://github.com/guideline-tech.png","language":"Ruby","readme":"# Subroutine\n\nA gem that provides an interface for creating feature-driven operations. You've probably heard at least one of these terms: \"service objects\", \"form objects\", \"intentions\", or \"commands\". Subroutine calls these \"ops\" and really it's just about enabling clear, concise, testable, and meaningful code.\n\n## Example\n\nSo you need to sign up a user? or maybe update one's account? or change a password? or maybe you need to sign up a business along with a user, associate them, send an email, and queue a worker in a single request? Not a problem, create an op for any of these use cases. Here's the signup example.\n\n```ruby\nclass SignupOp \u003c ::Subroutine::Op\n\n  string :name\n  string :email\n  string :password\n\n  string :company_name\n\n  validates :name, presence: true\n  validates :email, presence: true\n  validates :password, presence: true\n  validates :company_name, presence: true\n\n  outputs :user\n  outputs :business, type: Business # validate that output type is an instance of Business\n  outputs :heavy_operation, lazy: true # delay the execution of the output until accessed\n\n  protected\n\n  def perform\n    u = create_user!\n    b = create_business!(u)\n\n    deliver_welcome_email(u)\n\n    output :user, u\n    output :business, b\n    output :heavy_operation, -\u003e { some_heavy_operation }\n  end\n\n  def create_user!\n    User.create!(name: name, email: email, password: password)\n  end\n\n  def create_business!(owner)\n    Business.create!(company_name: company_name, owner: owner)\n  end\n\n  def some_heavy_operation\n    # ...\n  end\n\n  def deliver_welcome_email(u)\n    UserMailer.welcome(u.id).deliver_later\n  end\nend\n```\n\n## So why use this?\n\n- Avoid cluttering models or controllers with logic only applicable to one intention. You also don't need strong parameters because the inputs to the Op are well-defined.\n- Test the Op in isolation\n- Clear and concise intention in a single file\n- Multi-model operations become simple\n\n## Continue Reading\n\n- [Implementing an Op](https://github.com/guideline-tech/subroutine/wiki/Implementing-an-Op)\n- [Using an Op](https://github.com/guideline-tech/subroutine/wiki/Using-an-Op)\n- [Errors](https://github.com/guideline-tech/subroutine/wiki/Errors)\n- [Basic Usage in Rails](https://github.com/guideline-tech/subroutine/wiki/Rails-Usage)\n\n## Development\n\nRun the test suite against current Rails version:\n\n```\nbundle exec rake test\n```\n\nRun the test suite against all supported Rails versions using `appraisal`:\n\n```\nbundle exec appraisal rake test\n```\n\nFor help updating the `Gemfile` or changing supported Rails versions, see the `appraisal` gem [README](https://github.com/thoughtbot/appraisal#usage).\n\nNote that the gemfiles in `gemfiles/*` are auto-generated by `appraisal` and should not be modified directly.\n","funding_links":[],"categories":["Ruby"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguideline-tech%2Fsubroutine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguideline-tech%2Fsubroutine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguideline-tech%2Fsubroutine/lists"}