Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make detail tuples typed-ish #837

Open
wants to merge 15 commits into
base: main
Choose a base branch
from
Prev Previous commit
Next Next commit
Fix Number handling
spuun committed Dec 5, 2024
commit c836a675adf6fa18f881b144ef956c81b6fa527f
3 changes: 2 additions & 1 deletion spec/metadata_spec.cr
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
require "./spec_helper"

module LavinMQ
struct Metadata(T)
struct NamedTupleMetadata(T) < Metadata
describe Value do
describe "compare" do
{% begin %}
@@ -17,6 +17,7 @@ module LavinMQ
{nil, nil, 0},
{1, "a", -1},
{"a", 1, 1},
{1u8, 2i32, -1},
}
%}
{% for values in testdata %}
1 change: 1 addition & 0 deletions src/lavinmq/data_dir_lock.cr
Original file line number Diff line number Diff line change
@@ -14,6 +14,7 @@ module LavinMQ
def acquire
begin
@lock.flock_exclusive(blocking: false)
Log.debug { "Data directory lock acquired" }
rescue
Log.info { "Data directory locked by '#{@lock.gets_to_end}'" }
Log.info { "Waiting for file lock to be released" }
17 changes: 10 additions & 7 deletions src/lavinmq/metadata.cr
Original file line number Diff line number Diff line change
@@ -29,23 +29,26 @@ module LavinMQ
@value
end

def <=>(other : Value)
def <=>(other : Value(T2)) forall T2
return 0 if @value.nil? && other.@value.nil?
return -1 if @value.nil?
return 1 if other.@value.nil?

if Number === @value === other.@value
return @value <=> other.@value
end
{% if T <= Number && T2 <= Number %}
if other_value = other.@value
return @value <=> other_value
end
{% end %}

if self.type != other.type
return @value.to_s <=> other.@value.to_s
end

if (value = @value) && (other_value = other.@value.as?(T))
if value.is_a?(Comparable)
{% if T <= Comparable %}
if (value = @value) && (other_value = other.@value.as?(T))
return value <=> other_value
end
end
{% end %}

return 0
end