Class: Vedeu::DSL::Keymap
- Inherits:
-
Object
- Object
- Vedeu::DSL::Keymap
- Includes:
- Common, Vedeu::DSL
- Defined in:
- lib/vedeu/dsl/components/keymap.rb
Overview
Provides methods to be used to define keypress mapped to actions.
Instance Attribute Summary collapse
- #client ⇒ Object readonly private
- #model ⇒ Keymap readonly private
Class Method Summary collapse
-
.keymap(name, &block) ⇒ Keymap
Define actions for keypresses for when specific interfaces are in focus.
Instance Method Summary collapse
-
#initialize(model, client = nil) ⇒ Vedeu::DSL::Keymap
constructor
Returns an instance of DSL::Keymap.
-
#key(*value_or_values, &block) ⇒ Array
Define keypress(es) to perform an action.
-
#name(value) ⇒ String
Define the name of the keymap.
Methods included from Vedeu::DSL
Methods included from Common
Constructor Details
#initialize(model, client = nil) ⇒ Vedeu::DSL::Keymap
Returns an instance of DSL::Keymap.
64 65 66 67 |
# File 'lib/vedeu/dsl/components/keymap.rb', line 64 def initialize(model, client = nil) @model = model @client = client end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Vedeu::DSL
Instance Attribute Details
#client ⇒ Object (readonly, private)
130 131 132 |
# File 'lib/vedeu/dsl/components/keymap.rb', line 130 def client @client end |
#model ⇒ Keymap (readonly, private)
133 134 135 |
# File 'lib/vedeu/dsl/components/keymap.rb', line 133 def model @model end |
Class Method Details
.keymap(name, &block) ⇒ Keymap
Try to remember why we need to pre-create the keymap in the repository.
When defining an interface, there is no need to provide a name since this can be discerned from the interface itself, e.g:
Vedeu.interface ‘my_interface’ do
keymap do
# ...
Define actions for keypresses for when specific interfaces are in focus. Unless an interface is specified, the key will be assumed to be global, meaning its action will happen regardless of the interface in focus.
53 54 55 56 57 |
# File 'lib/vedeu/dsl/components/keymap.rb', line 53 def self.keymap(name, &block) Vedeu::Keymap.new({ name: name }).store Vedeu::Keymap.build({ name: name }, &block).store end |
Instance Method Details
#key(*value_or_values, &block) ⇒ Array
Define keypress(es) to perform an action.
92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 |
# File 'lib/vedeu/dsl/components/keymap.rb', line 92 def key(*value_or_values, &block) fail InvalidSyntax, 'No action defined for `key`.' unless block_given? unless defined_value?(value_or_values) fail InvalidSyntax, 'No keypress(es) defined for `key`.' end value_or_values.each do |value| unless defined_value?(value) fail InvalidSyntax, 'An invalid value for `key` was encountered.' end model.add(model.member.new(value, &block)) end end |
#name(value) ⇒ String
Using the name of a keymap that already exists will overwrite that keymap. Do not use the name ‘system’ as unexpected behaviour may occur.
Define the name of the keymap.
To only allow certain keys to work with specific interfaces, use the same name as the interface.
When the name ‘global’ is used, all keys in the keymap block will be available to all interfaces. Once a key has been defined in the ‘global’ keymap, it cannot be used for a specific interface.
123 124 125 |
# File 'lib/vedeu/dsl/components/keymap.rb', line 123 def name(value) model.name = value end |