Class: Houston::Actions
- Inherits:
-
Object
show all
- Defined in:
- lib/houston/boot/actions.rb
Defined Under Namespace
Classes: Action, ExecutionContext, UndefinedActionError
Instance Method Summary
collapse
Constructor Details
Returns a new instance of Actions.
6
7
8
|
# File 'lib/houston/boot/actions.rb', line 6
def initialize
@actions = Concurrent::Hash.new
end
|
Instance Method Details
#[](name) ⇒ Object
24
25
26
|
# File 'lib/houston/boot/actions.rb', line 24
def [](name)
actions[name]
end
|
#clear ⇒ Object
38
39
40
|
# File 'lib/houston/boot/actions.rb', line 38
def clear
actions.clear
end
|
#count ⇒ Object
16
17
18
|
# File 'lib/houston/boot/actions.rb', line 16
def count
actions.count
end
|
#define(name, required_params = [], &block) ⇒ Object
44
45
46
47
|
# File 'lib/houston/boot/actions.rb', line 44
def define(name, required_params=[], &block)
raise ArgumentError, "#{name.inspect} is already defined" if exists?(name)
redefine(name, required_params, &block)
end
|
#exists?(name) ⇒ Boolean
20
21
22
|
# File 'lib/houston/boot/actions.rb', line 20
def exists?(name)
actions.key?(name)
end
|
#fetch(name) ⇒ Object
28
29
30
31
32
|
# File 'lib/houston/boot/actions.rb', line 28
def fetch(name)
actions.fetch(name)
rescue KeyError
raise UndefinedActionError, "#{name.inspect} is not defined"
end
|
#names ⇒ Object
12
13
14
|
# File 'lib/houston/boot/actions.rb', line 12
def names
actions.keys
end
|
#redefine(name, required_params = [], &block) ⇒ Object
49
50
51
52
|
# File 'lib/houston/boot/actions.rb', line 49
def redefine(name, required_params=[], &block)
raise ArgumentError, "A block is required to define an action" unless block_given?
actions[name] = Action.new(name, required_params, block)
end
|
#run(name, params = {}, options = {}) ⇒ Object
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
|
# File 'lib/houston/boot/actions.rb', line 61
def run(name, params={}, options={})
action = fetch(name)
unless params.is_a?(Hash)
raise ArgumentError, "params must be a Hash" unless params.respond_to?(:to_h)
params = params.to_h
end
assert_required_params! action, params
assert_serializable! params
Houston.async(options.fetch(:async, true)) do
::Action.run! name, params, options.fetch(:trigger, "manual")
end
end
|
#to_a ⇒ Object
34
35
36
|
# File 'lib/houston/boot/actions.rb', line 34
def to_a
actions.values
end
|
#undefine(name) ⇒ Object
54
55
56
57
|
# File 'lib/houston/boot/actions.rb', line 54
def undefine(name)
raise ArgumentError, "#{name.inspect} is not defined" unless exists?(name)
actions.delete name
end
|