marples 1.0.2 → 1.0.4

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -12,7 +12,8 @@ As Postmaster, Ernest Marples introduced postcodes to the UK, making message
12
12
  routing easier.
13
13
 
14
14
  Marples, this gem, removes any uncertainty about which destination our messages
15
- go to by enforcing a naming scheme.
15
+ go to by enforcing a naming scheme, and means we don't care about which
16
+ transport representation is used, because these details are hidden from us.
16
17
 
17
18
 
18
19
  ## Usage
@@ -27,13 +28,38 @@ go to by enforcing a naming scheme.
27
28
  ### Listening for messages
28
29
 
29
30
  stomp = Stomp::Client.new ...
30
- m = Marples::Client.new stomp
31
+ m = Marples::Client.new transport: stomp
31
32
  m.when 'publisher', 'publication', 'updated' do |publication|
32
33
  puts publication['slug']
33
34
  # => "how-postcodes-work"
34
35
  end
35
36
  m.join # Join the listening thread
36
37
 
38
+ ### Adding more content to a message
39
+
40
+ Some objects are only useful with more information eg an Account object is maybe
41
+ only useful when it has a list of all customers as well.
42
+
43
+ It's possible that you could override `#to_xml` for each object, but that feels
44
+ a little messy.
45
+
46
+ Normally of course you'd use an implementation of
47
+ [Data Enricher](http://eaipatterns.com/DataEnricher.html) but if, for some
48
+ reason, you don't have anywhere to implement these integration patterns, you can
49
+ choose to implement your own message payload generator:
50
+
51
+ stomp = Stomp::Client.new ...
52
+ m = Marples::Client.new transport: stomp, client_name: "publisher"
53
+ m.payload_for Account do |account|
54
+ account.to_xml :include => :customers
55
+ end
56
+
57
+ account = Account.find ...
58
+ m.updated account
59
+
60
+ Marples expects XML data to be put on the bus, if you choose to return something
61
+ that's not XML then you're on your own.
62
+
37
63
 
38
64
  ## Logging
39
65
 
@@ -58,12 +58,27 @@ module Marples
58
58
  destination = destination_for client_name, object_type, action
59
59
  logger.debug "Using transport #{transport}"
60
60
  logger.debug "Sending XML to #{destination}"
61
- logger.debug "XML: #{object.to_xml}"
62
- transport.publish destination, object.to_xml
61
+ payload = generate_payload_for object
62
+ logger.debug "XML: #{payload}"
63
+ transport.publish destination, payload
63
64
  logger.debug "Message sent"
64
65
  end
65
66
  private :publish
66
67
 
68
+ def payload_for klass, &block
69
+ payload_generator[klass] = block
70
+ end
71
+
72
+ def generate_payload_for object
73
+ payload_generator[object.class].call object
74
+ end
75
+ private :generate_payload_for
76
+
77
+ def payload_generator
78
+ @payload_generator ||= Hash.new(lambda { |o| o.to_xml })
79
+ end
80
+ private :payload_generator
81
+
67
82
  def destination_for application_name, object_type, action
68
83
  "/topic/marples.#{application_name}.#{object_type}.#{action}"
69
84
  end
@@ -13,7 +13,7 @@ module Marples
13
13
  # If you'd like the actions performed by Marples to be logged, set a
14
14
  # logger. By default this uses the NullLogger.
15
15
  class_attribute :marples_logger
16
- self.marples_logger = Rails.logger
16
+ self.marples_logger = NullLogger.instance
17
17
 
18
18
  CALLBACKS.each do |callback|
19
19
  callback_action = callback.to_s =~ /e$/ ? "#{callback}d" : "#{callback}ed"
@@ -1,3 +1,3 @@
1
1
  module Marples
2
- VERSION = "1.0.2"
2
+ VERSION = "1.0.4"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: marples
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,11 +10,11 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2011-11-25 00:00:00.000000000 Z
13
+ date: 2011-12-02 00:00:00.000000000Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: null_logger
17
- requirement: &70212070634820 !ruby/object:Gem::Requirement
17
+ requirement: &70125815622680 !ruby/object:Gem::Requirement
18
18
  none: false
19
19
  requirements:
20
20
  - - ! '>='
@@ -22,10 +22,10 @@ dependencies:
22
22
  version: '0'
23
23
  type: :runtime
24
24
  prerelease: false
25
- version_requirements: *70212070634820
25
+ version_requirements: *70125815622680
26
26
  - !ruby/object:Gem::Dependency
27
27
  name: activesupport
28
- requirement: &70212070633860 !ruby/object:Gem::Requirement
28
+ requirement: &70125815621380 !ruby/object:Gem::Requirement
29
29
  none: false
30
30
  requirements:
31
31
  - - ! '>='
@@ -33,10 +33,10 @@ dependencies:
33
33
  version: '0'
34
34
  type: :runtime
35
35
  prerelease: false
36
- version_requirements: *70212070633860
36
+ version_requirements: *70125815621380
37
37
  - !ruby/object:Gem::Dependency
38
38
  name: i18n
39
- requirement: &70212070632780 !ruby/object:Gem::Requirement
39
+ requirement: &70125815620380 !ruby/object:Gem::Requirement
40
40
  none: false
41
41
  requirements:
42
42
  - - ! '>='
@@ -44,10 +44,10 @@ dependencies:
44
44
  version: '0'
45
45
  type: :runtime
46
46
  prerelease: false
47
- version_requirements: *70212070632780
47
+ version_requirements: *70125815620380
48
48
  - !ruby/object:Gem::Dependency
49
49
  name: rake
50
- requirement: &70212070631880 !ruby/object:Gem::Requirement
50
+ requirement: &70125815619300 !ruby/object:Gem::Requirement
51
51
  none: false
52
52
  requirements:
53
53
  - - ! '>='
@@ -55,10 +55,10 @@ dependencies:
55
55
  version: '0'
56
56
  type: :development
57
57
  prerelease: false
58
- version_requirements: *70212070631880
58
+ version_requirements: *70125815619300
59
59
  - !ruby/object:Gem::Dependency
60
60
  name: activerecord
61
- requirement: &70212070630920 !ruby/object:Gem::Requirement
61
+ requirement: &70125815618520 !ruby/object:Gem::Requirement
62
62
  none: false
63
63
  requirements:
64
64
  - - ! '>='
@@ -66,10 +66,10 @@ dependencies:
66
66
  version: '0'
67
67
  type: :development
68
68
  prerelease: false
69
- version_requirements: *70212070630920
69
+ version_requirements: *70125815618520
70
70
  - !ruby/object:Gem::Dependency
71
71
  name: activerecord-nulldb-adapter
72
- requirement: &70212070629780 !ruby/object:Gem::Requirement
72
+ requirement: &70125815617880 !ruby/object:Gem::Requirement
73
73
  none: false
74
74
  requirements:
75
75
  - - ! '>='
@@ -77,7 +77,7 @@ dependencies:
77
77
  version: '0'
78
78
  type: :development
79
79
  prerelease: false
80
- version_requirements: *70212070629780
80
+ version_requirements: *70125815617880
81
81
  description: Message destination arbiter
82
82
  email:
83
83
  - craig@barkingiguana.com
@@ -113,18 +113,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
113
113
  - - ! '>='
114
114
  - !ruby/object:Gem::Version
115
115
  version: '0'
116
- segments:
117
- - 0
118
- hash: 2905283016913556502
119
116
  required_rubygems_version: !ruby/object:Gem::Requirement
120
117
  none: false
121
118
  requirements:
122
119
  - - ! '>='
123
120
  - !ruby/object:Gem::Version
124
121
  version: '0'
125
- segments:
126
- - 0
127
- hash: 2905283016913556502
128
122
  requirements: []
129
123
  rubyforge_project: marples
130
124
  rubygems_version: 1.8.10