Class: Adminbox::Command

Inherits:
Object
  • Object
show all
Defined in:
lib/adminbox/command.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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_jwtObject (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_jwtObject



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

#executeObject



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

#headersObject



32
33
34
# File 'lib/adminbox/command.rb', line 32

def headers
  decoded_jwt[1]
end

#idsObject



48
49
50
# File 'lib/adminbox/command.rb', line 48

def ids
  payload["ids"]
end

#nameObject



36
37
38
# File 'lib/adminbox/command.rb', line 36

def name
  payload["command"]
end

#payloadObject



28
29
30
# File 'lib/adminbox/command.rb', line 28

def payload
  decoded_jwt[0]
end

#shared_secretObject



14
15
16
# File 'lib/adminbox/command.rb', line 14

def shared_secret
  Adminbox.configuration.shared_secret
end

#tableObject



40
41
42
# File 'lib/adminbox/command.rb', line 40

def table
  payload["table"]
end

#table_moduleObject



44
45
46
# File 'lib/adminbox/command.rb', line 44

def table_module
  table.split('_').collect(&:capitalize).join
end