Class: Expedite::Actions
- Inherits:
-
Object
- Object
- Expedite::Actions
- Defined in:
- lib/expedite/actions.rb
Class Method Summary collapse
- .current ⇒ Object
- .lookup(name) ⇒ Object
-
.register(name, klass_or_nil = nil, **named_options, &block) ⇒ Object
Registers an action.
-
.reset ⇒ Object
Restores existing registrations to default.
Instance Method Summary collapse
-
#initialize ⇒ Actions
constructor
A new instance of Actions.
- #lookup(name) ⇒ Object
- #register(name, klass_or_nil = nil, **named_options, &block) ⇒ Object
- #reset ⇒ Object
Constructor Details
#initialize ⇒ Actions
Returns a new instance of Actions.
33 34 35 |
# File 'lib/expedite/actions.rb', line 33 def initialize reset end |
Class Method Details
.current ⇒ Object
6 7 8 |
# File 'lib/expedite/actions.rb', line 6 def self.current @current ||= Actions.new end |
.lookup(name) ⇒ Object
10 11 12 |
# File 'lib/expedite/actions.rb', line 10 def self.lookup(name) self.current.lookup(name) end |
.register(name, klass_or_nil = nil, **named_options, &block) ⇒ Object
Registers an action. If multiple actions are registered with the same name, the last one takes precedence.
- name
-
Name of the action. Expedite internal actions are prefixed with “expedite/”
- klass_or_nil
-
Class of the action. If omitted, will default to Expedite::Action::Block.
- named_options
-
Action options. Passed to the initializer.
23 24 25 |
# File 'lib/expedite/actions.rb', line 23 def self.register(name, klass_or_nil = nil, **, &block) self.current.register(name.to_s, klass_or_nil, **, &block) end |
.reset ⇒ Object
Restores existing registrations to default
29 30 31 |
# File 'lib/expedite/actions.rb', line 29 def self.reset self.current.reset end |
Instance Method Details
#lookup(name) ⇒ Object
37 38 39 40 41 |
# File 'lib/expedite/actions.rb', line 37 def lookup(name) ret = @registrations[name.to_s] raise NotImplementedError, "Action #{name.inspect} not found" if ret.nil? ret end |
#register(name, klass_or_nil = nil, **named_options, &block) ⇒ Object
43 44 45 46 47 48 49 50 51 |
# File 'lib/expedite/actions.rb', line 43 def register(name, klass_or_nil = nil, **, &block) cmd = if klass_or_nil.nil? Action::Block.new(**, &block) else klass_or_nil.new(**) end @registrations[name.to_s] = cmd end |