event_sorcerer 0.1.1 → 0.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 204474547eba7a0e9289b8dda4f55548ba225fa6
4
- data.tar.gz: 84fb8dfbd0220067c63bfe526899bb33ac9b4982
3
+ metadata.gz: 1a30a15c744e7f3f861840bbdc3cfb822a5b8a88
4
+ data.tar.gz: 11012f39e7e59b80349a947f63216cec5f28657a
5
5
  SHA512:
6
- metadata.gz: bd80f51216f11bd01f9a6d4eace6accfa0f703bbd0c9a8fff5e0265862a1e66f749e7592fd5d20b91ecb8ff980c30ba582f023d8118242d75256897bef9abb8a
7
- data.tar.gz: d13b3e23dc632637ce415212b60873a038a443fc13a585a46072afeb944f5d803df62bf835d4ac35695bc99720d0731b900968797cfa784b88d971ab1f696f97
6
+ metadata.gz: 1a2db2aaa933ed7280f7cebe9d6544bcd767a605ddc78108ed2e1911481d2efb5f7ebf2b364358b82e8777357a01190dab8e3bc11371db3b6f81844287e3c0a9
7
+ data.tar.gz: de9da895801ddd797276efdd48c55cccad6342a822eea80b6451a2e864f7b2c97bc59825c43f2387dc0137840639a65e1b31d2e92345f172a06949d2660b1d93
@@ -25,4 +25,5 @@ Gem::Specification.new do |spec|
25
25
 
26
26
  spec.add_runtime_dependency 'invokr', '~> 0.9.6'
27
27
  spec.add_runtime_dependency 'timecop', '0.7.1'
28
+ spec.add_runtime_dependency 'uber', '~> 0.0.11'
28
29
  end
@@ -13,9 +13,8 @@ module EventSorcerer
13
13
  def self.included(base)
14
14
  base.class.send :alias_method, :build, :new
15
15
  base.extend(ClassMethods)
16
- base.class.extend(Forwardable)
17
- base.class.send :def_delegators, :EventSorcerer, :event_store,
18
- :unit_of_work
16
+ base.class.extend(Uber::Delegates)
17
+ base.class.send :delegates, :EventSorcerer, :event_store, :unit_of_work
19
18
  end
20
19
 
21
20
  # Public: Class methods to be extended onto the including class.
@@ -111,7 +110,7 @@ module EventSorcerer
111
110
  # block - the block to yield the event stream to.
112
111
  #
113
112
  # Returns the return value of the given block.
114
- def with_all_event_streams_for_type()
113
+ def with_all_event_streams_for_type
115
114
  yield event_store.read_event_streams_for_type(name)
116
115
  end
117
116
 
@@ -141,7 +140,7 @@ module EventSorcerer
141
140
  #
142
141
  # Returns the return value of the given block.
143
142
  def with_event_stream_for_id(id)
144
- yield event_store.read_event_stream(id)
143
+ yield event_store.read_event_stream(id, name)
145
144
  end
146
145
 
147
146
  # Private: Creates an AggregateLoader for an ID and yields it to a given
@@ -1,8 +1,6 @@
1
1
  module EventSorcerer
2
2
  # Public: Service class for loading aggregates from the event store.
3
3
  class AggregateLoader
4
- extend Forwardable
5
-
6
4
  # Public: Creates a new AggregateLoader instance.
7
5
  #
8
6
  # klass - class for the aggregate to be loaded.
@@ -7,14 +7,14 @@ module EventSorcerer
7
7
  # Public: Value object which is returned from a successful save.
8
8
  class SaveReciept < Struct.new(:id, :klass, :events, :meta); end
9
9
 
10
- extend Forwardable
10
+ extend Uber::Delegates
11
11
 
12
12
  instance_methods.each do |m|
13
13
  undef_method(m) unless m =~ /(^__|^nil\?$|^send$|^object_id$|^tap$)/
14
14
  end
15
15
 
16
16
  # Public: Shortcuts to access the global event_store and unit_of_work.
17
- def_delegators :EventSorcerer, :event_store, :unit_of_work
17
+ delegates :EventSorcerer, :event_store, :unit_of_work
18
18
 
19
19
  # Public: Creates a new AggregateProxy instance.
20
20
  #
@@ -14,77 +14,79 @@ module EventSorcerer
14
14
  # Public: Append events to a specified aggregate. Should be defined in a
15
15
  # subclass.
16
16
  #
17
- # _aggregate_id - UUID of the aggregate as a String.
18
- # _klass - Text representation of aggregate class.
17
+ # _id - UUID of the aggregate as a String.
18
+ # _type - Text representation of aggregate class.
19
19
  # _events - Array of JSON-serialized events.
20
20
  # _expected_version - The current version of the aggregate.
21
21
  #
22
22
  # Raises a NotImplementedError
23
- def append_events(_aggregate_id, _klass, _events, _expected_version)
23
+ def append_events(_id, _type, _events, _expected_version)
24
24
  fail NotImplementedError
25
25
  end
26
26
 
27
27
  # Public: Retrieve the current version for a specified aggregate. Should
28
28
  # be defined in a subclass.
29
29
  #
30
- # _aggregate_id - UUID of the aggregate as a String.
30
+ # _id - UUID of the aggregate as a String.
31
31
  #
32
32
  # Raises a NotImplementedError
33
- def get_current_version(_aggregate_id)
33
+ def get_current_version(_id, _type)
34
34
  fail NotImplementedError
35
35
  end
36
36
 
37
37
  # Public: Retrieve the IDs for a given aggregate class. Should be defined
38
38
  # in a subclass.
39
39
  #
40
- # _klass - Text representation of aggregate class.
40
+ # _type - Text representation of aggregate class.
41
41
  #
42
42
  # Raises a NotImplementedError
43
- def get_ids_for_type(_klass)
43
+ def get_ids_for_type(_type)
44
44
  fail NotImplementedError
45
45
  end
46
46
 
47
47
  # Public: Retrieve the events for a specified aggregate. Should be defined
48
48
  # in a subclass.
49
49
  #
50
- # _aggregate_id - UUID of the aggregate as a String.
50
+ # _id - UUID of the aggregate as a String.
51
+ # _type - Text representation of aggregate class.
51
52
  #
52
53
  # Raises a NotImplementedError
53
- def read_events(_aggregate_id)
54
+ def read_events(_id, _type)
54
55
  fail NotImplementedError
55
56
  end
56
57
 
57
58
  # Public: Retrieve the event stream for a specified aggregate. Should be
58
59
  # defined in a subclass.
59
60
  #
60
- # aggregate_id - UUID of the aggregate as a String.
61
+ # id - UUID of the aggregate as a String.
62
+ # type - Text representation of aggregate class.
61
63
  #
62
64
  # Returns an EventStream
63
- def read_event_stream(aggregate_id)
64
- EventStream.new(aggregate_id, read_events(aggregate_id),
65
- get_current_version(aggregate_id))
65
+ def read_event_stream(id, type)
66
+ EventStream.new id, read_events(id, type), get_current_version(id, type)
66
67
  end
67
68
 
68
69
  # Public: Retrieve the event stream for all aggregates of a given type.
69
70
  # Optionally can be defined in subclass to optimize loading these
70
71
  # aggregates with a minimum of external calls.
71
72
  #
72
- # klass - Text representation of aggregate class.
73
+ # type - Text representation of aggregate class.
73
74
  #
74
75
  # Returns an Array.
75
- def read_event_streams_for_type(klass)
76
- read_multiple_event_streams get_ids_for_type(klass)
76
+ def read_event_streams_for_type(type)
77
+ read_multiple_event_streams get_ids_for_type(type), type
77
78
  end
78
79
 
79
80
  # Public: Retrieve the events for multiple aggregates. Optionally can be
80
81
  # defined in subclass to optimize loading multiple aggregates with
81
82
  # a minimum of external calls.
82
83
  #
83
- # aggregate_ids - Array of UUIDs of the aggregates as Strings.
84
+ # ids - Array of UUIDs of the aggregates as Strings.
85
+ # type - Text representation of aggregate class.
84
86
  #
85
87
  # Returns an Array.
86
- def read_multiple_event_streams(aggregate_ids)
87
- aggregate_ids.map { |id| read_event_stream id }
88
+ def read_multiple_event_streams(ids, type)
89
+ ids.map { |id| read_event_stream id, type }
88
90
  end
89
91
 
90
92
  # Public: Ensures events appended within the given block are done so
@@ -4,13 +4,13 @@ module EventSorcerer
4
4
  # Public: Publish events for a specified aggregate. Should be defined in a
5
5
  # subclass.
6
6
  #
7
- # _aggregate_id - UUID of the aggregate as a String.
8
- # _klass - Text representation of aggregate class.
9
- # _events - Array of Event objects.
10
- # _meta - Hash of extra data to publish on the bus.
7
+ # _id - UUID of the aggregate as a String.
8
+ # _type - Text representation of aggregate class.
9
+ # _events - Array of Event objects.
10
+ # _meta - Hash of extra data to publish on the bus.
11
11
  #
12
12
  # Raises a NotImplementedError
13
- def publish_events(_aggregate_id, _klass, _events, _meta)
13
+ def publish_events(_id, _type, _events, _meta)
14
14
  fail NotImplementedError
15
15
  end
16
16
  end
@@ -2,10 +2,10 @@ module EventSorcerer
2
2
  # Public: Handles the API of a UnitOfWork but does nothing.
3
3
  module NoUnitOfWork
4
4
  class << self
5
- extend Forwardable
5
+ extend Uber::Delegates
6
6
 
7
7
  # Public: Shortcuts to access the global message_bus.
8
- def_delegators :EventSorcerer, :message_bus
8
+ delegates :EventSorcerer, :message_bus
9
9
 
10
10
  # Public: Returns nil.
11
11
  def fetch_aggregate(_id)
@@ -2,10 +2,10 @@ module EventSorcerer
2
2
  # Public: Provides transactional integrity across multiple aggregate saves.
3
3
  # Also provides an indentity map.
4
4
  class UnitOfWork
5
- extend Forwardable
5
+ extend Uber::Delegates
6
6
 
7
7
  # Public: Shortcuts to access the global event_store and message_bus.
8
- def_delegators :EventSorcerer, :event_store, :message_bus
8
+ delegates :EventSorcerer, :event_store, :message_bus
9
9
 
10
10
  # Public: Creates a new UnitOfWork instance.
11
11
  def initialize
@@ -1,4 +1,4 @@
1
1
  # Public: Defines a constant for the current version number.
2
2
  module EventSorcerer
3
- VERSION = '0.1.1'
3
+ VERSION = '0.1.2'
4
4
  end
@@ -1,5 +1,7 @@
1
1
  require 'event_sorcerer/version'
2
2
 
3
+ require 'uber/delegates'
4
+
3
5
  require 'event_sorcerer/aggregate'
4
6
  require 'event_sorcerer/aggregate_creator'
5
7
  require 'event_sorcerer/aggregate_loader'
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: event_sorcerer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Sebastian Edwards
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-12-03 00:00:00.000000000 Z
11
+ date: 2014-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -108,6 +108,20 @@ dependencies:
108
108
  - - '='
109
109
  - !ruby/object:Gem::Version
110
110
  version: 0.7.1
111
+ - !ruby/object:Gem::Dependency
112
+ name: uber
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - "~>"
116
+ - !ruby/object:Gem::Version
117
+ version: 0.0.11
118
+ type: :runtime
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - "~>"
123
+ - !ruby/object:Gem::Version
124
+ version: 0.0.11
111
125
  description: '["Generic", "event-sourcing", "scaffold"]'
112
126
  email:
113
127
  - me@sebastianedwards.co.nz