dispatch-rider 0.1.2 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,15 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 093cafac338ae5b0c8b1c904a165ea70fb7b9c51
4
- data.tar.gz: e2a11b4fb385a9c378cbc34f306187cb43bcef7e
2
+ !binary "U0hBMQ==":
3
+ metadata.gz: !binary |-
4
+ MTkzOGNhMTYyMGFlNzUxMWJjM2MyY2ZmNjRmZTAxZTlkMTk3NDY5Mw==
5
+ data.tar.gz: !binary |-
6
+ ZjQxZDVmOTIxYTc3N2U1NWYwYTQzODQ1MDNjZTk2YjFmMmQ1ZjQ3OQ==
5
7
  SHA512:
6
- metadata.gz: 8927e40c071aa98fc1bc00821d65ebb2be8ae7a6c903f95a474806596c068f9aaadc620d1979ee2023e936b8d090824e8319bc02a96515c29651cff234871397
7
- data.tar.gz: 5fed12410bb43754a04c578dca723e5f5dca29132f7f3e451660d54784a5d4b9df73f215c594a86a54629c6a29f5f6c232f5f26d726f7796f7a5eb1393c7660a
8
+ metadata.gz: !binary |-
9
+ YjE4NTI3OGYzY2MzMzJiODBkZDFjZGU0MDcwNjZkODM2OGViNzY5MGU1YmM5
10
+ MTg2Y2RjNTZiYjY4ZGE0N2ViYTYwMDRmYzg5MjYzNTUxODY3MTUyYTg0MDEz
11
+ Mjk4ZDA1OGNhY2ZlNTNhODUxNDllNmI1YTUwMWNhNGY0MjIyYjc=
12
+ data.tar.gz: !binary |-
13
+ OTg0OGQxMDYyNWMzYTgyMjg0NWQxYWMyNjI5NzY3M2NmODM4OWQyMjU0ZmEw
14
+ YTg2YTJkMTUxZjUyNGZiZTc1NzJjMjVhMzdmZTBhNjIxY2I1N2U4NDI1NWMy
15
+ ZDZiZGQ0OTY3MDFiZWY2YzcxMjY5NGZkMmU1M2MxNDdmNDIzYmY=
data/README.md CHANGED
@@ -34,11 +34,12 @@ Setting up a publisher is simple.
34
34
  All configuration can be loaded from a hash instead of being done like the examples below.
35
35
  (currently only implemented for the publisher)
36
36
 
37
- eg:
37
+ #### Global configuration
38
+
39
+ You can set the global configuration using either a hash:
38
40
 
39
41
  ```ruby
40
- publisher = DispatchRider::Publisher.new
41
- publisher.configure({
42
+ DispatchRider::Publisher.configure({
42
43
  notification_services: {
43
44
  file_system: {}
44
45
  },
@@ -54,6 +55,59 @@ publisher.configure({
54
55
  })
55
56
  ```
56
57
 
58
+ or a block:
59
+
60
+ ```ruby
61
+ DispatchRider::Publisher.configure do |config|
62
+ config.parse({
63
+ notification_services: {
64
+ file_system: {}
65
+ },
66
+ destinations: {
67
+ file_foo: {
68
+ service: :file_system,
69
+ channel: :foo,
70
+ options: {
71
+ path: "test/channel",
72
+ }
73
+ }
74
+ }
75
+ })
76
+ end
77
+ ```
78
+
79
+ Then anytime you call configure on a new publisher, it will default to global configuration.
80
+
81
+ ```ruby
82
+ DispatchRider::Publisher.new
83
+
84
+ # is the same as
85
+
86
+ DispatchRider::Publisher.new(DispatchRider::Publisher.configuration)
87
+ ```
88
+
89
+ #### Local configuration
90
+ Alternatively, you can create your own configuration and load that configuration into your new publisher.
91
+
92
+ ```ruby
93
+ config = DispatchRider::Publisher::Configuration.new({
94
+ notification_services: {
95
+ file_system: {}
96
+ },
97
+ destinations: {
98
+ file_foo: {
99
+ service: :file_system,
100
+ channel: :foo,
101
+ options: {
102
+ path: "test/channel",
103
+ }
104
+ }
105
+ }
106
+ })
107
+
108
+ DispatchRider::Publisher.new(config)
109
+ ```
110
+
57
111
  You can load this configuration hash from a YAML file or something, whatever works
58
112
  well for your environment.
59
113
 
@@ -114,54 +168,17 @@ Sample Rails publisher:
114
168
 
115
169
  ```ruby
116
170
  # app/publishers/news_update
117
- class NewsPublisher
118
- @publisher = DispatchRider::Publisher.new
119
-
120
- amazon_config = YAML.load_file("#{Rails.root}/config/amazon.yml")
121
-
122
- @publisher.register_notification_service(:aws_sns)
123
- @publisher.register_destination(:sns_message_queue, :aws_sns, :dev_channel, {
124
- :account => amazon_config[:account],
125
- :region => amazon_config[:region],
126
- :topic => "news-updates-#{Rails.env}"
127
- })
128
-
129
- @destinations = [:sns_message_queue]
171
+ class NewsPublisher < DispatchRider::Publisher::Base
130
172
 
131
- class << self
132
- attr_reader :publisher
133
- attr_accessor :destinations
134
- end
135
-
136
- delegate :publisher, :destinations, :to => :"self.class"
173
+ destinations :sns_message_queue
174
+ subject "read_news"
137
175
 
138
- def initialize(news)
139
- @news = news
176
+ def self.publish(news)
177
+ publish({"headlines" => news.headlines})
140
178
  end
141
179
 
142
- def publish
143
- publisher.publish(:destinations => destinations, :message => {
144
- :subject => "read_news",
145
- :body => {"headlines" => @news.headlines}
146
- })
147
- end
148
- end
149
-
150
- # app/models/news
151
- class News
152
- serialize :headlines, Array
153
-
154
- after_create :publish
155
-
156
- def publish
157
- NewsPublisher.new(self).publish
158
- end
159
180
  end
160
181
 
161
- News.create!(:headlines => [
162
- "April 29, 2013: Rails 4.0.0.rc1 is released.",
163
- "May 14, 2013: Ruby 2.0.0-p195 is released"
164
- ])
165
182
  ```
166
183
 
167
184
  ### Subscriber
@@ -1,18 +1,19 @@
1
1
  require "active_support/core_ext/hash/indifferent_access"
2
+ require_relative "publisher/configuration_support"
2
3
 
3
4
  # This class takes care of the publishing side of the messaging system.
4
5
  module DispatchRider
5
6
  class Publisher
6
- attr_reader :service_channel_mapper, :notification_service_registrar, :publishing_destination_registrar, :sns_channel_registrar
7
+ extend ConfigurationSupport
7
8
 
8
- def configure(configuration_hash = {})
9
- ConfigurationReader.parse(configuration_hash.with_indifferent_access, self)
10
- end
9
+ attr_reader :service_channel_mapper, :notification_service_registrar, :publishing_destination_registrar, :sns_channel_registrar
11
10
 
12
- def initialize
11
+ def initialize(configuration = self.class.configuration)
13
12
  @notification_service_registrar = DispatchRider::Registrars::NotificationService.new
14
13
  @publishing_destination_registrar = DispatchRider::Registrars::PublishingDestination.new
15
14
  @service_channel_mapper = ServiceChannelMapper.new(publishing_destination_registrar)
15
+
16
+ ConfigurationReader.load_config(configuration, self)
16
17
  end
17
18
 
18
19
  def register_notification_service(name, options = {})
@@ -70,4 +71,6 @@ module DispatchRider
70
71
  end
71
72
  end
72
73
 
74
+ require_relative "publisher/configuration"
73
75
  require_relative "publisher/configuration_reader"
76
+ require_relative "publisher/base"
@@ -0,0 +1,47 @@
1
+ module DispatchRider
2
+ class Publisher::Base
3
+
4
+ class << self
5
+
6
+ def subject(subject)
7
+ @subject = subject
8
+ end
9
+
10
+ def destinations(destinations)
11
+ @destinations = Array(destinations)
12
+ end
13
+
14
+ def default_publisher
15
+ @@default_publisher ||= DispatchRider::Publisher.new
16
+ end
17
+
18
+ def publish(*args, &block)
19
+ raise NotImplementedError
20
+ end
21
+
22
+ end
23
+
24
+ def initialize(publisher = nil)
25
+ @publisher = publisher
26
+ end
27
+
28
+ def publish(body)
29
+ publisher.publish(destinations: destinations, message: { subject: subject, body: body })
30
+ end
31
+
32
+ private
33
+
34
+ def publisher
35
+ @publisher || self.class.default_publisher
36
+ end
37
+
38
+ def destinations
39
+ self.class.instance_variable_get(:@destinations)
40
+ end
41
+
42
+ def subject
43
+ self.class.instance_variable_get(:@subject)
44
+ end
45
+
46
+ end
47
+ end
@@ -0,0 +1,49 @@
1
+ module DispatchRider
2
+ class Publisher::Configuration
3
+
4
+ def initialize(configuration_hash = {})
5
+ @notification_services = []
6
+ @destinations = []
7
+ parse(configuration_hash)
8
+ end
9
+
10
+ def notification_services
11
+ @notification_services
12
+ end
13
+
14
+ def destinations
15
+ @destinations
16
+ end
17
+
18
+ def parse(configuration_hash)
19
+ clear
20
+
21
+ configuration_hash = configuration_hash.with_indifferent_access
22
+ configure_notification_services(configuration_hash[:notification_services] || {})
23
+ configure_destinations(configuration_hash[:destinations] || {})
24
+ end
25
+
26
+ def clear
27
+ @notification_services.clear
28
+ @destinations.clear
29
+ end
30
+
31
+ private
32
+
33
+ def configure_notification_services(notification_services_hash)
34
+ notification_services_hash.each do |name, options|
35
+ @notification_services << NotificationService.new(name, options)
36
+ end
37
+ end
38
+
39
+ def configure_destinations(destinations_hash)
40
+ destinations_hash.each do |name, options|
41
+ @destinations << Destination.new(name, options)
42
+ end
43
+ end
44
+
45
+ end
46
+ end
47
+
48
+ require_relative "configuration/destination"
49
+ require_relative "configuration/notification_service"
@@ -0,0 +1,23 @@
1
+ module DispatchRider
2
+ class Publisher::Configuration::Destination
3
+
4
+ def initialize(name, attributes={})
5
+ @name = name
6
+
7
+ attributes = attributes.with_indifferent_access
8
+ @service = attributes[:service]
9
+ @channel = attributes[:channel]
10
+ @options = attributes[:options]
11
+ end
12
+
13
+ attr_reader :name, :service, :channel, :options
14
+
15
+ def ==(other)
16
+ self.name == other.name &&
17
+ self.service == other.service &&
18
+ self.channel == other.channel &&
19
+ self.options == other.options
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,17 @@
1
+ module DispatchRider
2
+ class Publisher::Configuration::NotificationService
3
+
4
+ def initialize(name, options)
5
+ @name = name
6
+ @options = options
7
+ end
8
+
9
+ attr_reader :name, :options
10
+
11
+ def ==(other)
12
+ self.name == other.name &&
13
+ self.options == other.options
14
+ end
15
+
16
+ end
17
+ end
@@ -1,32 +1,29 @@
1
1
  module DispatchRider
2
-
3
2
  class Publisher
4
-
5
3
  module ConfigurationReader
6
4
 
7
5
  class << self
8
- def parse(configuration_hash, publisher)
9
- configure_notification_services(configuration_hash[:notification_services], publisher) if configuration_hash[:notification_services]
10
- configure_destinations(configuration_hash[:destinations], publisher) if configuration_hash[:destinations]
6
+ def load_config(configuration, publisher)
7
+ configure_notification_services(configuration.notification_services, publisher)
8
+ configure_destinations(configuration.destinations, publisher)
11
9
  end
12
10
 
13
11
  private
14
12
 
15
- def configure_notification_services(notification_services, publisher)
16
- notification_services.each do |(service_name, service_options)|
17
- publisher.register_notification_service(service_name, service_options)
18
- end
13
+ def configure_notification_services(notification_services, publisher)
14
+ notification_services.each do |service|
15
+ publisher.register_notification_service(service.name, service.options)
19
16
  end
17
+ end
20
18
 
21
- def configure_destinations(destinations, publisher)
22
- destinations.each do |(destination_name, info)|
23
- publisher.register_destination(destination_name, info[:service], info[:channel], info[:options])
24
- end
19
+ def configure_destinations(destinations, publisher)
20
+ destinations.each do |destination|
21
+ publisher.register_destination(destination.name, destination.service, destination.channel, destination.options)
25
22
  end
23
+ end
26
24
 
27
25
  end
28
- end
29
26
 
27
+ end
30
28
  end
31
-
32
29
  end
@@ -0,0 +1,20 @@
1
+ module DispatchRider
2
+ class Publisher
3
+ module ConfigurationSupport
4
+
5
+ def configuration
6
+ @configuration ||= Configuration.new
7
+ end
8
+ alias_method :config, :configuration
9
+
10
+ def configure(configuration_hash = {})
11
+ if block_given?
12
+ yield configuration
13
+ else
14
+ configuration.parse(configuration_hash)
15
+ end
16
+ end
17
+
18
+ end
19
+ end
20
+ end
@@ -1,4 +1,4 @@
1
1
  # This file specifies the current version of the gem.
2
2
  module DispatchRider
3
- VERSION = "0.1.2"
3
+ VERSION = "0.2.0"
4
4
  end
metadata CHANGED
@@ -1,69 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dispatch-rider
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Suman Mukherjee
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-11-01 00:00:00.000000000 Z
11
+ date: 2013-11-13 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - '>='
17
+ - - ! '>='
18
18
  - !ruby/object:Gem::Version
19
19
  version: '0'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - '>='
24
+ - - ! '>='
25
25
  - !ruby/object:Gem::Version
26
26
  version: '0'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: activemodel
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - '>='
31
+ - - ! '>='
32
32
  - !ruby/object:Gem::Version
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - '>='
38
+ - - ! '>='
39
39
  - !ruby/object:Gem::Version
40
40
  version: '0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: daemons
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - '>='
45
+ - - ! '>='
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - '>='
52
+ - - ! '>='
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: bundler
57
57
  requirement: !ruby/object:Gem::Requirement
58
58
  requirements:
59
- - - '>='
59
+ - - ! '>='
60
60
  - !ruby/object:Gem::Version
61
61
  version: '0'
62
62
  type: :development
63
63
  prerelease: false
64
64
  version_requirements: !ruby/object:Gem::Requirement
65
65
  requirements:
66
- - - '>='
66
+ - - ! '>='
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
69
  - !ruby/object:Gem::Dependency
@@ -72,68 +72,70 @@ dependencies:
72
72
  requirements:
73
73
  - - ~>
74
74
  - !ruby/object:Gem::Version
75
- version: 1.8.4
75
+ version: !binary |-
76
+ MS44LjQ=
76
77
  type: :development
77
78
  prerelease: false
78
79
  version_requirements: !ruby/object:Gem::Requirement
79
80
  requirements:
80
81
  - - ~>
81
82
  - !ruby/object:Gem::Version
82
- version: 1.8.4
83
+ version: !binary |-
84
+ MS44LjQ=
83
85
  - !ruby/object:Gem::Dependency
84
86
  name: rake
85
87
  requirement: !ruby/object:Gem::Requirement
86
88
  requirements:
87
- - - '>='
89
+ - - ! '>='
88
90
  - !ruby/object:Gem::Version
89
91
  version: '0'
90
92
  type: :development
91
93
  prerelease: false
92
94
  version_requirements: !ruby/object:Gem::Requirement
93
95
  requirements:
94
- - - '>='
96
+ - - ! '>='
95
97
  - !ruby/object:Gem::Version
96
98
  version: '0'
97
99
  - !ruby/object:Gem::Dependency
98
100
  name: travis-lint
99
101
  requirement: !ruby/object:Gem::Requirement
100
102
  requirements:
101
- - - '>='
103
+ - - ! '>='
102
104
  - !ruby/object:Gem::Version
103
105
  version: '0'
104
106
  type: :development
105
107
  prerelease: false
106
108
  version_requirements: !ruby/object:Gem::Requirement
107
109
  requirements:
108
- - - '>='
110
+ - - ! '>='
109
111
  - !ruby/object:Gem::Version
110
112
  version: '0'
111
113
  - !ruby/object:Gem::Dependency
112
114
  name: rspec
113
115
  requirement: !ruby/object:Gem::Requirement
114
116
  requirements:
115
- - - '>='
117
+ - - ! '>='
116
118
  - !ruby/object:Gem::Version
117
119
  version: '0'
118
120
  type: :development
119
121
  prerelease: false
120
122
  version_requirements: !ruby/object:Gem::Requirement
121
123
  requirements:
122
- - - '>='
124
+ - - ! '>='
123
125
  - !ruby/object:Gem::Version
124
126
  version: '0'
125
127
  - !ruby/object:Gem::Dependency
126
128
  name: debugger
127
129
  requirement: !ruby/object:Gem::Requirement
128
130
  requirements:
129
- - - '>='
131
+ - - ! '>='
130
132
  - !ruby/object:Gem::Version
131
133
  version: '0'
132
134
  type: :development
133
135
  prerelease: false
134
136
  version_requirements: !ruby/object:Gem::Requirement
135
137
  requirements:
136
- - - '>='
138
+ - - ! '>='
137
139
  - !ruby/object:Gem::Version
138
140
  version: '0'
139
141
  description: Messaging system that is customizable based on which queueing system
@@ -168,7 +170,12 @@ files:
168
170
  - lib/dispatch-rider/notification_services/file_system/channel.rb
169
171
  - lib/dispatch-rider/notification_services/file_system/notifier.rb
170
172
  - lib/dispatch-rider/publisher.rb
173
+ - lib/dispatch-rider/publisher/base.rb
174
+ - lib/dispatch-rider/publisher/configuration.rb
175
+ - lib/dispatch-rider/publisher/configuration/destination.rb
176
+ - lib/dispatch-rider/publisher/configuration/notification_service.rb
171
177
  - lib/dispatch-rider/publisher/configuration_reader.rb
178
+ - lib/dispatch-rider/publisher/configuration_support.rb
172
179
  - lib/dispatch-rider/queue_services.rb
173
180
  - lib/dispatch-rider/queue_services/aws_sqs.rb
174
181
  - lib/dispatch-rider/queue_services/aws_sqs/message_body_extractor.rb
@@ -199,17 +206,17 @@ require_paths:
199
206
  - lib
200
207
  required_ruby_version: !ruby/object:Gem::Requirement
201
208
  requirements:
202
- - - '>='
209
+ - - ! '>='
203
210
  - !ruby/object:Gem::Version
204
211
  version: '0'
205
212
  required_rubygems_version: !ruby/object:Gem::Requirement
206
213
  requirements:
207
- - - '>='
214
+ - - ! '>='
208
215
  - !ruby/object:Gem::Version
209
216
  version: '0'
210
217
  requirements: []
211
218
  rubyforge_project:
212
- rubygems_version: 2.0.3
219
+ rubygems_version: 2.1.10
213
220
  signing_key:
214
221
  specification_version: 4
215
222
  summary: Messaging system based on the reactor patter. You can publish messages to