class CreateEvent
Input = Request.build(:creator_name, :event_date, :event_name)
Success = Response.build(:event_code)
Failure = Response.build(:error)
def initialize(input)
@creator_name = input.creator_name
@event_date = input.event_date
@event_name = input.event_name
end
def call
if event_valid?
save_event
Success.new(:event_code => event_code)
else
Failure.new(:errors => errors)
end
end
private
def event_valid?
event_validator.valid?
end
def event_validator
@event_validator ||= EventValidator.new(@event)
end
def event
@event ||= event_gateway.build(
:name => @event_name,
:date => @event_date,
:creator => creator
)
end
def event_gateway
@event_gateway ||= EventGateway.new
end
def creator
@creator ||= user_gateway.detect_by_name(@creator_name)
end
def user_gateway
@user_gateway ||= UserGateway.new
end
def save_event
@event = event_gate.save_and_reload @event
end
def event_code
@event.code
end
def errors
event_validator.errors
end
class EventValidator < Validator
# ...
end
end
I never really thought about another partitioning, like yours. Would you mind to mention a few use-cases of the EMR application and which gateways and gateway-methods they are specifically using? I am sure, this would kindly help me understanding your approach correctly.
Thanks for your time!
class ProductGateway def add_product(product) //add method end
def find_by(specifications) products.select{|p| satisfied_by_specs(specifications, p)} end
def satisfied_by_specs(specifications, product) specifications.all? do |spec| spec.is_satisified_by?(product) end end
end
class MaterialSpecification def initialize(material) @material = material end
def is_satisified_by?(product) product.built_with?(@material) endend
class ProductIdentifierSpecification
def intitialize(productId)
@productId = productId
end
def is_satisified_by?(product) product.productId == @productId endend