Class: Sod::Command
- Inherits:
-
Object
show all
- Extended by:
- Forwardable
- Defined in:
- lib/sod/command.rb
Overview
A generic command (and DSL) from which to inherit and build custom commands from. :reek:TooManyInstanceVariables
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
Constructor Details
#initialize(context: Context::EMPTY, model: Models::Command) ⇒ Command
Returns a new instance of Command.
36
37
38
39
40
41
42
|
# File 'lib/sod/command.rb', line 36
def initialize(context: Context::EMPTY, model: Models::Command, **)
super(**)
@context = context
@record = build_record model
verify_handle
end
|
Instance Attribute Details
#record ⇒ Object
Returns the value of attribute record.
34
35
36
|
# File 'lib/sod/command.rb', line 34
def record
@record
end
|
Class Method Details
.ancillary(*lines) ⇒ Object
26
27
28
|
# File 'lib/sod/command.rb', line 26
def self.ancillary(*lines)
@ancillary ? fail(Error, "Ancillary can only be defined once.") : @ancillary = lines
end
|
.description(text) ⇒ Object
22
23
24
|
# File 'lib/sod/command.rb', line 22
def self.description text
@description ? fail(Error, "Description can only be defined once.") : @description = text
end
|
.handle(text) ⇒ Object
18
19
20
|
# File 'lib/sod/command.rb', line 18
def self.handle text
@handle ? fail(Error, "Handle can only be defined once.") : @handle = text
end
|
.inherited(descendant) ⇒ Object
13
14
15
16
|
# File 'lib/sod/command.rb', line 13
def self.inherited descendant
super
descendant.class_eval { @actions = Set.new }
end
|
.on(action, *positionals, **keywords) ⇒ Object
30
|
# File 'lib/sod/command.rb', line 30
def self.on(action, *positionals, **keywords) = @actions.add [action, positionals, keywords]
|
Instance Method Details
#call ⇒ Object
44
45
46
|
# File 'lib/sod/command.rb', line 44
def call
logger.debug { "`#{self.class}##{__method__}}` called without implementation. Skipped." }
end
|
#inspect ⇒ Object
48
49
50
51
52
53
54
55
|
# File 'lib/sod/command.rb', line 48
def inspect
attributes = record.to_h
.map { |key, value| "#{key}=#{value.inspect}" }
.join ", "
"#<#{self.class}:#{object_id} @logger=#{logger.inspect} @context=#{context.inspect} " \
"#{attributes}>"
end
|