decorator
Version, currently 0.1.05 versions
- 1.1.0latestOct 21, 2021
- 1.0.0not indexedNov 24, 2025
- 0.3.0not indexedNov 24, 2025
- 0.2.0not indexedNov 24, 2025
- 0.1.0not indexedNov 24, 2025
github.com/LuckyCasts/decorator
A simple object decoration library for Crystal apps
12 stars
0 dependents
License: MIT
Nothing has been indexed for 0.1.0 yet. The tag is recorded, its shard.yml has not been read, so the manifest and dependency list below are empty because they are unknown rather than because they are absent.
Installation
# Add this to your shard.yml
dependencies:
decorator:
github: LuckyCasts/decorator
version: ~> 0.1.0Then run:
shards installshard.yml
No shard.yml has been indexed for 0.1.0. You can read it on the repository.
Dependencies
Unknown: the shard.yml for this version has not been read yet.
README
This README is the one indexed from the repository at its latest ref, not from the tag for this version.
# Decorator

[](https://stephendolan.github.io/decorator)
[](https://github.com/stephendolan/decorator/releases)
A simple [Crystal](https://crystal-lang.org) shard for decorating objects.
## Installation
Add the dependency to your `shard.yml`:
```yaml
dependencies:
decorator:
github: stephendolan/decorator
```
Run `shards install`
## 🎬 Screencast
<a href="https://luckycasts.com/videos/decorator-shard"><img src="https://i.imgur.com/1gs4z0c.jpg" title="Decorating Lucky Apps with the Decorator Shard" width="500" /></a>
[Watch a LuckyCast on the Decorator shard](https://luckycasts.com/videos/decorator-shard)
## Usage
Require the shard:
```crystal
require "decorator"
```
Create a decorator `Struct` that inherits from `Decorator::Base`, and define
what it `decorates`:
```crystal
struct TimeDecorator < Decorator::Base
decorates time : Time
# Return a pretty version of a date and weekday in the format:
# `Monday, November 2, 2020`
def date_with_weekday : String
time.to_s("%A, %B %-d, %Y")
end
# Return a pretty version of a date in the format:
# `November 2, 2020`
def date : String
time.to_s("%B %-d, %Y")
end
end
```
In the above example, `Decorator` adds the following to the `TimeDecorator`
struct for you:
- An `initialize(@time : Time)` method
- A `collection(objects : Array(Time))` class method
- A `getter` (or `getter?` for `Bool` types) for `@time`
Now, you're able to transform `Time` objects using the decorator:
```crystal
decorated_time = TimeDecorator.new(Time.utc)
puts decorated_time.date_with_weekday
# => "Monday, November 2, 2020"
puts decorated_time.date
# => "November 2, 2020"
```
Or even a collection of time objects with the `collection` method:
```crystal
decorated_times = TimeDecorator.collection([
Time.utc - 1.year,
Time.utc,
Time.utc + 1.year
])
puts decorated_times[0].date_with_weekday
# => "Saturday, November 2, 2019"
puts decorated_times[1].date_with_weekday
# => "Monday, November 2, 2020"
puts decorated_times[2].date_with_weekday
# => "Tuesday, November 2, 2021"
```
## Contributing
1. [Fork it](https://github.com/stephendolan/decorator/fork)
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
## Contributors
- [Stephen Dolan](https://github.com/stephendolan) - creator and maintainer
## Inspiration
- 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.
Documentation
Built from the current release. The first visit to a release nobody has asked for starts its build.
Links
This release
- Version
0.1.0- Tagged
- Nov 24, 2025
- Commit
66adb9806a49- Indexed
- not yet
Dependents
No indexed shard depends on this one yet.
Repository
github.com/LuckyCasts/decorator
Metadata
- Created
- Aug 13, 2026
- Updated
- Aug 13, 2026
- Synced
- Aug 13, 2026
- Versions
- 5