Class: Gilmour::Composers::Request
- Inherits:
-
Object
- Object
- Gilmour::Composers::Request
- Defined in:
- lib/gilmour/composers.rb
Overview
:nodoc:
Instance Attribute Summary collapse
-
#topic ⇒ Object
readonly
Returns the value of attribute topic.
Instance Method Summary collapse
- #execute(data = {}, &blk) ⇒ Object
-
#initialize(backend, spec) ⇒ Request
constructor
A new instance of Request.
Constructor Details
#initialize(backend, spec) ⇒ Request
Returns a new instance of Request.
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/gilmour/composers.rb', line 6 def initialize(backend, spec) @backend = backend @spec = spec if spec.kind_of?(Hash) = spec[:message] || spec['message'] || {} @topic = spec[:topic] || spec['topic'] if !@topic raise ArgumentError.new("Request topic cannot be empty in a request spec") end @opts = spec[:opts] || spec['opts'] || {} if @opts && !@opts.kind_of?(Hash) raise ArgumentError.new("Request opts must be a Hash") end elsif spec.kind_of?(Proc) @topic = spec.to_s else raise ArgumentError.new("Request spec must be a spec or proc") end end |
Instance Attribute Details
#topic ⇒ Object (readonly)
Returns the value of attribute topic.
5 6 7 |
# File 'lib/gilmour/composers.rb', line 5 def topic @topic end |
Instance Method Details
#execute(data = {}, &blk) ⇒ Object
26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/gilmour/composers.rb', line 26 def execute(data = {}, &blk) if @spec.kind_of?(Proc) begin res = @spec.call(data) rescue => e code = 500 end code = res ? 200 : 500 blk.call(res, code) else = if .kind_of?(Hash) && data.kind_of?(Hash) data.merge() else data end @backend.request!(, @topic, @opts, &blk) end rescue Exception => e GLogger.debug e. GLogger.debug e.backtrace end |