diff --git a/.github/workflows/linters.yml b/.github/workflows/linters.yml index 56ef7bc..cd6f8ea 100644 --- a/.github/workflows/linters.yml +++ b/.github/workflows/linters.yml @@ -27,7 +27,13 @@ jobs: restore-keys: ${{ runner.os }}-shards- - name: Install shards - run: shards update + run: shards install + + - name: Set up bin dir + run: mkdir -p bin + + - name: Build ameba + run: crystal build -o bin/ameba lib/ameba/bin/ameba.cr - name: Run linter run: bin/ameba diff --git a/.github/workflows/tests.yml b/.github/workflows/tests.yml index b155602..83e1c23 100644 --- a/.github/workflows/tests.yml +++ b/.github/workflows/tests.yml @@ -37,7 +37,7 @@ jobs: restore-keys: ${{ runner.os }}-shards- - name: Install shards - run: shards update + run: shards install - name: Run tests run: crystal spec --verbose diff --git a/README.md b/README.md index 01b6b08..20f3720 100644 --- a/README.md +++ b/README.md @@ -305,6 +305,18 @@ Format the code: crystal tool format ``` +Build ameba: + +``` +crystal build -o bin/ameba lib/ameba/bin/ameba.cr +``` + +Run ameba: + +``` +bin/ameba +``` + ### Guidelines - Keep the public interface small. Anything that doesn't have to be public, should explicitly be marked as protected or diff --git a/shard.lock b/shard.lock index 29bd507..7d59e41 100644 --- a/shard.lock +++ b/shard.lock @@ -2,7 +2,7 @@ version: 2.0 shards: ameba: git: https://github.com/crystal-ameba/ameba.git - version: 1.5.0 + version: 1.7.0 db: git: https://github.com/crystal-lang/crystal-db.git @@ -10,5 +10,5 @@ shards: redis: git: https://github.com/jgaskins/redis.git - version: 0.15.1 + version: 0.15.3 diff --git a/shard.yml b/shard.yml index bf2d7fd..41c85c7 100644 --- a/shard.yml +++ b/shard.yml @@ -5,7 +5,7 @@ authors: - Florin Lipan - Rodrigo Pinto -crystal: "1.0.0, < 2.0.0" +crystal: ">= 1.0.0, < 2.0.0" dependencies: redis: @@ -15,4 +15,4 @@ dependencies: development_dependencies: ameba: github: crystal-ameba/ameba - version: ~> 1.5.0 + version: ~> 1.7.0 diff --git a/src/defense/memory_store.cr b/src/defense/memory_store.cr index bbe8cee..02210cd 100644 --- a/src/defense/memory_store.cr +++ b/src/defense/memory_store.cr @@ -23,7 +23,7 @@ module Defense @data.has_key?(key) && @data[key]["expires_at"] > Time.utc.to_unix_ms end - def read(unprefixed_key : String) : Int64 | Nil + def read(unprefixed_key : String) : Int64? if exists?(unprefixed_key) @data[prefix_key(unprefixed_key)]["count"] end diff --git a/src/defense/redis_store.cr b/src/defense/redis_store.cr index 3dbd81e..cdb2444 100644 --- a/src/defense/redis_store.cr +++ b/src/defense/redis_store.cr @@ -18,9 +18,9 @@ module Defense def increment(unprefixed_key : String, expires_in : Int32) : Int64 key = prefix_key(unprefixed_key) - @redis.multi do |r| - r.incr(key) - r.expire(key, expires_in) + @redis.multi do |red| + red.incr(key) + red.expire(key, expires_in) end.as(Array).first.as(Int64) end @@ -28,7 +28,7 @@ module Defense @redis.exists(prefix_key(unprefixed_key)) == 1 end - def read(unprefixed_key : String) : Int64 | Nil + def read(unprefixed_key : String) : Int64? @redis.get(prefix_key(unprefixed_key)).try(&.to_i64) end diff --git a/src/defense/store.cr b/src/defense/store.cr index 9a46b66..bfbd345 100644 --- a/src/defense/store.cr +++ b/src/defense/store.cr @@ -2,7 +2,7 @@ module Defense abstract class Store abstract def exists?(unprefixed_key : String) : Bool abstract def increment(unprefixed_key : String, expires_in : Int32) : Int64 - abstract def read(unprefixed_key : String) : Int64 | Nil + abstract def read(unprefixed_key : String) : Int64? abstract def reset def prefix