Class: Ali::Task
- Inherits:
-
Object
show all
- Defined in:
- lib/ali/task.rb
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize ⇒ Task
Returns a new instance of Task.
54
55
56
|
# File 'lib/ali/task.rb', line 54
def initialize
@template = Ali::Template.new(self)
end
|
Instance Attribute Details
#template ⇒ Object
Returns the value of attribute template.
52
53
54
|
# File 'lib/ali/task.rb', line 52
def template
@template
end
|
Class Method Details
.description(value = nil) ⇒ Object
16
17
18
19
|
# File 'lib/ali/task.rb', line 16
def description(value = nil)
return @description.to_s if value.nil?
@description = value
end
|
.inherited(subclass) ⇒ Object
5
6
7
|
# File 'lib/ali/task.rb', line 5
def inherited(subclass)
Ali::Registry.instance.register subclass
end
|
.inspect ⇒ Object
31
32
33
34
35
36
37
38
39
40
|
# File 'lib/ali/task.rb', line 31
def inspect
value = <<~INSPECT
#<#{name}
name=#{name(for: :task).inspect}
monikers=#{monikers.inspect}
description=#{description.to_s.squish.inspect}
options=#{options.inspect}>
INSPECT
value.squish
end
|
.monikers(*values) ⇒ Object
21
22
23
24
|
# File 'lib/ali/task.rb', line 21
def monikers(*values)
return @monikers.to_a if values.none?
@monikers ||= Set.new(values.flatten.map(&:to_s))
end
|
.name(options = {for: :class}) ⇒ Object
9
10
11
12
13
14
|
# File 'lib/ali/task.rb', line 9
def name(options = {for: :class})
return super() if options[:for] == :class
super()
.then { |it| it.delete_prefix("Ali::Tasks::") }
.then { |it| it.split("::").map(&:parameterize).join(":") }
end
|
.options(*values) ⇒ Object
26
27
28
29
|
# File 'lib/ali/task.rb', line 26
def options(*values)
return @options.to_a if values.none?
@options ||= Set.new(values.flatten.select { |it| it.is_a?(Ali::Option) })
end
|
.to_h ⇒ Object
42
43
44
45
46
47
48
49
|
# File 'lib/ali/task.rb', line 42
def to_h
{
name: name(for: :task),
monikers: monikers,
description: description
}.stringify_keys
end
|
Instance Method Details
58
59
60
|
# File 'lib/ali/task.rb', line 58
def perform(*args)
raise NotImplementedError, "#perform must be implemented by subclass"
end
|