Making Smart Technology Choices in an Era of Complexity
Alessandro Desantis
alessandro.codes
@aldesantis
Software developer
Engineering manager
Chief technical officer
Technical advisor
Co-founder
Growth advisor
A complex system that works is invariably found to have evolved from a simple system that worked.
- John Gall
class Rules::CustomerName
def initialize(first_name:, last_name:)
@first_name = first_name
@last_name = last_name
end
def call(order)
order.customer.first_name == @fist_name &&
order.customer.last_name == @last_name
end
end
class Rules::CustomerEmail
def initialize(email:)
@email = email
end
def call(order)
order.customer.email == @email
end
end
class Order < ApplicationRecord
RISK_RULES = [
Rules::CustomerName.new(first_name: 'John', last_name: 'Doe'),
Rules::CustomerEmail.new(email: 'jdoe@acme.com'),
]
before_save :analyze_risk
def analyze_risk
self.risky = RISK_RULES.any? { |rule| rule.call(self) }
end
end