{"id":18930016,"url":"https://github.com/pdabrowski6/tuner","last_synced_at":"2025-04-15T15:31:13.058Z","repository":{"id":116823149,"uuid":"181019402","full_name":"pdabrowski6/tuner","owner":"pdabrowski6","description":"A pure implementation of the decorator pattern","archived":false,"fork":false,"pushed_at":"2019-04-20T13:18:00.000Z","size":4,"stargazers_count":11,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"master","last_synced_at":"2025-03-28T22:51:10.578Z","etag":null,"topics":["decorator","decorator-pattern","ruby","ruby-gem","ruby-on-rails"],"latest_commit_sha":null,"homepage":null,"language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pdabrowski6.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2019-04-12T14:01:33.000Z","updated_at":"2020-11-11T00:45:51.000Z","dependencies_parsed_at":null,"dependency_job_id":"e51182c2-1354-4305-b89c-a63fa968f601","html_url":"https://github.com/pdabrowski6/tuner","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pdabrowski6%2Ftuner","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pdabrowski6%2Ftuner/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pdabrowski6%2Ftuner/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pdabrowski6%2Ftuner/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pdabrowski6","download_url":"https://codeload.github.com/pdabrowski6/tuner/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":249097890,"owners_count":21212371,"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":["decorator","decorator-pattern","ruby","ruby-gem","ruby-on-rails"],"created_at":"2024-11-08T11:36:14.566Z","updated_at":"2025-04-15T15:31:13.052Z","avatar_url":"https://github.com/pdabrowski6.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Tuner\n\nA pure implementation of decorator pattern, alternative to Draper gem\n\n## Installation\n\n```\ngem install tuner\n```\n\n## Usage\n\nTurn your class into decorator by inheriting from `Tuner::Decorator` class:\n\n```ruby\nclass UserDecorator \u003c Tuner::Decorator\n  def full_name\n    \"#{model.first_name} #{model.last_name}\"\n  end\nend\n```\n\nthen you can decorate your object:\n\n```ruby\nuser = User.find(...)\n\nUserDecorator.new(user)\n# or \nUserDecorator.decorate(user)\n```\n\n## Benchmarks\n\nIn basic usage, `Tuner` is around 3 times faster than `Draper` and it allocates 60% less objects.\n\nCode used for benchmarks:\n\n```ruby\nrequire 'allocation_stats'\nrequire 'draper'\nrequire 'tuner'\nrequire 'benchmark'\n\nclass UserTunerDecorator \u003c Tuner::Decorator\n  def full_name\n    \"#{model.first_name} #{model.last_name}\"\n  end\nend\n\nclass UserDraperDecorator \u003c Draper::Decorator\n  def full_name\n    \"#{model.first_name} #{model.last_name}\"\n  end\nend\n\nuser = Struct.new(:first_name, :last_name).new('John', 'Doe')\n\nstats = AllocationStats.trace { UserDraperDecorator.new(user).full_name }\nputs stats.allocations.group_by(:class).to_text\n\nstats = AllocationStats.trace { UserTunerDecorator.new(user).full_name }\nputs stats.allocations.group_by(:class).to_text\n\nBenchmark.bm 10 do |bench|\n  bench.report \"Tuner: \" do\n    1_000_000.times { UserTunerDecorator.new(user).full_name }\n  end\n\n  bench.report \"Draper: \" do\n    1_000_000.times { UserDraperDecorator.new(user).full_name }\n  end\nend\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpdabrowski6%2Ftuner","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpdabrowski6%2Ftuner","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpdabrowski6%2Ftuner/lists"}