Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Callback ideas for hexagonal Rails controllers
# From http://blog.boochtek.com/2015/02/23/hexagonal-rails-controllers
class OrderController < ApplicationController
def index
interactor.on(:display) { |orders| render orders }
interactor.list
end
def show
interactor.on(:display) { |order| render order }
interactor.on(:not_found) { |order_id| render status: 404 }
interactor.get(params[:id])
end
end
# Same thing, with callback API suggested by @adkron.
class OrderController < ApplicationController
def index
interactor.list do |on|
on.display { |orders| render orders }
end
end
def show
interactor.get(params[:id]) do |on|
on.display { |order| render order }
on.not_found { |order_id| render status: 404 }
end
end
end
# Same thing, with callbacks using stabby lambdas as arguments.
class OrderController < ApplicationController
def index
interactor.list(
display: ->(orders){ render orders }
)
end
def show
interactor.get(params[:id],
display: ->(order) { render order },
not_found: ->(order_id) { render status: 404 }
)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.