Skip to content

Commit

Permalink
Fixes #24 arity check on procs is correct
Browse files Browse the repository at this point in the history
The issue wasn't just in MRI 1.9 p180.

Proc#arity returns the correct arity. Proc#method(:call)#arity returns
-1 in MRI.
  • Loading branch information
gruis committed Feb 4, 2012
1 parent 94538d5 commit 68175b3
Showing 1 changed file with 11 additions and 9 deletions.
20 changes: 11 additions & 9 deletions lib/pry-remote-em/server.rb
Original file line number Diff line number Diff line change
Expand Up @@ -65,16 +65,18 @@ def run(obj, host = DEFHOST, port = DEFPORT, opts = {:tls => false})
def initialize(opts = {:tls => false})
@after_auth = []
@opts = opts
if (a = opts[:auth])
if a.respond_to?(:call)
return fail("auth handler procs must take two arguments not (#{a.method(:call).arity})") unless a.method(:call).arity == 2
@auth = a
else
return error("auth handler objects must respond to :call, or :[]") unless a.respond_to?(:[])
@auth = lambda {|u,p| a[u] && a[u] == p }
end
@auth_tries = 5
return unless (a = opts[:auth])
if a.is_a?(Proc)
return fail("auth handler Procs must take two arguments not (#{a.arity})") unless a.arity == 2
@auth = a
elsif a.respond_to?(:call)
return fail("auth handler must take two arguments not (#{a.method(:call).arity})") unless a.method(:call).arity == 2
@auth = a
else
return error("auth handler objects must respond to :call, or :[]") unless a.respond_to?(:[])
@auth = lambda {|u,p| a[u] && a[u] == p }
end
@auth_tries = 5
end

def post_init
Expand Down

0 comments on commit 68175b3

Please sign in to comment.