Class: RubyEventStore::Facade

Inherits:
Object
  • Object
show all
Defined in:
lib/ruby_event_store/facade.rb

Defined Under Namespace

Classes: Page

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(repository) ⇒ Facade

Returns a new instance of Facade.



3
4
5
# File 'lib/ruby_event_store/facade.rb', line 3

def initialize(repository)
  @repository = repository
end

Instance Attribute Details

#repositoryObject (readonly)

Returns the value of attribute repository.



6
7
8
# File 'lib/ruby_event_store/facade.rb', line 6

def repository
  @repository
end

Instance Method Details

#append_to_stream(stream_name, event_data, expected_version = nil) ⇒ Object



13
14
15
16
# File 'lib/ruby_event_store/facade.rb', line 13

def append_to_stream(stream_name, event_data, expected_version = nil)
  raise WrongExpectedEventVersion if version_incorrect?(stream_name, expected_version)
  repository.create(event_data, stream_name)
end

#delete_stream(stream_name) ⇒ Object



18
19
20
21
# File 'lib/ruby_event_store/facade.rb', line 18

def delete_stream(stream_name)
  raise IncorrectStreamData if stream_name.nil? || stream_name.empty?
  repository.delete_stream(stream_name)
end

#publish_event(event_data, stream_name = GLOBAL_STREAM, expected_version = nil) ⇒ Object



8
9
10
11
# File 'lib/ruby_event_store/facade.rb', line 8

def publish_event(event_data, stream_name = GLOBAL_STREAM, expected_version = nil)
  event = append_to_stream(stream_name, event_data, expected_version)
  event_broker.notify_subscribers(event)
end

#read_all_streams_backward(start, count) ⇒ Object



50
51
52
53
# File 'lib/ruby_event_store/facade.rb', line 50

def read_all_streams_backward(start, count)
  page = Page.new(repository, start, count)
  repository.read_all_streams_backward(page.start, page.count)
end

#read_all_streams_forward(start, count) ⇒ Object



45
46
47
48
# File 'lib/ruby_event_store/facade.rb', line 45

def read_all_streams_forward(start, count)
  page = Page.new(repository, start, count)
  repository.read_all_streams_forward(page.start, page.count)
end

#read_events_backward(stream_name, start, count) ⇒ Object



29
30
31
32
33
# File 'lib/ruby_event_store/facade.rb', line 29

def read_events_backward(stream_name, start, count)
  raise IncorrectStreamData if stream_name.nil? || stream_name.empty?
  page = Page.new(repository, start, count)
  repository.read_events_backward(stream_name, page.start, page.count)
end

#read_events_forward(stream_name, start, count) ⇒ Object



23
24
25
26
27
# File 'lib/ruby_event_store/facade.rb', line 23

def read_events_forward(stream_name, start, count)
  raise IncorrectStreamData if stream_name.nil? || stream_name.empty?
  page = Page.new(repository, start, count)
  repository.read_events_forward(stream_name, page.start, page.count)
end

#read_stream_events_backward(stream_name) ⇒ Object



40
41
42
43
# File 'lib/ruby_event_store/facade.rb', line 40

def read_stream_events_backward(stream_name)
  raise IncorrectStreamData if stream_name.nil? || stream_name.empty?
  repository.read_stream_events_backward(stream_name)
end

#read_stream_events_forward(stream_name) ⇒ Object



35
36
37
38
# File 'lib/ruby_event_store/facade.rb', line 35

def read_stream_events_forward(stream_name)
  raise IncorrectStreamData if stream_name.nil? || stream_name.empty?
  repository.read_stream_events_forward(stream_name)
end

#subscribe(subscriber, event_types) ⇒ Object



55
56
57
# File 'lib/ruby_event_store/facade.rb', line 55

def subscribe(subscriber, event_types)
  event_broker.add_subscriber(subscriber, event_types)
end

#subscribe_to_all_events(subscriber) ⇒ Object



59
60
61
# File 'lib/ruby_event_store/facade.rb', line 59

def subscribe_to_all_events(subscriber)
  event_broker.add_global_subscriber(subscriber)
end