Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I stop a pry.binding conditionally on a symbol or string?

I have a rails app running and I am placing binding.pry within a method that is called a lot. I want to stop on a specific string on symbol, but I cannot find the syntax. Here is my code:

  def can?(resource, operation, options={})
    binding.pry
    credentials(options[:as]).each do |credential|
      can = credential.can?(resource, operation, options)
      return can unless can.nil?
    end
    nil
  end

I see in the docs about the break keyword, but I can't seem to make that work either. Could someone please show me what the syntax is supposed to be?

like image 252
jhamm Avatar asked Dec 25 '22 03:12

jhamm


1 Answers

You can just add an if

def can?(resource, operation, options={})
  binding.pry if your_condition_is_met
  credentials(options[:as]).each do |credential|
    can = credential.can?(resource, operation, options)
    return can unless can.nil?
  end
  nil
end
like image 59
Fer Avatar answered May 16 '23 08:05

Fer