Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class ApplicationController < ActionController::Base
private

def verify_agent!
@current_agent ||= Vestauth.provider.verify(http_method: request.method, uri: request.original_url, headers: request.headers)
@current_agent ||= Vestauth.tool.verify(http_method: request.method, uri: request.original_url, headers: request.headers)
rescue => e
render json: { error: { status: 401, code: 401, message: e.message } }, status: 401
end
Expand Down
6 changes: 5 additions & 1 deletion lib/vestauth.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,14 @@
module Vestauth
class Error < StandardError; end

def self.provider
def self.tool
Provider
end

class << self
alias provider tool
end

Comment on lines +12 to +19
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The alias provider tool keeps backward compatibility, but the current placement (class << self block separated from the def self.tool) is a bit indirect and can be confusing to maintain. Since this is a module with singleton methods, you can define the alias directly on the singleton class in a tighter, more idiomatic way, and ideally add a short deprecation note so callers know to migrate.

Also, if this is intended as a rename rather than a permanent dual API, consider emitting a deprecation warning from provider to drive adoption (while keeping it non-breaking).

Suggestion

Consider restructuring to make the relationship explicit and optionally deprecate the old name:

module Vestauth
  def self.tool
    Provider
  end

  class << self
    def provider
      warn "Vestauth.provider is deprecated; use Vestauth.tool" if $VERBOSE
      tool
    end
  end
end

This keeps compatibility while encouraging migration. Reply with "@CharlieHelps yes please" if you'd like me to add a commit with this suggestion.

def self.agent
Agent
end
Expand Down
9 changes: 5 additions & 4 deletions spec/vestauth_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,19 @@
expect(Vestauth::VERSION).not_to be nil
end

it "exposes namespaced provider and agent modules" do
it "exposes namespaced tool/provider and agent modules" do
expect(Vestauth.tool).to eq(Vestauth::Provider)
expect(Vestauth.provider).to eq(Vestauth::Provider)
expect(Vestauth.agent).to eq(Vestauth::Agent)
expect(Vestauth.binary).to eq(Vestauth::Binary)
end

it "delegates provider verify to binary provider_verify" do
it "delegates tool verify to binary provider_verify" do
binary = instance_double(Vestauth::Binary)
allow(Vestauth::Binary).to receive(:new).and_return(binary)
allow(binary).to receive(:provider_verify).and_return({ "uid" => "agent-123" })

result = Vestauth.provider.verify(
result = Vestauth.tool.verify(
http_method: "GET",
uri: "https://api.vestauth.com/whoami",
headers: {
Expand All @@ -41,7 +42,7 @@
allow(Vestauth::Binary).to receive(:new).and_return(binary)
allow(binary).to receive(:provider_verify).and_return({ "success" => false })

Vestauth.provider.verify(
Vestauth.tool.verify(
http_method: "GET",
uri: "https://api.vestauth.com/whoami",
headers: {}
Expand Down