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.
-
#extra ⇒ Object
readonly
Returns the value of attribute extra.
-
#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 = {}) ⇒ Request
constructor
A new instance of Request.
- #next_filter ⇒ Object
- #to_json ⇒ Object
Constructor Details
#initialize(op, command_name, param_values = {}, extra = {}) ⇒ Request
Returns a new instance of Request.
12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/vop/objects/request.rb', line 12 def initialize(op, command_name, param_values = {}, extra = {}) @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 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 |
#extra ⇒ Object (readonly)
Returns the value of attribute extra.
9 10 11 |
# File 'lib/vop/objects/request.rb', line 9 def extra @extra 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
41 42 43 44 |
# File 'lib/vop/objects/request.rb', line 41 def self.from_json(op, json) hash = JSON.parse(json) self.new(op, hash["command"], hash["params"], hash["extra"]) end |
Instance Method Details
#cache_key ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/vop/objects/request.rb', line 28 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
24 25 26 |
# File 'lib/vop/objects/request.rb', line 24 def command @op.commands[@command_name] end |
#execute ⇒ Object
58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'lib/vop/objects/request.rb', line 58 def execute result = nil context = nil # 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
54 55 56 |
# File 'lib/vop/objects/request.rb', line 54 def next_filter @chain.next() end |
#to_json ⇒ Object
46 47 48 49 50 51 52 |
# File 'lib/vop/objects/request.rb', line 46 def to_json { command: @command_name, params: @param_values, extra: @extra }.to_json end |