Commit b0ff157

mo khan <mo@mokhan.ca>
2026-03-23 20:23:24
refactor: delegate to #command_for
1 parent 88e3efe
Changed files (2)
lib
spec
lib/elelem/commands.rb
@@ -12,13 +12,13 @@ module Elelem
     end
 
     def call(args)
+      @handler.arity == 0 ? @handler.call : @handler.call(args)
     end
   end
 
   class Commands
     include Enumerable
 
-
     def initialize(registry = {})
       @registry = registry
     end
@@ -28,10 +28,10 @@ module Elelem
     end
 
     def command_for(name)
-      hash = @registry[name]
-      return if hash.nil?
+      item = @registry[name]
+      return unless item
 
-      SlashCommand.new(name, description: hash[:description], completions: hash[:completions], handler: hash[:handler])
+      SlashCommand.new(name, description: item[:description], completions: item[:completions], handler: item[:handler])
     end
 
     def completions_for(name, partial = "")
@@ -43,10 +43,10 @@ module Elelem
     end
 
     def run(name, args = nil)
-      entry = @registry[name]
-      return false unless entry
+      command = command_for(name)
+      return false unless command
 
-      entry[:handler].arity == 0 ? entry[:handler].call : entry[:handler].call(args)
+      command.call(args)
       true
     end
 
spec/elelem/commands_spec.rb
@@ -61,11 +61,11 @@ RSpec.describe Elelem::Commands do
   describe "#run" do
     it "returns true when command exists" do
       commands.register("test") { }
-      expect(commands.run("test")).to be true
+      expect(commands.run("test")).to be(true)
     end
 
     it "returns false when command does not exist" do
-      expect(commands.run("nonexistent")).to be false
+      expect(commands.run("nonexistent")).to be(false)
     end
   end