class Fir::KeyCommand
Attributes
character[R]
state[R]
Public Class Methods
build(character, state)
click to toggle source
# File lib/fir/key_command/key_command.rb, line 9 def self.build(character, state) find(character).new(character, state) end
character_regex()
click to toggle source
# File lib/fir/key_command/key_command.rb, line 35 def self.character_regex /.*/ end
for(character, state)
click to toggle source
# File lib/fir/key_command/key_command.rb, line 13 def self.for(character, state) registry.find do |candidate| candidate.handles?(character) end.new(character, state) end
handles?(character)
click to toggle source
# File lib/fir/key_command/key_command.rb, line 31 def self.handles?(character) Array(character_regex).any? { |re| re.match(character) } end
inherited(candidate)
click to toggle source
# File lib/fir/key_command/key_command.rb, line 27 def self.inherited(candidate) register(candidate) end
new(character, state)
click to toggle source
# File lib/fir/key_command/key_command.rb, line 39 def initialize(character, state) @character = character @state = state end
register(candidate)
click to toggle source
# File lib/fir/key_command/key_command.rb, line 23 def self.register(candidate) registry.unshift(candidate) end
registry()
click to toggle source
# File lib/fir/key_command/key_command.rb, line 19 def self.registry @registry ||= [KeyCommand] end
Public Instance Methods
execute()
click to toggle source
# File lib/fir/key_command/key_command.rb, line 44 def execute execute_hook(state.clone) end
execute_hook(new_state)
click to toggle source
# File lib/fir/key_command/key_command.rb, line 48 def execute_hook(new_state) new_state end