Skip to content

Commit

Permalink
Extract repository
Browse files Browse the repository at this point in the history
  • Loading branch information
mostlyobvious committed Nov 26, 2023
1 parent 70a6b34 commit 401afde
Show file tree
Hide file tree
Showing 4 changed files with 25 additions and 23 deletions.
1 change: 1 addition & 0 deletions examples/document_way/lib/project_management.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@
require_relative "../../../shared/lib/project_management"
require_relative "project_management/handler"
require_relative "project_management/issue"
require_relative "project_management/repository"
2 changes: 1 addition & 1 deletion examples/document_way/lib/project_management/handler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ def stop(id) = with_aggregate(id) { |issue| issue.stop }
def stream_name(id) = "Issue$#{id}"

def with_aggregate(id)
repository = Issue::Repository.new(id)
repository = Repository.new(id)
issue = Issue.new(repository.load)

@event_store.append(yield(issue), stream_name: stream_name(id))
Expand Down
22 changes: 0 additions & 22 deletions examples/document_way/lib/project_management/issue.rb
Original file line number Diff line number Diff line change
@@ -1,27 +1,5 @@
module ProjectManagement
class Issue
State = Struct.new(:id, :status)

class Repository
class Record < ActiveRecord::Base
self.table_name = :issues
end
private_constant :Record

def initialize(id)
@id = id
end

def store(state)
Record.where(uuid: @id).update_all(status: state.status)
end

def load
record = Record.find_or_create_by(uuid: @id)
State.new(record.uuid, record.status)
end
end

InvalidTransition = Class.new(StandardError)

attr_reader :state
Expand Down
23 changes: 23 additions & 0 deletions examples/document_way/lib/project_management/repository.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
module ProjectManagement
class Repository
class Record < ActiveRecord::Base
self.table_name = :issues
end
private_constant :Record

State = Struct.new(:id, :status)

def initialize(id)
@id = id
end

def store(state)
Record.where(uuid: @id).update_all(status: state.status)
end

def load
record = Record.find_or_create_by(uuid: @id)
State.new(record.uuid, record.status)
end
end
end

0 comments on commit 401afde

Please sign in to comment.