Class: Adminbox::Command
- Inherits:
-
Object
- Object
- Adminbox::Command
- Defined in:
- lib/adminbox/command.rb
Instance Attribute Summary collapse
-
#encoded_jwt ⇒ Object
readonly
Returns the value of attribute encoded_jwt.
Instance Method Summary collapse
- #decoded_jwt ⇒ Object
- #execute ⇒ Object
- #headers ⇒ Object
- #ids ⇒ Object
-
#initialize(jwt) ⇒ Command
constructor
A new instance of Command.
- #name ⇒ Object
- #payload ⇒ Object
- #shared_secret ⇒ Object
- #table ⇒ Object
- #table_module ⇒ Object
Constructor Details
#initialize(jwt) ⇒ Command
Returns a new instance of Command.
5 6 7 |
# File 'lib/adminbox/command.rb', line 5 def initialize(jwt) @encoded_jwt = jwt end |
Instance Attribute Details
#encoded_jwt ⇒ Object (readonly)
Returns the value of attribute encoded_jwt.
3 4 5 |
# File 'lib/adminbox/command.rb', line 3 def encoded_jwt @encoded_jwt end |
Instance Method Details
#decoded_jwt ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/adminbox/command.rb', line 18 def decoded_jwt @decoded_jwt ||= begin JWT.decode(encoded_jwt, shared_secret) rescue JWT::VerificationError raise Adminbox::InvalidSignature rescue JWT::ExpiredSignature raise Adminbox::ExpiredSignature end end |
#execute ⇒ Object
9 10 11 12 |
# File 'lib/adminbox/command.rb', line 9 def execute subcommand = Object.const_get("Commands::#{table_module}::#{name}") subcommand.new(encoded_jwt).execute end |
#headers ⇒ Object
32 33 34 |
# File 'lib/adminbox/command.rb', line 32 def headers decoded_jwt[1] end |
#ids ⇒ Object
48 49 50 |
# File 'lib/adminbox/command.rb', line 48 def ids payload["ids"] end |
#name ⇒ Object
36 37 38 |
# File 'lib/adminbox/command.rb', line 36 def name payload["command"] end |
#payload ⇒ Object
28 29 30 |
# File 'lib/adminbox/command.rb', line 28 def payload decoded_jwt[0] end |
#shared_secret ⇒ Object
14 15 16 |
# File 'lib/adminbox/command.rb', line 14 def shared_secret Adminbox.configuration.shared_secret end |
#table ⇒ Object
40 41 42 |
# File 'lib/adminbox/command.rb', line 40 def table payload["table"] end |
#table_module ⇒ Object
44 45 46 |
# File 'lib/adminbox/command.rb', line 44 def table_module table.split('_').collect(&:capitalize).join end |