Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 7 additions & 1 deletion .github/workflows/linters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 1 addition & 1 deletion .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 2 additions & 2 deletions shard.lock
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ 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
version: 0.14.0

redis:
git: https://github.com/jgaskins/redis.git
version: 0.15.1
version: 0.15.3

4 changes: 2 additions & 2 deletions shard.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ authors:
- Florin Lipan <florinlipan@gmail.com>
- Rodrigo Pinto <contato@rodrigopinto.me>

crystal: "1.0.0, < 2.0.0"
crystal: ">= 1.0.0, < 2.0.0"

dependencies:
redis:
Expand All @@ -15,4 +15,4 @@ dependencies:
development_dependencies:
ameba:
github: crystal-ameba/ameba
version: ~> 1.5.0
version: ~> 1.7.0
2 changes: 1 addition & 1 deletion src/defense/memory_store.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
8 changes: 4 additions & 4 deletions src/defense/redis_store.cr
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,17 @@ 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

def exists?(unprefixed_key : String) : Bool
@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

Expand Down
2 changes: 1 addition & 1 deletion src/defense/store.cr
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down