Class: Pry::BondCompleter

Inherits:
Object
  • Object
show all
Defined in:
lib/salad/bond_completer.rb

Class Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(input, pry = nil) ⇒ BondCompleter

Returns a new instance of BondCompleter.



80
81
82
83
# File 'lib/salad/bond_completer.rb', line 80

def initialize(input, pry = nil)
  @pry = pry
  @input = input
end

Class Attribute Details

.bondObject (readonly)

Returns the value of attribute bond.



55
56
57
# File 'lib/salad/bond_completer.rb', line 55

def bond
  @bond
end

Class Method Details

.setup(config = {}) ⇒ Object



58
59
60
61
62
63
64
65
66
# File 'lib/salad/bond_completer.rb', line 58

def self.setup(config = {})
  @lock ||= Mutex.new
  return if @bond

  @bond = Bond::M
  @bond.config.merge!(config)
  @current_pry_instance = nil
  # Don't call start here - Bond will initialize when needed
end

.with_pry(instance) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
# File 'lib/salad/bond_completer.rb', line 68

def self.with_pry(instance)
  @lock ||= Mutex.new
  @lock.synchronize do
    begin
      @current_pry_instance = instance
      yield
    ensure
      @current_pry_instance = nil
    end
  end
end

Instance Method Details

#call(str, _options) ⇒ Object



85
86
87
88
89
90
91
# File 'lib/salad/bond_completer.rb', line 85

def call(str, _options)
  Pry::BondCompleter.setup if Pry::BondCompleter.bond.nil?

  Pry::BondCompleter.with_pry(@pry) do
    Pry::BondCompleter.bond.agent.call(str, get_full_line_input || str)
  end
end