qwrapper 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 440822aee81b5f17df9d16212ee014db6f211eea
4
- data.tar.gz: 60bfd4688740b0ff7a0642b5146964812d590024
3
+ metadata.gz: 9dd93f9625eadb6c8e0e1be07c6cd8b6fbbfbca5
4
+ data.tar.gz: 0ba2c2ef4ae15690166701bc369fd9c04e26ecfd
5
5
  SHA512:
6
- metadata.gz: 10a5652c010cc584f410a5a157164ba83c4c1c8a3b128ceb7c912e75aa987ba09b9c86740d1029310c05f5f01ca52c63ffd3d62c7d1d7fadd95fd7d75ef5a61e
7
- data.tar.gz: 74c42374eee12d508784d9ebee2d263aa425fc2ae93d24dab4f2dc418739c15f6aec1ce314917ebf8c97e64989323fbe2f0843bfc5d4859af317eab073da390e
6
+ metadata.gz: 96ad304c4cf690a04e1093ef244f03c104aad2c1e5963996cab147b54938d3a7d87d708d64274a113d9a1fa900ca3d572c78a3e0bc08fb8e7619c781edf45f9a
7
+ data.tar.gz: a1c75746abb0ab55c960b231f0937623464ca8f6a97f3e7665d6a19a9d85afcf212314139ea15c46f7959efb81325d744d47231d94accdcac8dbec941ca9de64
data/lib/qwrapper.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  require "qwrapper/version"
2
2
  require "qwrapper/support"
3
+ require "qwrapper/message"
3
4
  require "qwrapper/queues"
4
5
 
5
6
  # Qwrapper is an idomatic API for working with message queues.
@@ -0,0 +1,36 @@
1
+ module Qwrapper
2
+ class Message
3
+
4
+ include Loggable
5
+
6
+ attr_reader :original_body, :hash
7
+
8
+ def initialize(body)
9
+ raise ArgumentError.new "Message body cannot be blank" if body.blank?
10
+ @original_body = body
11
+ begin
12
+ @hash = eval(body.to_s) rescue JSON.parse(body.to_s)
13
+ logger.info "Message evaluated: #{@hash}"
14
+ rescue => ex
15
+ logger.error "Message body cannot be evaluated: #{body}"
16
+ raise ex
17
+ end
18
+ validate!
19
+ end
20
+
21
+ def action
22
+ ((hash[:action] || hash["action"])).to_sym
23
+ end
24
+
25
+ def method_missing(m, *args, &block)
26
+ hash[m.to_s] || hash[m.to_s.to_sym]
27
+ end
28
+
29
+ private
30
+
31
+ def validate!
32
+ # TODO: Raise NotImplementedError? Client should implement their own custom error
33
+ end
34
+
35
+ end
36
+ end
@@ -61,26 +61,28 @@ module Qwrapper
61
61
  end
62
62
 
63
63
  def connection
64
- @conn ||= begin
64
+ #@conn ||= begin
65
65
  Bunny.new(connection_details).tap do |c|
66
66
  c.start
67
67
  end
68
- end
68
+ #end
69
69
  end
70
70
 
71
71
  def connection_details
72
- bunny_logger = logger
73
- bunny_logger = logger.duplicate("bunny") if logger.respond_to?(:duplicate)
74
72
  {
75
73
  host: config[:host] || "localhost",
76
74
  port: config[:port] || 5672,
77
- logger: bunny_logger,
75
+ logger: dup_logger,
78
76
  keepalive: config[:keepalive] || true
79
77
  }
80
78
  end
81
79
 
80
+ def dup_logger
81
+ logger.respond_to?(:duplicate) ? logger.duplicate("bunny") : logger
82
+ end
83
+
82
84
  end
83
85
 
84
86
  end
85
87
 
86
- end
88
+ end
@@ -1,3 +1,3 @@
1
1
  module Qwrapper
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: qwrapper
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nirmit Patel
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-10 00:00:00.000000000 Z
11
+ date: 2014-11-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -138,6 +138,7 @@ files:
138
138
  - README.md
139
139
  - Rakefile
140
140
  - lib/qwrapper.rb
141
+ - lib/qwrapper/message.rb
141
142
  - lib/qwrapper/queues.rb
142
143
  - lib/qwrapper/queues/base.rb
143
144
  - lib/qwrapper/queues/rabbitmq.rb