{"id":47874641,"url":"https://github.com/alec-c4/auto_decorator","last_synced_at":"2026-04-04T01:09:42.764Z","repository":{"id":340208100,"uuid":"1164974752","full_name":"alec-c4/auto_decorator","owner":"alec-c4","description":"Convention-based decorator autoloading for Rails models.","archived":false,"fork":false,"pushed_at":"2026-04-02T20:36:47.000Z","size":99,"stargazers_count":2,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2026-04-03T16:44:49.979Z","etag":null,"topics":["decorator","gem","ruby","ruby-on-rails"],"latest_commit_sha":null,"homepage":"https://alec-c4.com/projects/auto_decorator","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/alec-c4.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","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,"notice":null,"maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null},"funding":{"github":"alec-c4"}},"created_at":"2026-02-23T17:31:51.000Z","updated_at":"2026-04-02T20:36:49.000Z","dependencies_parsed_at":null,"dependency_job_id":null,"html_url":"https://github.com/alec-c4/auto_decorator","commit_stats":null,"previous_names":["alec-c4/auto_decorator"],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/alec-c4/auto_decorator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alec-c4%2Fauto_decorator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alec-c4%2Fauto_decorator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alec-c4%2Fauto_decorator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alec-c4%2Fauto_decorator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/alec-c4","download_url":"https://codeload.github.com/alec-c4/auto_decorator/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/alec-c4%2Fauto_decorator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31383705,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-03T23:20:52.058Z","status":"ssl_error","status_checked_at":"2026-04-03T23:20:51.675Z","response_time":107,"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":["decorator","gem","ruby","ruby-on-rails"],"created_at":"2026-04-04T01:09:37.854Z","updated_at":"2026-04-04T01:09:42.755Z","avatar_url":"https://github.com/alec-c4.png","language":"Ruby","funding_links":["https://github.com/sponsors/alec-c4"],"categories":[],"sub_categories":[],"readme":"# auto_decorator\n\nConvention-based decorator autoloading for Rails models.\n\nDecorators are plain Ruby modules that get automatically included into your model classes based on file naming convention — no configuration required.\n\n\u003e **Why not Draper?** Draper wraps objects in presenter classes. `auto_decorator` adds methods directly to the model. Less indirection, less boilerplate, same result for most use cases.\n\n## Installation\n\nAdd to your Gemfile:\n\n```ruby\ngem \"auto_decorator\"\n```\n\n## Usage\n\n### Convention\n\nPlace decorator files in `app/decorators/`. The gem discovers them automatically and includes each module into the matching model class:\n\n| File                                                 | Module                             | Included into             |\n| ---------------------------------------------------- | ---------------------------------- | ------------------------- |\n| `app/decorators/user_decorator.rb`                   | `UserDecorator`                    | `User`                    |\n| `app/decorators/organization_decorator.rb`           | `OrganizationDecorator`            | `Organization`            |\n| `app/decorators/organizations/employee_decorator.rb` | `Organizations::EmployeeDecorator` | `Organizations::Employee` |\n\n### Example\n\n```ruby\n# app/decorators/user_decorator.rb\nmodule UserDecorator\n  def full_name\n    [first_name, last_name].compact.join(\" \")\n  end\n\n  def to_s\n    full_name.presence || email\n  end\nend\n```\n\n```ruby\n# app/decorators/organizations/employee_decorator.rb\nmodule Organizations\n  module EmployeeDecorator\n    def active?\n      status == \"active\"\n    end\n  end\nend\n```\n\nSince the modules are included directly into the model, decorated methods are available anywhere the model is used:\n\n```ruby\nuser = User.find(1)\nuser.full_name  # =\u003e \"Alice Smith\"\nuser.to_s       # =\u003e \"Alice Smith\"\n```\n\n### Generator\n\nScaffold a new decorator with:\n\n```bash\nrails g decorator User\n# → creates app/decorators/user_decorator.rb\n\nrails g decorator Organizations::Employee\n# → creates app/decorators/organizations/employee_decorator.rb\n```\n\nGenerated file for `User`:\n\n```ruby\n# frozen_string_literal: true\n\nmodule UserDecorator\nend\n```\n\nGenerated file for `Organizations::Employee`:\n\n```ruby\n# frozen_string_literal: true\n\nmodule Organizations\n  module EmployeeDecorator\n  end\nend\n```\n\n### Configuration\n\nThe gem works with zero configuration. To override defaults:\n\n```ruby\n# config/initializers/auto_decorator.rb\nAutoDecorator.configure do |config|\n  config.decorators_path = \"app/decorators\"  # relative to Rails.root\n  config.decorator_suffix = \"Decorator\"\nend\n```\n\n## How it works\n\nOn every `config.to_prepare` (triggered on boot and in development on each request):\n\n1. Glob all `*_decorator.rb` files under `decorators_path`\n2. Derive the module name from the file path: `organizations/employee_decorator.rb` → `Organizations::EmployeeDecorator`\n3. Derive the model name by stripping the suffix: `Organizations::EmployeeDecorator` → `Organizations::Employee`\n4. Call `ModelClass.include(DecoratorModule)` — skips if already included\n\nIf the model class doesn't exist (e.g. a decorator for a non-existent model), it is silently skipped.\n\n## Compatibility\n\n|       |           |\n| ----- | --------- |\n| Ruby  | ≥ 3.2     |\n| Rails | 7.0 – 8.1 |\n\n## Contributing\n\nBug reports and pull requests are welcome on [GitHub](https://github.com/alec-c4/auto_decorator).\n\n## License\n\n[MIT](LICENSE.txt)\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falec-c4%2Fauto_decorator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Falec-c4%2Fauto_decorator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Falec-c4%2Fauto_decorator/lists"}