Class: Fatty::Command
- Inherits:
-
Object
- Object
- Fatty::Command
- Defined in:
- lib/fatty/command.rb
Instance Attribute Summary collapse
-
#action ⇒ Object
readonly
Returns the value of attribute action.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#target ⇒ Object
readonly
Returns the value of attribute target.
Class Method Summary collapse
- .coerce(value) ⇒ Object
- .normalize_list(value) ⇒ Object
- .session(id, action, **payload) ⇒ Object
- .terminal(action, **payload) ⇒ Object
Instance Method Summary collapse
- #id ⇒ Object
-
#initialize(target:, action:, payload: {}) ⇒ Command
constructor
A new instance of Command.
- #inspect ⇒ Object
- #session? ⇒ Boolean
- #terminal? ⇒ Boolean
Constructor Details
#initialize(target:, action:, payload: {}) ⇒ Command
Returns a new instance of Command.
7 8 9 10 11 |
# File 'lib/fatty/command.rb', line 7 def initialize(target:, action:, payload: {}) @target = target.to_sym @action = action.to_sym @payload = payload || {} end |
Instance Attribute Details
#action ⇒ Object (readonly)
Returns the value of attribute action.
5 6 7 |
# File 'lib/fatty/command.rb', line 5 def action @action end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
5 6 7 |
# File 'lib/fatty/command.rb', line 5 def payload @payload end |
#target ⇒ Object (readonly)
Returns the value of attribute target.
5 6 7 |
# File 'lib/fatty/command.rb', line 5 def target @target end |
Class Method Details
.coerce(value) ⇒ Object
25 26 27 28 29 30 31 32 33 34 |
# File 'lib/fatty/command.rb', line 25 def self.coerce(value) case value when Command value when Array coerce_array(value) else raise ArgumentError, "expected command, got #{value.inspect}" end end |
.normalize_list(value) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/fatty/command.rb', line 36 def self.normalize_list(value) result = case value when nil [] when Command [value] when Array value.grep(Command) else [] end result end |
.session(id, action, **payload) ⇒ Object
21 22 23 |
# File 'lib/fatty/command.rb', line 21 def self.session(id, action, **payload) new(target: id, action: action, payload: payload) end |
.terminal(action, **payload) ⇒ Object
17 18 19 |
# File 'lib/fatty/command.rb', line 17 def self.terminal(action, **payload) new(target: :terminal, action: action, payload: payload) end |
Instance Method Details
#id ⇒ Object
60 61 62 |
# File 'lib/fatty/command.rb', line 60 def id target unless terminal? end |
#inspect ⇒ Object
13 14 15 |
# File 'lib/fatty/command.rb', line 13 def inspect "Command: @target=#{@target}, @action=#{@action} @payload keys=#{@payload.keys}" end |
#session? ⇒ Boolean
56 57 58 |
# File 'lib/fatty/command.rb', line 56 def session? !terminal? end |
#terminal? ⇒ Boolean
52 53 54 |
# File 'lib/fatty/command.rb', line 52 def terminal? target == :terminal end |