The document discusses attribution events in software design. An attribution event identifies a user and has a timestamp. Sheets can have different types of attribution events, like submitted and reviewed events. A module defines methods to capture attribution events, which assigns an AttributionEvent object to the appropriate attribute on the model. This provides a cleaner way to track who performed different actions on a sheet and when.
32. #
# Represents the information required to attribute
# an event to a user.
#
class AttributionEvent
attr_reader :name, :email, :user_id, :event_at
def initialize(name, email, user_id, at)
@name = name
@email = email
@user_id = user_id
@event_at = at
end
end
An attribution event
identifies a user and
has a timestamp
36. #
# Represents the information required to attribute
# an event to a user.
#
class AttributionEvent
attr_reader :name, :email, :user_id, :event_at
def initialize(name, email, user_id, at)
@name = name
@email = email
@user_id = user_id
@event_at = at
end
end
An attribution event
identifies a user and
has a timestamp
37. #
# Represents the information required to attribute
# an event to a user.
#
class AttributionEvent
attr_reader :name, :email, :user_id, :event_at
def self.build(user, at: Time.zone.now)
new(user.name, user.email, user.id, at)
end
def initialize(name, email, user_id, at)
@name = name
@email = email
@user_id = user_id
@event_at = at
end
end
An attribution event
identifies a user and
has a timestamp
44. #
# Represents the information required to attribute
# an event to a user.
#
class AttributionEvent
attr_reader :name, :email, :user_id, :event_at
def self.build(user, at: Time.zone.now)
new(user.name, user.email, user.id, at)
end
def initialize(name, email, user_id, at)
@name = name
@email = email
@user_id = user_id
@event_at = at
end
end
66. module Models
module AttributionEvents
extend ActiveSupport::Concern
included do
def capture_attribution_event(type:, user:,
at: Time.zone.now)
send("#{type}_attribution_event=",
AttributionEvent.build(user, at: at))
end
end
module ClassMethods
...
end
end
end
67. module Models
module AttributionEvents
extend ActiveSupport::Concern
included do
def capture_attribution_event(type:, user:,
at: Time.zone.now)
send("#{type}_attribution_event=",
AttributionEvent.build(user, at: at))
end
end
module ClassMethods
...
end
end
end
68. module Models
module AttributionEvents
extend ActiveSupport::Concern
included do
def capture_attribution_event(type:, user:,
at: Time.zone.now)
send("#{type}_attribution_event=",
AttributionEvent.build(user, at: at))
end
end
module ClassMethods
...
end
end
end
73. class Sheet < ActiveRecord::Base
include Models::AttributionEvents
attribution_event :reviewed
attribution_event :submitted
sheet.capture_attribution_event(
type: :submitted, user: inspector
)
An attribution event
identifies a user and
has a timestamp
And we capture different
types of attribution events
74. class Sheet < ActiveRecord::Base
include Models::AttributionEvents
attribution_event :reviewed
attribution_event :submitted
sheet.capture_attribution_event(
type: :submitted, user: inspector
)
78. Ubiquitous
Language
The language used by everyone on the team
to describe the domain model when speaking,
writing user stories, and in the source code.
79. • Passes the tests
• Reveals intention
Simple
Design
• No duplication
• Fewest elements
85. #
# Represents the information required to attribute
# an event to a user.
#
class AttributionEvent
attr_reader :name, :email, :user_id, :event_at
def initialize(name, email, user_id, at)
@name = name
@email = email
@user_id = user_id
@event_at = at
end
end
sheet.submitted_attribution_event =
AttributionEvent.new(
inspector.name, inspector.email,
inspector.id, Time.zone.now
)
86. #
# Represents the information required to attribute
# an event to a user.
#
class AttributionEvent
attr_reader :name, :email, :user_id, :event_at
def self.build(user, at: Time.zone.now)
new(user.name, user.email, user.id, at)
end
def initialize(name, email, user_id, at)
@name = name
@email = email
@user_id = user_id
@event_at = at
end
end
An attribution event
identifies a user and
has a timestamp