philotic 0.3.0 → 0.4.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
- ---
2
- SHA1:
3
- metadata.gz: dd9e68a219e5e261cff5c93874204ee23ac50eff
4
- data.tar.gz: 76474a8e73d1306e885161c8639043b1ad80d15f
5
- SHA512:
6
- metadata.gz: 1cd304f11017c7e646a0ce22d7bf620613cdb73a5fff3e0cfc2e78d2c63750dd7ed28ec8cf216f59f273eeda92a77881c94894d9a0e07edbee49c37958be336c
7
- data.tar.gz: c7db1f0ac754a5e76c0266957443b13cc1e25e52f9ce2aec2fe47723465881262214ac67342ee8cc5aa18e4f330cd1ab6cb843ccaca92c44efdc5766439a36d4
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 158377a2a7f0458ec444e07ab7aab54225911480
4
+ data.tar.gz: 510ad20cb672b6d3294fbde7d71f4afd42a19500
5
+ SHA512:
6
+ metadata.gz: 8fe5d2caff540d1eacfb224c5de104ed7bdf8769a13a8bc99afe6748e70368ce0c13b57bbb92d90efa7e38d4455b867a0c51d834cf3b4c79625fa6b0bf9cdd14
7
+ data.tar.gz: 713a02825e3bdc0d8eb62f0a185508a8de8bd3df8a9c3b431ff4b5213e7177b8f4a1a40431c1e478c8edcb185801670c09cf33461c41ce57f0861054227c299d
@@ -6,18 +6,29 @@ require 'philotic/connection'
6
6
 
7
7
 
8
8
  module Philotic
9
+ class << self
10
+ extend Forwardable
9
11
 
10
- def self.root
11
- ::Pathname.new File.expand_path('../../', __FILE__)
12
- end
12
+ def root
13
+ ::Pathname.new File.expand_path('../../', __FILE__)
14
+ end
13
15
 
14
- def self.env
15
- ENV['SERVICE_ENV'] || 'development'
16
- end
16
+ def env
17
+ ENV['SERVICE_ENV'] || 'development'
18
+ end
19
+
20
+ def connection
21
+ @connection ||= Philotic::Connection.new
22
+ end
23
+
24
+ def method_missing(method, *args, &block)
25
+ connection.send(method, *args, &block)
26
+ end
27
+
28
+ def_delegators :connection, *(Philotic::Connection.public_instance_methods(false) - [:connection])
17
29
 
18
- def self.connection
19
- @connection ||= Philotic::Connection.new
20
30
  end
31
+
21
32
  end
22
33
 
23
34
  require 'philotic/version'
@@ -8,6 +8,8 @@ require 'philotic/subscriber'
8
8
 
9
9
  module Philotic
10
10
  class Connection
11
+ extend Forwardable
12
+
11
13
  attr_reader :connection
12
14
  attr_accessor :logger
13
15
 
@@ -133,8 +135,7 @@ module Philotic
133
135
  @logger
134
136
  end
135
137
 
136
- def publish(event)
137
- publisher.publish(event)
138
- end
138
+ def_delegators :publisher, :publish
139
+ def_delegators :subscriber, :subscribe
139
140
  end
140
141
  end
@@ -1,3 +1,4 @@
1
+ require 'philotic'
1
2
  require 'philotic/constants'
2
3
  require 'philotic/connection'
3
4
  require 'philotic/routable'
@@ -6,6 +7,21 @@ module Philotic
6
7
  class Event
7
8
  include Philotic::Routable
8
9
 
10
+ attr_accessor :connection
11
+
12
+ def initialize(routables={}, payloads={}, connection=nil)
13
+ self.timestamp = Time.now.to_i
14
+ self.philotic_firehose = true
15
+ self.connection = connection
16
+
17
+ # dynamically insert any passed in routables into both attr_routable
18
+ # and attr_payload
19
+ # result: ability to arbitrarily send a easily routable hash
20
+ # over into the bus
21
+ _set_routables_or_payloads(:routable, routables)
22
+ _set_routables_or_payloads(:payload, payloads)
23
+ end
24
+
9
25
  def self.inherited(sub)
10
26
  Philotic::PHILOTIC_HEADERS.each do |header|
11
27
  sub.attr_routable header
@@ -30,25 +46,35 @@ module Philotic
30
46
  end
31
47
 
32
48
  def connection
33
- Philotic::Connection.instance
49
+ @connection ||= Philotic.connection
50
+ end
51
+
52
+ def publish
53
+ connection.publish self
34
54
  end
35
55
 
36
- def set_routables_or_payloads(type, attrs)
56
+ def self.publish(*args)
57
+ self.new(*args).publish
58
+ end
59
+
60
+ private
61
+
62
+ def _set_routables_or_payloads(type, attrs)
37
63
  attrs.each do |key, value|
38
64
  if self.respond_to?(:"#{key}=")
39
65
  send(:"#{key}=", value)
40
66
  elsif self.class == Philotic::Event
41
- set_event_attribute(type, key, value)
67
+ _set_event_attribute(type, key, value)
42
68
  end
43
69
  end
44
70
  end
45
71
 
46
- def set_event_attribute(type, key, value)
47
- set_event_attribute_setter(key, type, value)
48
- set_event_attribute_getter(key, type)
72
+ def _set_event_attribute(type, key, value)
73
+ _set_event_attribute_setter(key, type, value)
74
+ _set_event_attribute_getter(key, type)
49
75
  end
50
76
 
51
- def set_event_attribute_getter(key, type)
77
+ def _set_event_attribute_getter(key, type)
52
78
  self.class.send("attr_#{type}_readers").concat([key])
53
79
  getter = lambda do
54
80
  instance_variable_get(:"@#{key}")
@@ -56,7 +82,7 @@ module Philotic
56
82
  self.class.send :define_method, :"#{key}", getter
57
83
  end
58
84
 
59
- def set_event_attribute_setter(key, type, value)
85
+ def _set_event_attribute_setter(key, type, value)
60
86
  self.class.send("attr_#{type}_writers").concat([:"#{key}="])
61
87
  setter = lambda do |v|
62
88
  instance_variable_set(:"@#{key}", v)
@@ -64,19 +90,5 @@ module Philotic
64
90
  self.class.send :define_method, :"#{key}=", setter
65
91
  self.send(:"#{key}=", value)
66
92
  end
67
-
68
- def initialize(routables={}, payloads=nil)
69
- payloads ||= {}
70
- self.timestamp = Time.now.to_i
71
- self.philotic_firehose = true
72
-
73
- # dynamically insert any passed in routables into both attr_routable
74
- # and attr_payload
75
- # result: ability to arbitrarily send a easily routable hash
76
- # over into the bus
77
- set_routables_or_payloads(:routable, routables)
78
- set_routables_or_payloads(:payload, payloads)
79
- self
80
- end
81
93
  end
82
94
  end
@@ -1,3 +1,3 @@
1
1
  module Philotic
2
- VERSION = '0.3.0'
2
+ VERSION = '0.4.0'
3
3
  end
data/repl CHANGED
@@ -1,3 +1,3 @@
1
1
  #!/bin/sh
2
2
 
3
- bundle exec irb -Ilib -r 'philotic' -r 'awesome_print'
3
+ irb -Ilib -r 'philotic' -r 'awesome_print'
@@ -41,7 +41,7 @@ describe Philotic::Event do
41
41
  expect(subject.headers.keys).to include :philotic_product
42
42
  end
43
43
  end
44
-
44
+
45
45
  context 'generic event' do
46
46
  let(:headers) do
47
47
  {
@@ -66,4 +66,44 @@ describe Philotic::Event do
66
66
 
67
67
  end
68
68
  end
69
- end
69
+
70
+ describe '#publish' do
71
+ subject { Philotic::Event.new }
72
+ specify do
73
+ expect(subject.connection).to receive(:publish).with(subject)
74
+
75
+ subject.publish
76
+ end
77
+
78
+ end
79
+
80
+ describe '.publish' do
81
+ let (:connection) { double }
82
+ let(:headers) do
83
+ {
84
+ header1: 'h1',
85
+ header2: 'h2',
86
+ header3: 'h3',
87
+ }
88
+ end
89
+
90
+ let(:payloads) do
91
+ {
92
+ payload1: 'h1',
93
+ payload2: 'h2',
94
+ payload3: 'h3',
95
+ }
96
+ end
97
+ subject { Philotic::Event }
98
+ specify do
99
+ expect_any_instance_of(Philotic::Event).to receive(:connection).and_return(connection)
100
+ expect(connection).to receive(:publish) do |event|
101
+ expect(event.headers).to include(headers)
102
+ expect(event.payload).to eq payloads
103
+ end
104
+
105
+ subject.publish(headers, payloads)
106
+ end
107
+
108
+ end
109
+ end
@@ -7,4 +7,13 @@ describe Philotic do
7
7
  expect(Philotic.connection.class).to eq(Philotic::Connection)
8
8
  end
9
9
  end
10
+
11
+ describe 'delegation' do
12
+ it 'should delegate to the connection instance' do
13
+ (Philotic.connection.public_methods(false) - [:connection]).each do |method|
14
+ expect(Philotic.connection).to receive(method)
15
+ Philotic.send "#{method}"
16
+ end
17
+ end
18
+ end
10
19
  end
metadata CHANGED
@@ -1,218 +1,164 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: philotic
3
- version: !ruby/object:Gem::Version
4
- version: 0.3.0
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.0
5
5
  platform: ruby
6
- authors:
6
+ authors:
7
7
  - Nathan Keyes
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-18 00:00:00.000000000 Z
12
- dependencies:
13
- - !ruby/object:Gem::Dependency
11
+
12
+ date: 2014-12-18 00:00:00 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
14
15
  name: codeclimate-test-reporter
15
- requirement: !ruby/object:Gem::Requirement
16
- requirements:
17
- - - '>='
18
- - !ruby/object:Gem::Version
19
- version: '0'
20
- type: :development
21
16
  prerelease: false
22
- version_requirements: !ruby/object:Gem::Requirement
23
- requirements:
24
- - - '>='
25
- - !ruby/object:Gem::Version
26
- version: '0'
27
- - !ruby/object:Gem::Dependency
28
- name: bundler
29
- requirement: !ruby/object:Gem::Requirement
30
- requirements:
31
- - - ~>
32
- - !ruby/object:Gem::Version
33
- version: '1.6'
17
+ requirement: &id001 !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - &id009
20
+ - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: "0"
34
23
  type: :development
24
+ version_requirements: *id001
25
+ - !ruby/object:Gem::Dependency
26
+ name: bundler
35
27
  prerelease: false
36
- version_requirements: !ruby/object:Gem::Requirement
37
- requirements:
38
- - - ~>
39
- - !ruby/object:Gem::Version
40
- version: '1.6'
41
- - !ruby/object:Gem::Dependency
42
- name: evented-spec
43
- requirement: !ruby/object:Gem::Requirement
44
- requirements:
28
+ requirement: &id002 !ruby/object:Gem::Requirement
29
+ requirements:
45
30
  - - ~>
46
- - !ruby/object:Gem::Version
47
- version: '0.9'
31
+ - !ruby/object:Gem::Version
32
+ version: "1.6"
48
33
  type: :development
34
+ version_requirements: *id002
35
+ - !ruby/object:Gem::Dependency
36
+ name: evented-spec
49
37
  prerelease: false
50
- version_requirements: !ruby/object:Gem::Requirement
51
- requirements:
38
+ requirement: &id003 !ruby/object:Gem::Requirement
39
+ requirements:
52
40
  - - ~>
53
- - !ruby/object:Gem::Version
54
- version: '0.9'
55
- - !ruby/object:Gem::Dependency
56
- name: pry
57
- requirement: !ruby/object:Gem::Requirement
58
- requirements:
59
- - - ~>
60
- - !ruby/object:Gem::Version
61
- version: '0.10'
41
+ - !ruby/object:Gem::Version
42
+ version: "0.9"
62
43
  type: :development
44
+ version_requirements: *id003
45
+ - !ruby/object:Gem::Dependency
46
+ name: pry
63
47
  prerelease: false
64
- version_requirements: !ruby/object:Gem::Requirement
65
- requirements:
48
+ requirement: &id004 !ruby/object:Gem::Requirement
49
+ requirements:
66
50
  - - ~>
67
- - !ruby/object:Gem::Version
68
- version: '0.10'
69
- - !ruby/object:Gem::Dependency
70
- name: rake
71
- requirement: !ruby/object:Gem::Requirement
72
- requirements:
73
- - - ~>
74
- - !ruby/object:Gem::Version
75
- version: '10.3'
51
+ - !ruby/object:Gem::Version
52
+ version: "0.10"
76
53
  type: :development
54
+ version_requirements: *id004
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
77
57
  prerelease: false
78
- version_requirements: !ruby/object:Gem::Requirement
79
- requirements:
80
- - - ~>
81
- - !ruby/object:Gem::Version
82
- version: '10.3'
83
- - !ruby/object:Gem::Dependency
84
- name: rspec
85
- requirement: !ruby/object:Gem::Requirement
86
- requirements:
58
+ requirement: &id005 !ruby/object:Gem::Requirement
59
+ requirements:
87
60
  - - ~>
88
- - !ruby/object:Gem::Version
89
- version: '3.1'
61
+ - !ruby/object:Gem::Version
62
+ version: "10.3"
90
63
  type: :development
64
+ version_requirements: *id005
65
+ - !ruby/object:Gem::Dependency
66
+ name: rspec
91
67
  prerelease: false
92
- version_requirements: !ruby/object:Gem::Requirement
93
- requirements:
94
- - - ~>
95
- - !ruby/object:Gem::Version
96
- version: '3.1'
97
- - !ruby/object:Gem::Dependency
98
- name: rspec-its
99
- requirement: !ruby/object:Gem::Requirement
100
- requirements:
68
+ requirement: &id006 !ruby/object:Gem::Requirement
69
+ requirements:
101
70
  - - ~>
102
- - !ruby/object:Gem::Version
103
- version: '1.1'
71
+ - !ruby/object:Gem::Version
72
+ version: "3.1"
104
73
  type: :development
74
+ version_requirements: *id006
75
+ - !ruby/object:Gem::Dependency
76
+ name: rspec-its
105
77
  prerelease: false
106
- version_requirements: !ruby/object:Gem::Requirement
107
- requirements:
78
+ requirement: &id007 !ruby/object:Gem::Requirement
79
+ requirements:
108
80
  - - ~>
109
- - !ruby/object:Gem::Version
110
- version: '1.1'
111
- - !ruby/object:Gem::Dependency
112
- name: timecop
113
- requirement: !ruby/object:Gem::Requirement
114
- requirements:
115
- - - ~>
116
- - !ruby/object:Gem::Version
117
- version: '0.7'
81
+ - !ruby/object:Gem::Version
82
+ version: "1.1"
118
83
  type: :development
84
+ version_requirements: *id007
85
+ - !ruby/object:Gem::Dependency
86
+ name: timecop
119
87
  prerelease: false
120
- version_requirements: !ruby/object:Gem::Requirement
121
- requirements:
88
+ requirement: &id008 !ruby/object:Gem::Requirement
89
+ requirements:
122
90
  - - ~>
123
- - !ruby/object:Gem::Version
124
- version: '0.7'
125
- - !ruby/object:Gem::Dependency
126
- name: simplecov
127
- requirement: !ruby/object:Gem::Requirement
128
- requirements:
129
- - - '>='
130
- - !ruby/object:Gem::Version
131
- version: '0'
91
+ - !ruby/object:Gem::Version
92
+ version: "0.7"
132
93
  type: :development
94
+ version_requirements: *id008
95
+ - !ruby/object:Gem::Dependency
96
+ name: simplecov
133
97
  prerelease: false
134
- version_requirements: !ruby/object:Gem::Requirement
135
- requirements:
136
- - - '>='
137
- - !ruby/object:Gem::Version
138
- version: '0'
139
- - !ruby/object:Gem::Dependency
98
+ requirement: &id010 !ruby/object:Gem::Requirement
99
+ requirements:
100
+ - *id009
101
+ type: :development
102
+ version_requirements: *id010
103
+ - !ruby/object:Gem::Dependency
140
104
  name: activesupport
141
- requirement: !ruby/object:Gem::Requirement
142
- requirements:
143
- - - '>='
144
- - !ruby/object:Gem::Version
145
- version: '3.2'
146
- type: :runtime
147
105
  prerelease: false
148
- version_requirements: !ruby/object:Gem::Requirement
149
- requirements:
150
- - - '>='
151
- - !ruby/object:Gem::Version
152
- version: '3.2'
153
- - !ruby/object:Gem::Dependency
154
- name: activerecord
155
- requirement: !ruby/object:Gem::Requirement
156
- requirements:
157
- - - '>='
158
- - !ruby/object:Gem::Version
159
- version: '3.2'
106
+ requirement: &id011 !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - &id012 !ruby/object:Gem::Version
110
+ version: "3.2"
160
111
  type: :runtime
112
+ version_requirements: *id011
113
+ - !ruby/object:Gem::Dependency
114
+ name: activerecord
161
115
  prerelease: false
162
- version_requirements: !ruby/object:Gem::Requirement
163
- requirements:
164
- - - '>='
165
- - !ruby/object:Gem::Version
166
- version: '3.2'
167
- - !ruby/object:Gem::Dependency
168
- name: awesome_print
169
- requirement: !ruby/object:Gem::Requirement
170
- requirements:
171
- - - ~>
172
- - !ruby/object:Gem::Version
173
- version: '1.2'
116
+ requirement: &id013 !ruby/object:Gem::Requirement
117
+ requirements:
118
+ - - ">="
119
+ - *id012
174
120
  type: :runtime
121
+ version_requirements: *id013
122
+ - !ruby/object:Gem::Dependency
123
+ name: awesome_print
175
124
  prerelease: false
176
- version_requirements: !ruby/object:Gem::Requirement
177
- requirements:
178
- - - ~>
179
- - !ruby/object:Gem::Version
180
- version: '1.2'
181
- - !ruby/object:Gem::Dependency
182
- name: bunny
183
- requirement: !ruby/object:Gem::Requirement
184
- requirements:
125
+ requirement: &id014 !ruby/object:Gem::Requirement
126
+ requirements:
185
127
  - - ~>
186
- - !ruby/object:Gem::Version
187
- version: 1.2.1
128
+ - !ruby/object:Gem::Version
129
+ version: "1.2"
188
130
  type: :runtime
131
+ version_requirements: *id014
132
+ - !ruby/object:Gem::Dependency
133
+ name: bunny
189
134
  prerelease: false
190
- version_requirements: !ruby/object:Gem::Requirement
191
- requirements:
135
+ requirement: &id015 !ruby/object:Gem::Requirement
136
+ requirements:
192
137
  - - ~>
193
- - !ruby/object:Gem::Version
138
+ - !ruby/object:Gem::Version
194
139
  version: 1.2.1
195
- - !ruby/object:Gem::Dependency
196
- name: json
197
- requirement: !ruby/object:Gem::Requirement
198
- requirements:
199
- - - ~>
200
- - !ruby/object:Gem::Version
201
- version: '1.8'
202
140
  type: :runtime
141
+ version_requirements: *id015
142
+ - !ruby/object:Gem::Dependency
143
+ name: json
203
144
  prerelease: false
204
- version_requirements: !ruby/object:Gem::Requirement
205
- requirements:
145
+ requirement: &id016 !ruby/object:Gem::Requirement
146
+ requirements:
206
147
  - - ~>
207
- - !ruby/object:Gem::Version
208
- version: '1.8'
148
+ - !ruby/object:Gem::Version
149
+ version: "1.8"
150
+ type: :runtime
151
+ version_requirements: *id016
209
152
  description: Lightweight, opinionated wrapper for using RabbitMQ headers exchanges
210
- email:
153
+ email:
211
154
  - nkeyes@gmail.com
212
155
  executables: []
156
+
213
157
  extensions: []
158
+
214
159
  extra_rdoc_files: []
215
- files:
160
+
161
+ files:
216
162
  - .gitignore
217
163
  - .rspec
218
164
  - .travis.yml
@@ -258,30 +204,29 @@ files:
258
204
  - spec/spec_helper.rb
259
205
  - tasks/bump.rake
260
206
  homepage: https://github.com/nkeyes/philotic
261
- licenses:
207
+ licenses:
262
208
  - MIT
263
209
  metadata: {}
210
+
264
211
  post_install_message:
265
212
  rdoc_options: []
266
- require_paths:
213
+
214
+ require_paths:
267
215
  - lib
268
- required_ruby_version: !ruby/object:Gem::Requirement
269
- requirements:
270
- - - '>='
271
- - !ruby/object:Gem::Version
272
- version: '0'
273
- required_rubygems_version: !ruby/object:Gem::Requirement
274
- requirements:
275
- - - '>='
276
- - !ruby/object:Gem::Version
277
- version: '0'
216
+ required_ruby_version: !ruby/object:Gem::Requirement
217
+ requirements:
218
+ - *id009
219
+ required_rubygems_version: !ruby/object:Gem::Requirement
220
+ requirements:
221
+ - *id009
278
222
  requirements: []
223
+
279
224
  rubyforge_project:
280
- rubygems_version: 2.2.2
225
+ rubygems_version: 2.4.5
281
226
  signing_key:
282
227
  specification_version: 4
283
228
  summary: Lightweight, opinionated wrapper for using RabbitMQ headers exchanges
284
- test_files:
229
+ test_files:
285
230
  - spec/philotic/config_spec.rb
286
231
  - spec/philotic/connection_spec.rb
287
232
  - spec/philotic/event_spec.rb
@@ -291,4 +236,3 @@ test_files:
291
236
  - spec/philotic/subscriber_spec.rb
292
237
  - spec/philotic_spec.rb
293
238
  - spec/spec_helper.rb
294
- has_rdoc: