Class: Expedite::Actions

Inherits:
Object
  • Object
show all
Defined in:
lib/expedite/actions.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeActions

Returns a new instance of Actions.



33
34
35
# File 'lib/expedite/actions.rb', line 33

def initialize
  reset
end

Class Method Details

.currentObject



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, **named_options, &block)
  self.current.register(name.to_s, klass_or_nil, **named_options, &block)
end

.resetObject

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

Raises:

  • (NotImplementedError)


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, **named_options, &block)
  cmd = if klass_or_nil.nil?
    Action::Block.new(**named_options, &block)
  else
    klass_or_nil.new(**named_options)
  end

  @registrations[name.to_s] = cmd
end

#resetObject



53
54
55
56
57
58
59
60
# File 'lib/expedite/actions.rb', line 53

def reset
  @registrations = {}

  # Default registrations
  register("expedite/boot", Expedite::Action::Boot)

  nil
end