README.md in dispatch-rider-0.1.2 vs README.md in dispatch-rider-0.2.0

- old
+ new

@@ -32,15 +32,16 @@ ### Hash Based Configuration All configuration can be loaded from a hash instead of being done like the examples below. (currently only implemented for the publisher) -eg: +#### Global configuration +You can set the global configuration using either a hash: + ```ruby -publisher = DispatchRider::Publisher.new -publisher.configure({ +DispatchRider::Publisher.configure({ notification_services: { file_system: {} }, destinations: { file_foo: { @@ -52,10 +53,63 @@ } } }) ``` +or a block: + +```ruby +DispatchRider::Publisher.configure do |config| + config.parse({ + notification_services: { + file_system: {} + }, + destinations: { + file_foo: { + service: :file_system, + channel: :foo, + options: { + path: "test/channel", + } + } + } + }) +end +``` + +Then anytime you call configure on a new publisher, it will default to global configuration. + +```ruby +DispatchRider::Publisher.new + +# is the same as + +DispatchRider::Publisher.new(DispatchRider::Publisher.configuration) +``` + +#### Local configuration +Alternatively, you can create your own configuration and load that configuration into your new publisher. + +```ruby + config = DispatchRider::Publisher::Configuration.new({ + notification_services: { + file_system: {} + }, + destinations: { + file_foo: { + service: :file_system, + channel: :foo, + options: { + path: "test/channel", + } + } + } + }) + + DispatchRider::Publisher.new(config) +``` + You can load this configuration hash from a YAML file or something, whatever works well for your environment. #### The old way ... @@ -112,57 +166,20 @@ Sample Rails publisher: ```ruby # app/publishers/news_update -class NewsPublisher - @publisher = DispatchRider::Publisher.new +class NewsPublisher < DispatchRider::Publisher::Base - amazon_config = YAML.load_file("#{Rails.root}/config/amazon.yml") + destinations :sns_message_queue + subject "read_news" - @publisher.register_notification_service(:aws_sns) - @publisher.register_destination(:sns_message_queue, :aws_sns, :dev_channel, { - :account => amazon_config[:account], - :region => amazon_config[:region], - :topic => "news-updates-#{Rails.env}" - }) - - @destinations = [:sns_message_queue] - - class << self - attr_reader :publisher - attr_accessor :destinations + def self.publish(news) + publish({"headlines" => news.headlines}) end - delegate :publisher, :destinations, :to => :"self.class" - - def initialize(news) - @news = news - end - - def publish - publisher.publish(:destinations => destinations, :message => { - :subject => "read_news", - :body => {"headlines" => @news.headlines} - }) - end end -# app/models/news -class News - serialize :headlines, Array - - after_create :publish - - def publish - NewsPublisher.new(self).publish - end -end - -News.create!(:headlines => [ - "April 29, 2013: Rails 4.0.0.rc1 is released.", - "May 14, 2013: Ruby 2.0.0-p195 is released" -]) ``` ### Subscriber ### Configuration