Class: PryKeybind
- Inherits:
-
Object
- Object
- PryKeybind
- Defined in:
- lib/version.rb,
lib/pry-keybind.rb
Defined Under Namespace
Classes: InputState, KeySequence
Constant Summary collapse
- VERSION =
"0.0.6"
Class Attribute Summary collapse
-
.bound ⇒ Object
Returns the value of attribute bound.
-
.layers ⇒ Object
Returns the value of attribute layers.
-
.registry ⇒ Object
Returns the value of attribute registry.
Instance Attribute Summary collapse
-
#pry_instance ⇒ Object
Returns the value of attribute pry_instance.
Class Method Summary collapse
- .bind_all!(pry, source: nil) ⇒ Object
- .register(constant, key, options = {}, &block) ⇒ Object
- .register_anonymous(key, options = {}, &block) ⇒ Object
- .unbind_all!(pry_instance, source: nil) ⇒ Object
Instance Method Summary collapse
- #bind! ⇒ Object
-
#initialize(key, options = {}, &block) ⇒ PryKeybind
constructor
A new instance of PryKeybind.
- #unbind! ⇒ Object
Constructor Details
#initialize(key, options = {}, &block) ⇒ PryKeybind
Returns a new instance of PryKeybind.
48 49 50 51 52 53 54 55 |
# File 'lib/pry-keybind.rb', line 48 def initialize(key, = {}, &block) raise ArgumentError, "block required" unless block_given? = @key = KeySequence.new(key) @block = block @bound = false end |
Class Attribute Details
.bound ⇒ Object
Returns the value of attribute bound.
8 9 10 |
# File 'lib/pry-keybind.rb', line 8 def bound @bound end |
.layers ⇒ Object
Returns the value of attribute layers.
7 8 9 |
# File 'lib/pry-keybind.rb', line 7 def layers @layers end |
.registry ⇒ Object
Returns the value of attribute registry.
6 7 8 |
# File 'lib/pry-keybind.rb', line 6 def registry @registry end |
Instance Attribute Details
#pry_instance ⇒ Object
Returns the value of attribute pry_instance.
11 12 13 |
# File 'lib/pry-keybind.rb', line 11 def pry_instance @pry_instance end |
Class Method Details
.bind_all!(pry, source: nil) ⇒ Object
27 28 29 30 31 32 33 34 |
# File 'lib/pry-keybind.rb', line 27 def self.bind_all!(pry, source: nil) @bound = true # puts "binding / layer size?: #{layers.size} / source: #{source}" layers << [*registry.values].map do |key_binding| key_binding.pry_instance = pry key_binding.bind! end.compact end |
.register(constant, key, options = {}, &block) ⇒ Object
16 17 18 19 20 |
# File 'lib/pry-keybind.rb', line 16 def self.register(constant, key, = {}, &block) self.registry ||= {} self.layers ||= [] self.registry[constant] = new(key, , &block) end |
.register_anonymous(key, options = {}, &block) ⇒ Object
22 23 24 25 |
# File 'lib/pry-keybind.rb', line 22 def self.register_anonymous(key, = {}, &block) constant = format("BINDING_%09d", Random.random_number(1_000_000_000)).to_sym register(constant, key, , &block) end |
.unbind_all!(pry_instance, source: nil) ⇒ Object
36 37 38 39 40 41 42 43 44 45 |
# File 'lib/pry-keybind.rb', line 36 def self.unbind_all!(pry_instance, source: nil) # puts "unbinding / layer size?: #{layers.size} / source: #{source}" return unless layer = layers.pop @bound = false layer.each do |key_binding| key_binding.pry_instance = pry_instance key_binding.unbind! end end |
Instance Method Details
#bind! ⇒ Object
57 58 59 60 61 62 63 64 65 |
# File 'lib/pry-keybind.rb', line 57 def bind! return nil if bound? Pryline.public_send(bind_method, key.for_readline, &block_caller) @bound = true self end |
#unbind! ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/pry-keybind.rb', line 67 def unbind! return self unless bound? Pryline.public_send(unbind_method, key.for_readline) @bound = false self end |