Sha256: ec0a4923741717cca78ecdf1b49f6f2488b45bd5bf303d426441b81ad551570a
Contents?: true
Size: 1.91 KB
Versions: 1
Compression:
Stored size: 1.91 KB
Contents
module Vedeu # A Keymap is the binding of a keypress to one or more interfaces; or globally # to perform a client application defined action. # # @api private class Keymap include Common attr_reader :attributes # Define a keymap for an interface or interfaces to perform an action when # a key is pressed whilst an aforementioned interface is in focus. # # @param attributes [Hash] The attributes to register the keymap with. # @option attributes :interfaces [] # @option attributes :keys [] # @param block [Proc] # @return [Keymap] def self.define(attributes = {}, &block) new(attributes).define(&block) end # Instantiate a new instance of the Keymap model. # # @param attributes [Hash] # @return [Keymap] def initialize(attributes = {}) @attributes = defaults.merge!(attributes) end # Adds the attributes to the Keymaps repository. # # @param block [Proc] # @return [Interface] def define(&block) if block_given? @self_before_instance_eval = eval('self', block.binding) instance_eval(&block) end Keymaps.add(attributes) self end private # The default attributes of the Keymap model. # # @return [Hash] def defaults { interfaces: [], # the interface(s) which will respond to the keypress(es) keys: [], # the keypress/action pairs for this keymap } end # @param method [Symbol] The name of the method sought. # @param args [Array] The arguments which the method was to be invoked with. # @param block [Proc] The optional block provided to the method. # @return [] def method_missing(method, *args, &block) Vedeu.log("Keymap#method_missing '#{method.to_s}' (args: #{args.inspect})") @self_before_instance_eval.send(method, *args, &block) if @self_before_instance_eval end end # Keymap end # Vedeu
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
vedeu-0.2.4 | lib/vedeu/models/keymap.rb |