From 8308ffd44fb238216a1ba086a21c8c4ca65b32c9 Mon Sep 17 00:00:00 2001 From: Stephen Dolan Date: Tue, 13 Apr 2021 11:49:28 -0400 Subject: [PATCH] Move from classes to structs (#2) --- .github/workflows/docs.yml | 8 ++++---- .github/workflows/shard.yml | 7 +++++-- README.md | 12 +++++------- shard.yml | 2 +- spec/decorator_spec.cr | 2 +- src/decorator.cr | 1 + src/decorator/base.cr | 8 ++++---- src/decorator/version.cr | 3 --- 8 files changed, 21 insertions(+), 22 deletions(-) delete mode 100644 src/decorator/version.cr diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index bd3c779..2e0f0fd 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -1,9 +1,9 @@ name: Deploy documentation on: - push: - branches: - - main + workflow_dispatch: + release: + types: [published] jobs: deploy: @@ -21,7 +21,7 @@ jobs: run: shards install --ignore-crystal-version - name: "Generate docs" - run: crystal docs + run: crystal docs --project-name=Decorator --project-version=${GITHUB_REF##*/} - name: Deploy to GitHub Pages uses: peaceiris/actions-gh-pages@v3 diff --git a/.github/workflows/shard.yml b/.github/workflows/shard.yml index 3b1b74f..126cacc 100644 --- a/.github/workflows/shard.yml +++ b/.github/workflows/shard.yml @@ -25,11 +25,14 @@ jobs: runs-on: ubuntu-latest continue-on-error: ${{ matrix.experimental }} - container: crystallang/crystal:${{ matrix.crystal_version }}-alpine steps: - uses: actions/checkout@v2 + - uses: oprypin/install-crystal@v1 + with: + crystal: ${{matrix.crystal_version}} + - name: Check format run: crystal tool format --check @@ -49,7 +52,7 @@ jobs: if: steps.crystal-cache.outputs.cache-hit != 'true' run: shards check || shards install --ignore-crystal-version - - name: Crystal Ameba Linter + - name: Run Ameba static code analysis run: ./bin/ameba - name: Run tests diff --git a/README.md b/README.md index bc9fe93..17e5e28 100644 --- a/README.md +++ b/README.md @@ -20,11 +20,9 @@ Run `shards install` ## 🎬 Screencast -
- -
+ -[Watch Screencast](https://luckycasts.com/videos/decorator-shard) +[Watch a LuckyCast on the Decorator shard](https://luckycasts.com/videos/decorator-shard) ## Usage @@ -34,10 +32,10 @@ Require the shard: require "decorator" ``` -Create a decorator that inherits from Decorator::Base, and tell the decorator what it `decorates` to decorate: +Create a decorator `Struct` that inherits from `Decorator::Base`, and define what it `decorates`: ```crystal -class TimeDecorator < Decorator::Base +struct TimeDecorator < Decorator::Base decorates time : Time # Return a pretty version of a date and weekday in the format: @@ -54,7 +52,7 @@ class TimeDecorator < Decorator::Base end ``` -In the above example, `Decorator` adds the following to the `TimeDecorator` class for you: +In the above example, `Decorator` adds the following to the `TimeDecorator` struct for you: - An `initialize(@time : Time)` method - A `getter` (or `getter?` for `Bool` types) for `@time` diff --git a/shard.yml b/shard.yml index 7e61fa2..2d59b43 100644 --- a/shard.yml +++ b/shard.yml @@ -1,6 +1,6 @@ name: decorator description: A simple object decoration library for Crystal apps -version: 0.3.0 +version: 1.0.0 authors: - Stephen Dolan diff --git a/spec/decorator_spec.cr b/spec/decorator_spec.cr index 0051349..cca24e1 100644 --- a/spec/decorator_spec.cr +++ b/spec/decorator_spec.cr @@ -14,7 +14,7 @@ class User end end -class UserDecorator < Decorator::Base +struct UserDecorator < Decorator::Base decorates user : User def full_name diff --git a/src/decorator.cr b/src/decorator.cr index 851882e..601597e 100644 --- a/src/decorator.cr +++ b/src/decorator.cr @@ -2,4 +2,5 @@ require "./decorator/*" # Decorator provides a simple interface to decorate an object with additional functionality. module Decorator + VERSION = {{ `shards version "#{__DIR__}"`.chomp.stringify }} end diff --git a/src/decorator/base.cr b/src/decorator/base.cr index 046ca39..eadb911 100644 --- a/src/decorator/base.cr +++ b/src/decorator/base.cr @@ -1,4 +1,4 @@ -class Decorator::Base +abstract struct Decorator::Base # Keep track of how many `decorates` statements have been provided so that we can limit to 1. macro inherited DECORATOR_ASSIGNS = [] of Nil @@ -8,15 +8,15 @@ class Decorator::Base # # Currently, you can only supply **one** `decorates` statement per decorator that inherits from `Decorator::Base`. # - # Given a decorator class like this: + # Given a decorator struct like this: # # ``` - # class TimeDecorator < Decorator::Base + # struct TimeDecorator < Decorator::Base # decorates time : Time # end # ``` # - # The following items are made available to the `TimeDecorator` class: + # The following items are made available to the `TimeDecorator` struct: # # - An `initialize(@time : Time)` method # - A `getter` (or `getter?` for `Bool` types) for `@time` diff --git a/src/decorator/version.cr b/src/decorator/version.cr deleted file mode 100644 index fa710a3..0000000 --- a/src/decorator/version.cr +++ /dev/null @@ -1,3 +0,0 @@ -module Decorator - VERSION = {{ `shards version "#{__DIR__}"`.chomp.stringify }} -end