Class: Specter::Request
- Inherits:
-
Object
- Object
- Specter::Request
- Defined in:
- lib/specter/request.rb
Instance Attribute Summary collapse
-
#args ⇒ Object
readonly
Returns the value of attribute args.
-
#command ⇒ Object
readonly
Returns the value of attribute command.
Class Method Summary collapse
Instance Method Summary collapse
- #execute(client) ⇒ Object
-
#initialize(command, args) ⇒ Request
constructor
A new instance of Request.
- #inspect ⇒ Object
Constructor Details
#initialize(command, args) ⇒ Request
Returns a new instance of Request.
23 24 25 26 27 28 29 30 |
# File 'lib/specter/request.rb', line 23 def initialize(command, args) if command.nil? || command.empty? raise RequestError, 'command not supplied' end @command = command.to_sym @args = args end |
Instance Attribute Details
#args ⇒ Object (readonly)
Returns the value of attribute args.
21 22 23 |
# File 'lib/specter/request.rb', line 21 def args @args end |
#command ⇒ Object (readonly)
Returns the value of attribute command.
19 20 21 |
# File 'lib/specter/request.rb', line 19 def command @command end |
Class Method Details
.parse(raw) ⇒ Object
6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/specter/request.rb', line 6 def self.parse(raw) begin = JSON.parse(raw) rescue JSON::ParserError raise RequestError, $! end command = ['command'] args = ['parameter'].to_s.split(',') new(command, args) end |
Instance Method Details
#execute(client) ⇒ Object
32 33 34 |
# File 'lib/specter/request.rb', line 32 def execute(client) client.send(command, *args) end |
#inspect ⇒ Object
36 37 38 |
# File 'lib/specter/request.rb', line 36 def inspect "#<#{self.class} command:#{command}, args:#{args.inspect}>" end |