Skip to content

Instantly share code, notes, and snippets.

@colindensem
Created June 3, 2021 16:32
Show Gist options
  • Save colindensem/e1dcd091a7d8e48004201b98d19a7d34 to your computer and use it in GitHub Desktop.
Save colindensem/e1dcd091a7d8e48004201b98d19a7d34 to your computer and use it in GitHub Desktop.
Controllers decoupling rails
> sp = ServicePoro.call(
arg1: 'fu',
on_sucess: -> (text) { puts "#{text}bar" }
> fubar
class FooController
def index
ServicePoro.call(
arg1: 'foo',
on_success: -> (data) { render_json(data, root: "meta") }
)
end
end
class ServicePoro
include Callable
attr_reader :on_success
def initialize(arg1:, on_sucess:)
@arg1 = arg1
@on_success = on_success
end
def call
# setup
# execute
on_success.call
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment