Class: Vop::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/vop/objects/request.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(op, command_name, param_values = {}, extra = {}, origin = nil) ⇒ Request

Returns a new instance of Request.



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/vop/objects/request.rb', line 14

def initialize(op, command_name, param_values = {}, extra = {}, origin = nil)
  @op = op
  @command_name = command_name
  raise "unknown command '#{command_name}'" if command.nil?
  @param_values = param_values
  @extra = extra
  @shell = nil

  @current_filter = nil
  @filter_chain = @op.filter_chain.clone
  # TODO not sure if this is really a hash out in the wild
  @origin = origin || {}

  @dont_log = false
end

Instance Attribute Details

#command_nameObject (readonly)

Returns the value of attribute command_name.



9
10
11
# File 'lib/vop/objects/request.rb', line 9

def command_name
  @command_name
end

#dont_logObject

Returns the value of attribute dont_log.



12
13
14
# File 'lib/vop/objects/request.rb', line 12

def dont_log
  @dont_log
end

#extraObject (readonly)

Returns the value of attribute extra.



9
10
11
# File 'lib/vop/objects/request.rb', line 9

def extra
  @extra
end

#originObject

Returns the value of attribute origin.



11
12
13
# File 'lib/vop/objects/request.rb', line 11

def origin
  @origin
end

#param_valuesObject (readonly)

Returns the value of attribute param_values.



9
10
11
# File 'lib/vop/objects/request.rb', line 9

def param_values
  @param_values
end

#shellObject

Returns the value of attribute shell.



10
11
12
# File 'lib/vop/objects/request.rb', line 10

def shell
  @shell
end

Class Method Details

.from_json(op, json) ⇒ Object



47
48
49
50
# File 'lib/vop/objects/request.rb', line 47

def self.from_json(op, json)
  hash = JSON.parse(json)
  self.new(op, hash["command"], hash["params"], hash["extra"], hash["origin"])
end

Instance Method Details

#cache_keyObject



34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/vop/objects/request.rb', line 34

def cache_key
  blacklist = %w|shell raw_params|

  ex = Executor.new(@op)
  prepared = ex.prepare_params(self)

  param_string = prepared.map { |k,v|
    next if blacklist.include? k
    [k.to_s,v].join("=")
  }.sort.compact.join(":")
  "vop/request:#{command.name}:" + param_string + ":v1"
end

#commandObject



30
31
32
# File 'lib/vop/objects/request.rb', line 30

def command
  @op.commands[@command_name]
end

#executeObject



65
66
67
68
69
70
71
72
73
# File 'lib/vop/objects/request.rb', line 65

def execute
  # build a chain out of all filters + the command itself
  filter_chain = @op.filter_chain.clone.map {
    |filter_name| @op.filters[filter_name.split(".").first]
  }
  filter_chain << Executor.new(@op)
  @chain = Chain.new(@op, filter_chain)
  @chain.execute(self)
end

#next_filterObject



61
62
63
# File 'lib/vop/objects/request.rb', line 61

def next_filter
   @chain.next()
end

#to_jsonObject



52
53
54
55
56
57
58
59
# File 'lib/vop/objects/request.rb', line 52

def to_json
  {
      command: @command_name,
      params: @param_values,
      origin: @origin,
      extra: @extra
  }.to_json
end