Skip to content

Commit

Permalink
enums without .new
Browse files Browse the repository at this point in the history
  • Loading branch information
malakai97 committed Dec 6, 2023
1 parent e78ec65 commit 463b8ec
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 28 deletions.
2 changes: 1 addition & 1 deletion lauth/lib/lauth/determination/allowed.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Allowed < Base

ALLOWED = "allowed"

def type
def self.type
ALLOWED
end

Expand Down
36 changes: 21 additions & 15 deletions lauth/lib/lauth/determination/base.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,27 +2,33 @@ module Lauth
module Determination
class Base

def type
raise NotImplementedError
end
class << self
def type
raise NotImplementedError
end

def eql?(other)
type == other.to_s
end
alias == eql?
def eql?(other)
type == other.to_s
end
alias == eql?

def to_s
to_str
end
def to_s
to_str
end

def to_str
type
end
def to_str
type
end

def inspect
to_s
def inspect
to_s
end
end

private

def new; end

end
end
end
2 changes: 1 addition & 1 deletion lauth/lib/lauth/determination/denied.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ class Denied < Base

DENIED = "denied"

def type
def self.type
DENIED
end

Expand Down
4 changes: 2 additions & 2 deletions lauth/lib/lauth/ops/authorize.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ def self.call(request:)

def call
determination = if grant_repo.for_user_and_uri(request.user, request.uri).any?
Determination::Allowed.new
Determination::Allowed
else
Determination::Denied.new
Determination::Denied
end
Lauth::Access::Result.new(determination:)
end
Expand Down
8 changes: 2 additions & 6 deletions lauth/spec/determination_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,6 @@
expect(determination).to eq string.to_sym
end

it "equals itself" do
expect(determination).to eq determination.class.new
end

it "prints as a string" do
expect(determination.to_s).to eql string
end
Expand All @@ -24,12 +20,12 @@
end

describe Lauth::Determination::Allowed do
let(:determination) { Lauth::Determination::Allowed.new }
let(:determination) { Lauth::Determination::Allowed}
include_examples "a determination", "allowed"
end

describe Lauth::Determination::Denied do
let(:determination) { Lauth::Determination::Denied.new }
let(:determination) { Lauth::Determination::Denied}
include_examples "a determination", "denied"
end

Expand Down
4 changes: 2 additions & 2 deletions lauth/spec/ops/authorize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@

result = Lauth::Ops::Authorize.call(request: request)

expect(result.determination).to eq Lauth::Determination::Denied.new
expect(result.determination).to eq Lauth::Determination::Denied
end
end

Expand All @@ -38,7 +38,7 @@

result = Lauth::Ops::Authorize.new(request: request).call

expect(result.determination).to eq Lauth::Determination::Allowed.new
expect(result.determination).to eq Lauth::Determination::Allowed
end
end
end
2 changes: 1 addition & 1 deletion lauth/spec/requests/authorized_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
get "/authorized", {user: "lauth-allowed", uri: "/restricted-by-username/"}
body = JSON.parse(last_response.body, symbolize_names: true)

expect(body).to eq({determination: Lauth::Determination::Allowed.new})
expect(body).to eq({determination: Lauth::Determination::Allowed})
end
end
end

0 comments on commit 463b8ec

Please sign in to comment.