philotic 1.2.2 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7a0a0b4ae57da0f6b43b05601febb8cdb8758e84
4
- data.tar.gz: 029b78c450e61411159336b6b10d86284cb939e6
3
+ metadata.gz: 1b524277f78a63e3afbcd2649eb0e82e9de78ffb
4
+ data.tar.gz: c4cc2b51a95698aa90a18c5cdbf83e314c5a4e2e
5
5
  SHA512:
6
- metadata.gz: ec5e334045ad137188f39a0b3f3e0e3ef0b76fc47f904ac9e4362d3620c3f7eda5bbf69172b31f2ade5be4dbff251128be9310053c55ae30ad59b9709d685b8b
7
- data.tar.gz: b9b3e27e50dfca3c350246d1815b168b7c058d4cd2722b062605d44d7331ac06f167ef4cc1838ada622e39e2fb8e5a2639b9c99956686faf403f4b19bf570aa5
6
+ metadata.gz: 3374f872ddc36c952277c06e20e0133b85eb342eee2d9fed8063d69b518d5f5d54f03eb134661b9ca7009514ed898a20b82a1c9ce8ce7c1a80ae1f046db8d3e3
7
+ data.tar.gz: 24db814982d903080bd8d8f2b647a962b2e530a7ed338f1914365466b23c45ac39d032d0cd47d7352e984cf2dac42433e309acd8f31ee84e722ffaa5213a1f0a
@@ -16,6 +16,7 @@ module Philotic
16
16
  RABBIT_VHOST = '%2f' # '/'
17
17
  RABBIT_URL = "#{RABBIT_SCHEME}://#{RABBIT_USER}:#{RABBIT_PASSWORD}@#{RABBIT_HOST}:#{RABBIT_PORT}/#{RABBIT_VHOST}"
18
18
  EXCHANGE_NAME = 'philotic.headers'
19
+ EXCHANGE_TYPE = 'headers'
19
20
  ROUTING_KEY = nil
20
21
  PERSISTENT = false
21
22
  IMMEDIATE = false
@@ -104,7 +104,7 @@ module Philotic
104
104
  end
105
105
 
106
106
  def exchange
107
- @exchange ||= channel.headers(config.exchange_name, durable: true)
107
+ @exchange ||= channel.send(config.exchange_type, config.exchange_name, durable: true)
108
108
  end
109
109
 
110
110
  def set_exchange_return_handler!
@@ -148,7 +148,7 @@ module Philotic
148
148
  end
149
149
 
150
150
  def exchange_from_config(config)
151
- config[:exchange] ? channel.headers(config[:exchange], durable: true) : exchange
151
+ config[:exchange] ? channel.send(self.config.exchange_type, config[:exchange], durable: true) : exchange
152
152
  end
153
153
 
154
154
  def queue_from_config(queue_name, config)
@@ -121,6 +121,7 @@ module Philotic
121
121
 
122
122
  def _set_routables_or_payloads(type, attrs)
123
123
  attrs.each do |key, value|
124
+ key = _normalize_attr_name(key)
124
125
  if self.respond_to?(:"#{key}=")
125
126
  send(:"#{key}=", value)
126
127
  elsif _is_anonymous_message?
@@ -135,21 +136,34 @@ module Philotic
135
136
  end
136
137
 
137
138
  def _set_message_attribute_accessor(attr, value)
139
+ attr = _normalize_attr_name(attr)
138
140
  _set_message_attribute_getter(attr)
139
141
  _set_message_attribute_setter(attr)
140
142
  self.send(:"#{attr}=", value)
141
143
  end
142
144
 
143
145
  def _set_message_attribute_getter(attr)
146
+ attr = _normalize_attr_name(attr)
144
147
  self.define_singleton_method :"#{attr}" do
145
148
  instance_variable_get(:"@#{attr}")
146
149
  end
147
150
  end
148
151
 
149
152
  def _set_message_attribute_setter(attr)
153
+ attr = _normalize_attr_name(attr)
150
154
  self.define_singleton_method :"#{attr}=" do |v|
151
155
  instance_variable_set(:"@#{attr}", v)
152
156
  end
153
157
  end
158
+
159
+ def _normalize_attr_name(attr)
160
+ %i[_underscore_attr_name].reduce(attr) do |attr, normalizer|
161
+ send(normalizer, attr)
162
+ end.to_sym
163
+ end
164
+ def _underscore_attr_name(attr)
165
+ attr.to_s.tr('-', '_')
166
+
167
+ end
154
168
  end
155
169
  end
@@ -1,3 +1,3 @@
1
1
  module Philotic
2
- VERSION = '1.2.2'
2
+ VERSION = '1.3.0'
3
3
  end
@@ -237,4 +237,14 @@ describe Philotic::Message do
237
237
  end
238
238
 
239
239
  end
240
+
241
+
242
+ describe 'hyphenated attrs' do
243
+ let(:hyphenated_attr) { 'x-hyphenated-attr' }
244
+ let(:hyphenated_attr_value) { 'foo' }
245
+ let(:message) { Class.new(Philotic::Message).new(hyphenated_attr => hyphenated_attr_value) }
246
+ specify 'translate hyphens to underscores' do
247
+ expect(message.x_hyphenated_attr).to eq hyphenated_attr_value
248
+ end
249
+ end
240
250
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: philotic
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.2
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nathan Keyes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-10-27 00:00:00.000000000 Z
11
+ date: 2015-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: awesome_print