From a124cd79d06d03f1fe8525fd18c75a4642bf4ee2 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Tue, 10 Mar 2026 17:11:06 -0700 Subject: [PATCH 1/2] Just leanred that I've had a typo in this repo... also updating everything to be latest stuff --- .ameba.yml | 14 ++++++++++++++ .github/workflows/ci.yml | 16 +++++++++------- .github/workflows/docs.yml | 4 ++-- shard.yml | 8 ++++---- spec/stores/memory_store_spec.cr | 12 ++++++------ spec/stores/null_store_spec.cr | 8 ++++---- src/lucky_cache.cr | 4 ++-- src/lucky_cache/cache_item.cr | 4 ++-- src/lucky_cache/{cachable.cr => cacheable.cr} | 2 +- src/lucky_cache/html_helpers.cr | 2 +- src/lucky_cache/stores/memory_store.cr | 10 +++++----- 11 files changed, 50 insertions(+), 34 deletions(-) create mode 100644 .ameba.yml rename src/lucky_cache/{cachable.cr => cacheable.cr} (68%) diff --git a/.ameba.yml b/.ameba.yml new file mode 100644 index 0000000..f0d07b1 --- /dev/null +++ b/.ameba.yml @@ -0,0 +1,14 @@ +# This configuration file was generated by `ameba --gen-config` +# on 2026-03-11 00:06:56 UTC using Ameba version 1.6.4. +# The point is for the user to remove these configuration records +# one by one as the reported problems are removed from the code base. + +# Problems found: 2 +# Run `ameba --only Lint/UselessAssign` for details +Lint/UselessAssign: + Description: Disallows useless variable assignments + ExcludeTypeDeclarations: false + Excluded: + - src/lucky_cache.cr + Enabled: true + Severity: Warning diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 31c7a5e..45aeb37 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: continue-on-error: false steps: - name: Download source - uses: actions/checkout@v3 + uses: actions/checkout@v6 - name: Install Crystal uses: crystal-lang/install-crystal@v1 - name: Install shards @@ -27,15 +27,17 @@ jobs: strategy: fail-fast: false matrix: - os: [ubuntu-latest, windows-latest] - crystal_version: [latest] - include: - - os: ubuntu-latest - crystal_version: 1.4.0 + os: + - ubuntu-latest + - macos-latest + - windows-latest + crystal_version: + - 1.16.3 + - latest runs-on: ${{ matrix.os }} continue-on-error: false steps: - - uses: actions/checkout@v3 + - uses: actions/checkout@v6 - uses: crystal-lang/install-crystal@v1 with: crystal: ${{ matrix.crystal_version }} diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml index 450bb30..ea98271 100644 --- a/.github/workflows/docs.yml +++ b/.github/workflows/docs.yml @@ -8,7 +8,7 @@ jobs: deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v2 + - uses: actions/checkout@v6 with: persist-credentials: false - uses: crystal-lang/install-crystal@v1 @@ -17,7 +17,7 @@ jobs: - name: "Generate docs" run: crystal docs - name: Deploy to GitHub Pages - uses: peaceiris/actions-gh-pages@v3 + uses: peaceiris/actions-gh-pages@v4 with: github_token: ${{ secrets.GITHUB_TOKEN }} publish_dir: ./docs diff --git a/shard.yml b/shard.yml index 77c9fce..36c9813 100644 --- a/shard.yml +++ b/shard.yml @@ -4,7 +4,7 @@ version: 0.1.1 authors: - Jeremy Woertink -crystal: ">= 1.4.0" +crystal: ">= 1.16.0" license: MIT @@ -13,12 +13,12 @@ dependencies: github: wyhaines/splay_tree_map.cr habitat: github: luckyframework/habitat - version: ~> 0.4.7 + version: ~> 0.4.9 development_dependencies: timecop: github: crystal-community/timecop.cr - branch: master + version: ~> 0.6.0 ameba: github: crystal-ameba/ameba - version: ~> 1.0.0 + version: ~> 1.6.4 diff --git a/spec/stores/memory_store_spec.cr b/spec/stores/memory_store_spec.cr index a1e1e63..a46aafb 100644 --- a/spec/stores/memory_store_spec.cr +++ b/spec/stores/memory_store_spec.cr @@ -1,7 +1,7 @@ require "../spec_helper" class User - include LuckyCache::Cachable + include LuckyCache::Cacheable property email : String def initialize(@email : String) @@ -9,7 +9,7 @@ class User end class Post - include LuckyCache::Cachable + include LuckyCache::Cacheable property title : String def initialize(@title : String) @@ -49,7 +49,7 @@ describe LuckyCache::MemoryStore do result.should be_a(Array(User)) counter.should eq(1) - friends = result.not_nil! + friends = result.as(Array(User)) friends.size.should eq(2) friends.map(&.email).should contain("chris@email.net") end @@ -68,7 +68,7 @@ describe LuckyCache::MemoryStore do result.should be_a(Array(Post)) counter.should eq(1) - friends = result.not_nil! + friends = result.as(Array(Post)) friends.size.should eq(2) friends.map(&.title).should contain("learn about cash") end @@ -93,10 +93,10 @@ describe LuckyCache::MemoryStore do UUID.random end Timecop.travel(12.hours.from_now) do - cache.read("coupon").not_nil!.expired?.should eq(false) + cache.read("coupon").as(LuckyCache::CacheItem).expired?.should eq(false) end Timecop.travel(35.hours.from_now) do - cache.read("coupon").not_nil!.expired?.should eq(false) + cache.read("coupon").as(LuckyCache::CacheItem).expired?.should eq(false) end Timecop.travel(49.hours.from_now) do cache.read("coupon").should eq(nil) diff --git a/spec/stores/null_store_spec.cr b/spec/stores/null_store_spec.cr index f96bf0a..39b8667 100644 --- a/spec/stores/null_store_spec.cr +++ b/spec/stores/null_store_spec.cr @@ -1,7 +1,7 @@ require "../spec_helper" class User - include LuckyCache::Cachable + include LuckyCache::Cacheable property email : String def initialize(@email : String) @@ -9,7 +9,7 @@ class User end class Post - include LuckyCache::Cachable + include LuckyCache::Cacheable property title : String def initialize(@title : String) @@ -49,7 +49,7 @@ describe LuckyCache::NullStore do result.should be_a(Array(User)) counter.should eq(2) - friends = result.not_nil! + friends = result.as(Array(User)) friends.size.should eq(2) friends.map(&.email).should contain("chris@email.net") end @@ -68,7 +68,7 @@ describe LuckyCache::NullStore do result.should be_a(Array(Post)) counter.should eq(2) - friends = result.not_nil! + friends = result.as(Array(Post)) friends.size.should eq(2) friends.map(&.title).should contain("learn about cash") end diff --git a/src/lucky_cache.cr b/src/lucky_cache.cr index 636b9e6..f7aa692 100644 --- a/src/lucky_cache.cr +++ b/src/lucky_cache.cr @@ -2,7 +2,7 @@ require "splay_tree_map" require "habitat" require "uuid" require "json" -require "./lucky_cache/cachable" +require "./lucky_cache/cacheable" require "./lucky_cache/cache_item" require "./lucky_cache/stores/*" require "./lucky_cache/*" @@ -15,5 +15,5 @@ module LuckyCache setting default_duration : Time::Span = 1.minute end - alias CachableTypes = Cachable | Array(Cachable) | String | Array(String) | Int32 | Array(Int32) | Int64 | Array(Int64) | Float64 | Array(Float64) | Bool | Array(Bool) | Time | UUID | JSON::Any + alias CacheableTypes = Cacheable | Array(Cacheable) | String | Array(String) | Int32 | Array(Int32) | Int64 | Array(Int64) | Float64 | Array(Float64) | Bool | Array(Bool) | Time | UUID | JSON::Any end diff --git a/src/lucky_cache/cache_item.cr b/src/lucky_cache/cache_item.cr index 0965138..8697b45 100644 --- a/src/lucky_cache/cache_item.cr +++ b/src/lucky_cache/cache_item.cr @@ -1,10 +1,10 @@ module LuckyCache struct CacheItem - getter value : CachableTypes + getter value : CacheableTypes getter expires_in : Time::Span private getter expiration : Time - def initialize(@value : CachableTypes, @expires_in : Time::Span) + def initialize(@value : CacheableTypes, @expires_in : Time::Span) @expiration = @expires_in.from_now end diff --git a/src/lucky_cache/cachable.cr b/src/lucky_cache/cacheable.cr similarity index 68% rename from src/lucky_cache/cachable.cr rename to src/lucky_cache/cacheable.cr index 85c5e71..5b73228 100644 --- a/src/lucky_cache/cachable.cr +++ b/src/lucky_cache/cacheable.cr @@ -1,3 +1,3 @@ # Include this module in the custom types you want to cache -module LuckyCache::Cachable +module LuckyCache::Cacheable end diff --git a/src/lucky_cache/html_helpers.cr b/src/lucky_cache/html_helpers.cr index 1d769cb..ba7f5dc 100644 --- a/src/lucky_cache/html_helpers.cr +++ b/src/lucky_cache/html_helpers.cr @@ -8,7 +8,7 @@ module LuckyCache::HtmlHelpers # end # end # ``` - def cache(key, *, expires_in : Time::Span?) + def cache(key, *, expires_in : Time::Span?, &) cache = LuckyCache.settings.storage expires = expires_in || LuckyCache.settings.default_duration diff --git a/src/lucky_cache/stores/memory_store.cr b/src/lucky_cache/stores/memory_store.cr index ed9a9d8..0f45a86 100644 --- a/src/lucky_cache/stores/memory_store.cr +++ b/src/lucky_cache/stores/memory_store.cr @@ -19,8 +19,8 @@ module LuckyCache data = yield if data.is_a?(Array) - stored_data = [] of Cachable - data.each { |d| stored_data << d } + stored_data = [] of Cacheable + data.each { |datum| stored_data << datum } else stored_data = data end @@ -43,20 +43,20 @@ module LuckyCache cache.clear end - # If the `CacheItem` exists, it will map the `Array(Cachable)` + # If the `CacheItem` exists, it will map the `Array(Cacheable)` # in to `Array(T)`. If no item is found, write the block value # and return the block value def fetch(key : CacheKey, *, as : Array(T).class, expires_in : Time::Span = LuckyCache.settings.default_duration, &) forall T if cache_item = read(key) new_array = Array(T).new - cache_item.value.as(Array(LuckyCache::Cachable)).each { |v| new_array << v.as(T) } + cache_item.value.as(Array(LuckyCache::Cacheable)).each { |v| new_array << v.as(T) } new_array else write(key, expires_in: expires_in) { yield } end end - # If the `CacheItem` exists, it will cast the `Cachable` + # If the `CacheItem` exists, it will cast the `Cacheable` # in to `T`. If no item is found, write the block value # and return the block value def fetch(key : CacheKey, *, as : T.class, expires_in : Time::Span = LuckyCache.settings.default_duration, &) forall T From 8d25aebc398706f77737f9b590324b3b76e94b26 Mon Sep 17 00:00:00 2001 From: Jeremy Date: Tue, 10 Mar 2026 17:17:00 -0700 Subject: [PATCH 2/2] Downgrade Timecop until we require Crystal 1.19 as a minimum --- shard.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shard.yml b/shard.yml index 36c9813..0b560e8 100644 --- a/shard.yml +++ b/shard.yml @@ -18,7 +18,7 @@ dependencies: development_dependencies: timecop: github: crystal-community/timecop.cr - version: ~> 0.6.0 + version: ~> 0.5.0 ameba: github: crystal-ameba/ameba version: ~> 1.6.4