Skip to content

Commit

Permalink
States as methods
Browse files Browse the repository at this point in the history
Accepted didn't get it's own method as it doesn't seem like this
"accepted" information is used in any way
  • Loading branch information
lukaszreszke committed Aug 6, 2024
1 parent 3077db0 commit d844c35
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions ecommerce/ordering/lib/ordering/order.rb
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ class Order

def initialize(id)
@id = id
@state = State.new
@state = State.draft
@basket = Basket.new
end

Expand Down Expand Up @@ -70,7 +70,7 @@ def remove_item(product_id)
end

on OrderExpired do |event|
@state = State.new(:expired)
@state = State.expired
end

on ItemAddedToBasket do |event|
Expand All @@ -83,11 +83,11 @@ def remove_item(product_id)

on OrderSubmitted do |event|
@order_number = event.data[:order_number]
@state = State.new(:submitted)
@state = State.submitted
end

on OrderRejected do |event|
@state = State.new
@state = State.draft
end

class Basket
Expand All @@ -114,7 +114,19 @@ def quantity(product_id)
end

class State
def initialize(state = :draft)
def self.draft
new(:draft)
end

def self.submitted
new(:submitted)
end

def self.expired
new(:expired)
end

def initialize(state)
@state = state
end

Expand Down

0 comments on commit d844c35

Please sign in to comment.