{"id":25751969,"url":"https://github.com/tinyhr/tiny_decorator","last_synced_at":"2026-04-29T14:33:51.139Z","repository":{"id":40172187,"uuid":"160130538","full_name":"TINYhr/tiny_decorator","owner":"TINYhr","description":"More strictly ruby decorator base on SimpleDelegator","archived":false,"fork":false,"pushed_at":"2023-03-08T18:06:53.000Z","size":42,"stargazers_count":0,"open_issues_count":9,"forks_count":0,"subscribers_count":1,"default_branch":"master","last_synced_at":"2024-03-23T08:22:09.021Z","etag":null,"topics":["decorators","ruby"],"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/TINYhr.png","metadata":{"files":{"readme":"README.md","changelog":null,"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,"governance":null}},"created_at":"2018-12-03T04:01:23.000Z","updated_at":"2023-01-31T17:08:03.000Z","dependencies_parsed_at":"2023-07-15T15:25:36.811Z","dependency_job_id":"e37c9b80-c970-40ee-bdb9-f96c76fd4f5b","html_url":"https://github.com/TINYhr/tiny_decorator","commit_stats":null,"previous_names":["anvox/tiny_decorator"],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TINYhr%2Ftiny_decorator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TINYhr%2Ftiny_decorator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TINYhr%2Ftiny_decorator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/TINYhr%2Ftiny_decorator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/TINYhr","download_url":"https://codeload.github.com/TINYhr/tiny_decorator/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":240867432,"owners_count":19870405,"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":["decorators","ruby"],"created_at":"2025-02-26T14:19:03.880Z","updated_at":"2026-04-29T14:33:51.109Z","avatar_url":"https://github.com/TINYhr.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"\n[![Build Status](https://travis-ci.org/anvox/tiny_decorator.svg?branch=master)](https://travis-ci.org/anvox/tiny_decorator)\n\n# TinyDecorator\n\nThe world of ruby decorator is dominated by `draper`, I use it all the time.\nBut when project grows and we chase the dealine, the flexible and easily of `draper` make us keep abusing it. Now, when using a decorated model we dont know which method/attribute are define in which decorator, which decorators depend on which ones.\n`tiny_decorator` aims to separate decoration logic into different decorators, and centralize logic to determine which decorators are used. It isn't built to replace `draper` as it just solve our internal problem of abusing `draper`, it's better if you using `draper` wisely instead `tiny_decorator`\n\nBut if you're interesting in this gem, every contributes are welcome.\n\n## Installation\n\nAdd this line to your application's Gemfile:\n\n```ruby\ngem 'tiny_decorator'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install tiny_decorator\n\n## Usage\n\nModel decorated by 1 single decorator\n```ruby\n  class NewDecorator \u003c TinyDecorator::SingleDecorator\n    def new_method\n      'decorated'\n    end\n  end\n\n  NewDecorator.decorate(Object.new).new_method # 'decorated'\n  NewDecorator.decorate_collection([Object.new, Object.new])[1].new_method # 'decorated'\n```\n\nModel decorate by more than 1 decorators\n```ruby\n  class NewDecorator2\n    extend TinyDecorator::CompositeDecorator\n\n    decorated_by :default, 'DefaultDecorator'\n\n    decorated_by :nil, -\u003e(record) { record.nil? ? 'NilDecorator' : 'DefaultDecorator' }\n    decorated_by :nil, -\u003e(record, context) { record.in(context).nil? ? 'NilDecorator' : 'DefaultDecorator' }\n  end\n```\n\nAnd use it\n```ruby\ncontext = { current_user: user }\n#\nNewDecorator.decorate(model)\nNewDecorator.decorate(model, context)\n# OR\nNewDecorator.decorate_collection(models)\nNewDecorator.decorate_collection(models, context)\n\n```\n\n### Preload\n\nIn case rails' eager loading doesn't fit, or we don't use. `preload` could be used to avoid N+1.\n\n```ruby\n  preload :count_all, -\u003e(all_records, context, preloaded) { Group(all_records).count }\n  #   all_records - all the records to decorate\n  #   context     - The context passed to collection decorating,\n  #     because preload run once before all decratings, this is the only cotext we have at this time\n  #   preloaded   - all preloaded before. For perfomrance, it's mutable, please handle with care\n```\n\nThen each single decorator could access through `preload[:count_all]`.\nNote: `preload` will be run once before decorating all records, compare to context will be ran for each record.\n\n## Development\n\nAfter checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You 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 tags, 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/anvox/tiny_decorator. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the [Contributor Covenant](http://contributor-covenant.org) code of conduct.\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## Code of Conduct\n\nEveryone interacting in the TinyDecorator project’s codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/anvox/tiny_decorator/blob/master/CODE_OF_CONDUCT.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinyhr%2Ftiny_decorator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ftinyhr%2Ftiny_decorator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ftinyhr%2Ftiny_decorator/lists"}