{"id":15713710,"url":"https://github.com/stephendolan/decorator","last_synced_at":"2025-05-12T22:54:50.859Z","repository":{"id":52928776,"uuid":"323151991","full_name":"stephendolan/decorator","owner":"stephendolan","description":"A simple Crystal shard for decorating objects","archived":false,"fork":false,"pushed_at":"2021-10-21T18:20:34.000Z","size":79,"stargazers_count":12,"open_issues_count":0,"forks_count":1,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-05-12T22:54:43.070Z","etag":null,"topics":["crystal","crystal-lang","decorator","decorator-pattern","decorators"],"latest_commit_sha":null,"homepage":"https://stephendolan.github.io/decorator","language":"Crystal","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/stephendolan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/funding.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":"stephendolan"}},"created_at":"2020-12-20T19:46:40.000Z","updated_at":"2024-04-19T18:00:24.000Z","dependencies_parsed_at":"2022-08-24T13:51:05.512Z","dependency_job_id":null,"html_url":"https://github.com/stephendolan/decorator","commit_stats":null,"previous_names":[],"tags_count":5,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephendolan%2Fdecorator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephendolan%2Fdecorator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephendolan%2Fdecorator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/stephendolan%2Fdecorator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/stephendolan","download_url":"https://codeload.github.com/stephendolan/decorator/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253837389,"owners_count":21971981,"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":["crystal","crystal-lang","decorator","decorator-pattern","decorators"],"created_at":"2024-10-03T21:33:02.984Z","updated_at":"2025-05-12T22:54:50.820Z","avatar_url":"https://github.com/stephendolan.png","language":"Crystal","funding_links":["https://github.com/sponsors/stephendolan"],"categories":[],"sub_categories":[],"readme":"# Decorator\n\n![Shard CI](https://github.com/stephendolan/decorator/workflows/Shard%20CI/badge.svg)\n[![API Documentation Website](https://img.shields.io/website?down_color=red\u0026down_message=Offline\u0026label=API%20Documentation\u0026up_message=Online\u0026url=https%3A%2F%2Fstephendolan.github.io%2Fdecorator%2F)](https://stephendolan.github.io/decorator)\n[![GitHub release](https://img.shields.io/github/release/stephendolan/decorator.svg?label=Release)](https://github.com/stephendolan/decorator/releases)\n\nA simple [Crystal](https://crystal-lang.org) shard for decorating objects.\n\n## Installation\n\nAdd the dependency to your `shard.yml`:\n\n```yaml\ndependencies:\n  decorator:\n    github: stephendolan/decorator\n```\n\nRun `shards install`\n\n## 🎬 Screencast\n\n\u003ca href=\"https://luckycasts.com/videos/decorator-shard\"\u003e\u003cimg src=\"https://i.imgur.com/1gs4z0c.jpg\" title=\"Decorating Lucky Apps with the Decorator Shard\" width=\"500\" /\u003e\u003c/a\u003e\n\n[Watch a LuckyCast on the Decorator shard](https://luckycasts.com/videos/decorator-shard)\n\n## Usage\n\nRequire the shard:\n\n```crystal\nrequire \"decorator\"\n```\n\nCreate a decorator `Struct` that inherits from `Decorator::Base`, and define\nwhat it `decorates`:\n\n```crystal\nstruct TimeDecorator \u003c Decorator::Base\n  decorates time : Time\n\n  # Return a pretty version of a date and weekday in the format:\n  # `Monday, November 2, 2020`\n  def date_with_weekday : String\n    time.to_s(\"%A, %B %-d, %Y\")\n  end\n\n  # Return a pretty version of a date in the format:\n  # `November 2, 2020`\n  def date : String\n    time.to_s(\"%B %-d, %Y\")\n  end\nend\n```\n\nIn the above example, `Decorator` adds the following to the `TimeDecorator`\nstruct for you:\n\n- An `initialize(@time : Time)` method\n- A `collection(objects : Array(Time))` class method\n- A `getter` (or `getter?` for `Bool` types) for `@time`\n\nNow, you're able to transform `Time` objects using the decorator:\n\n```crystal\ndecorated_time = TimeDecorator.new(Time.utc)\n\nputs decorated_time.date_with_weekday\n# =\u003e \"Monday, November 2, 2020\"\n\nputs decorated_time.date\n# =\u003e \"November 2, 2020\"\n```\n\nOr even a collection of time objects with the `collection` method:\n\n```crystal\ndecorated_times = TimeDecorator.collection([\n  Time.utc - 1.year,\n  Time.utc,\n  Time.utc + 1.year\n])\n\nputs decorated_times[0].date_with_weekday\n# =\u003e \"Saturday, November 2, 2019\"\nputs decorated_times[1].date_with_weekday\n# =\u003e \"Monday, November 2, 2020\"\nputs decorated_times[2].date_with_weekday\n# =\u003e \"Tuesday, November 2, 2021\"\n```\n\n## Contributing\n\n1. [Fork it](https://github.com/stephendolan/decorator/fork)\n2. Create your feature branch (`git checkout -b my-new-feature`)\n3. Commit your changes (`git commit -am 'Add some feature'`)\n4. Push to the branch (`git push origin my-new-feature`)\n5. Create a new Pull Request\n\n## Contributors\n\n- [Stephen Dolan](https://github.com/stephendolan) - creator and maintainer\n\n## Inspiration\n\n- The `decorates` syntax and code mimics the [Lucky::Assignable Module](https://github.com/luckyframework/lucky/blob/master/src/lucky/assignable.cr) `needs` implementation created by the [Lucky](https://luckyframework.org) team.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephendolan%2Fdecorator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fstephendolan%2Fdecorator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fstephendolan%2Fdecorator/lists"}