Class: Vop::Request
- Inherits:
-
Object
- Object
- Vop::Request
- Defined in:
- lib/vop/objects/request.rb
Instance Attribute Summary collapse
-
#command_name ⇒ Object
readonly
Returns the value of attribute command_name.
-
#dont_log ⇒ Object
Returns the value of attribute dont_log.
-
#extra ⇒ Object
readonly
Returns the value of attribute extra.
-
#origin ⇒ Object
Returns the value of attribute origin.
-
#param_values ⇒ Object
readonly
Returns the value of attribute param_values.
-
#shell ⇒ Object
Returns the value of attribute shell.
Class Method Summary collapse
Instance Method Summary collapse
- #cache_key ⇒ Object
- #command ⇒ Object
- #execute ⇒ Object
-
#initialize(op, command_name, param_values = {}, extra = {}, origin = nil) ⇒ Request
constructor
A new instance of Request.
- #next_filter ⇒ Object
- #to_json ⇒ Object
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_name ⇒ Object (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_log ⇒ Object
Returns the value of attribute dont_log.
12 13 14 |
# File 'lib/vop/objects/request.rb', line 12 def dont_log @dont_log end |
#extra ⇒ Object (readonly)
Returns the value of attribute extra.
9 10 11 |
# File 'lib/vop/objects/request.rb', line 9 def extra @extra end |
#origin ⇒ Object
Returns the value of attribute origin.
11 12 13 |
# File 'lib/vop/objects/request.rb', line 11 def origin @origin end |
#param_values ⇒ Object (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 |
#shell ⇒ Object
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_key ⇒ Object
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 |
#command ⇒ Object
30 31 32 |
# File 'lib/vop/objects/request.rb', line 30 def command @op.commands[@command_name] end |
#execute ⇒ Object
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_filter ⇒ Object
61 62 63 |
# File 'lib/vop/objects/request.rb', line 61 def next_filter @chain.next() end |
#to_json ⇒ Object
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 |