-
-
Save adkron/23adbc946942b84401af to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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 callback API suggested by @adkron but return the response object instead of a block | |
class OrderController < ApplicationController | |
def index | |
on = interactor.list | |
on.display { |orders| render orders } | |
end | |
def show | |
on = interactor.get(params[:id]) | |
on.display { |order| render order } | |
on.not_found { |order_id| render status: 404 } | |
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