marples 0.0.16

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.
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in marples.gemspec
4
+ gemspec
data/README.md ADDED
@@ -0,0 +1,47 @@
1
+ # Marples
2
+
3
+ A message destination arbiter.
4
+
5
+ "Alfred Ernest Marples, Baron Marples PC (9 December 1907 – 6 July 1978) was
6
+ a British Conservative politician who served as Postmaster General and
7
+ Minister of Transport. Following his retirement from active politics in
8
+ 1974, Marples was elevated to the peerage."
9
+ -- http://en.wikipedia.org/wiki/Ernest_Marples
10
+
11
+ As Postmaster, Ernest Marples introduced postcodes to the UK, making message
12
+ routing easier.
13
+
14
+ Marples, this gem, removes any uncertainty about which destination our messages
15
+ go to by enforcing a naming scheme.
16
+
17
+
18
+ ## Usage
19
+
20
+ ### Sending a message
21
+
22
+ stomp_client = Stomp::Client.new ...
23
+ m = Marples::Client.new stomp_client, "publisher"
24
+ m.updated publication
25
+ # => /topic/publisher.publications.updated
26
+ { 'guide' => { 'id' => 12345, 'title' => '...', ... }}
27
+
28
+ ### Listening for messages
29
+
30
+ stomp_client = Stomp::Client.new ...
31
+ m = Marples::Client.new stomp_client
32
+ m.when 'publisher', 'publication', 'updated' do |publication|
33
+ puts publication['slug']
34
+ # => "how-postcodes-work"
35
+ end
36
+ m.join # Join the listening thread
37
+
38
+
39
+ ## Logging
40
+
41
+ You can inject your logger into Marples to get some debugging information.
42
+
43
+ logger = Logger.new STDOUT
44
+ logger.level = Logger::DEBUG
45
+ producer = Marples::Client.new stomp_client, "publisher", logger
46
+ ...
47
+ consumer = Marples::Client.new stomp_client, 'consumer_name_here', logger
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,54 @@
1
+ module Marples
2
+ class Client
3
+ include Pethau::InitializeWith
4
+ include Pethau::DefaultValueOf
5
+
6
+ ACTIONS = [ :updated, :published ].freeze
7
+
8
+ initialize_with :transport, :client_name, :logger
9
+ default_value_of :client_name, File.basename($0)
10
+ default_value_of :transport, Marples::NullTransport.instance
11
+ default_value_of :logger, NullLogger.instance
12
+
13
+ def join
14
+ transport.join
15
+ end
16
+
17
+ def method_missing action, *args
18
+ return super unless ACTIONS.include? action
19
+ return super unless args.size == 1
20
+ publish action, args[0]
21
+ end
22
+
23
+ def when application, object_type, action
24
+ logger.debug "Listening for #{application} notifiying us of #{object_type} #{action}"
25
+ destination = destination_for application, object_type, action
26
+ logger.debug "Underlying destination is #{destination}"
27
+ transport.subscribe destination do |message|
28
+ logger.debug "Received message #{message.headers['message-id']} from #{destination}"
29
+ logger.debug "Message body: #{message.body}"
30
+ hash = Hash.from_xml message.body
31
+ logger.debug "Constructed hash: #{hash.inspect}"
32
+ attributes = hash.values[0]
33
+ logger.debug "Yielding hash: #{attributes.inspect}"
34
+ yield attributes
35
+ logger.debug "Finished processing message #{message.headers['message-id']}"
36
+ end
37
+ end
38
+
39
+ def publish action, object
40
+ object_type = object.class.name.tableize
41
+ destination = destination_for object_type, action
42
+ logger.debug "Sending XML to #{destination}"
43
+ logger.debug "XML: #{object.to_xml}"
44
+ transport.publish destination, object.to_xml
45
+ logger.debug "Message sent"
46
+ end
47
+ private :publish
48
+
49
+ def destination_for application_name = client_name, object_type, action
50
+ "/topic/#{application_name}.#{object_type}.#{action}"
51
+ end
52
+ private :destination_for
53
+ end
54
+ end
@@ -0,0 +1,8 @@
1
+ module Marples
2
+ class NullTransport
3
+ include Singleton
4
+ def publish *args; end
5
+ def subscribe *args; end
6
+ def join; end
7
+ end
8
+ end
@@ -0,0 +1,3 @@
1
+ module Marples
2
+ VERSION = "0.0.16"
3
+ end
data/lib/marples.rb ADDED
@@ -0,0 +1,10 @@
1
+ require "pethau"
2
+ require "null_logger"
3
+ require "active_support/core_ext/hash/conversions"
4
+
5
+ require "marples/version"
6
+ require "marples/null_transport"
7
+ require "marples/client"
8
+
9
+ module Marples
10
+ end
data/marples.gemspec ADDED
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "marples/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "marples"
7
+ s.version = Marples::VERSION
8
+ s.authors = ["Craig R Webster", "Dafydd Vaughan"]
9
+ s.email = ["craig@barkingiguana.com", "dai@daibach.co.uk"]
10
+ s.homepage = ""
11
+ s.summary = %q{Message destination arbiter}
12
+ s.description = %q{Message destination arbiter}
13
+ s.rubyforge_project = "marples"
14
+
15
+ s.files = `git ls-files`.split("\n")
16
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
17
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
18
+ s.require_paths = ["lib"]
19
+
20
+ s.add_runtime_dependency "pethau", ">= 0.0.2"
21
+ s.add_runtime_dependency "null_logger"
22
+ s.add_runtime_dependency "activesupport"
23
+ end
metadata ADDED
@@ -0,0 +1,89 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: marples
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.16
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Craig R Webster
9
+ - Dafydd Vaughan
10
+ autorequire:
11
+ bindir: bin
12
+ cert_chain: []
13
+ date: 2011-10-26 00:00:00.000000000Z
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: pethau
17
+ requirement: &70334281116860 !ruby/object:Gem::Requirement
18
+ none: false
19
+ requirements:
20
+ - - ! '>='
21
+ - !ruby/object:Gem::Version
22
+ version: 0.0.2
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: *70334281116860
26
+ - !ruby/object:Gem::Dependency
27
+ name: null_logger
28
+ requirement: &70334281116440 !ruby/object:Gem::Requirement
29
+ none: false
30
+ requirements:
31
+ - - ! '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: *70334281116440
37
+ - !ruby/object:Gem::Dependency
38
+ name: activesupport
39
+ requirement: &70334281115980 !ruby/object:Gem::Requirement
40
+ none: false
41
+ requirements:
42
+ - - ! '>='
43
+ - !ruby/object:Gem::Version
44
+ version: '0'
45
+ type: :runtime
46
+ prerelease: false
47
+ version_requirements: *70334281115980
48
+ description: Message destination arbiter
49
+ email:
50
+ - craig@barkingiguana.com
51
+ - dai@daibach.co.uk
52
+ executables: []
53
+ extensions: []
54
+ extra_rdoc_files: []
55
+ files:
56
+ - .gitignore
57
+ - Gemfile
58
+ - README.md
59
+ - Rakefile
60
+ - lib/marples.rb
61
+ - lib/marples/client.rb
62
+ - lib/marples/null_transport.rb
63
+ - lib/marples/version.rb
64
+ - marples.gemspec
65
+ homepage: ''
66
+ licenses: []
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ none: false
79
+ requirements:
80
+ - - ! '>='
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
83
+ requirements: []
84
+ rubyforge_project: marples
85
+ rubygems_version: 1.8.10
86
+ signing_key:
87
+ specification_version: 3
88
+ summary: Message destination arbiter
89
+ test_files: []