-
-
Save colindensem/e1dcd091a7d8e48004201b98d19a7d34 to your computer and use it in GitHub Desktop.
Controllers decoupling rails
This file contains 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
> sp = ServicePoro.call( | |
arg1: 'fu', | |
on_sucess: -> (text) { puts "#{text}bar" } | |
> fubar |
This file contains 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
class FooController | |
def index | |
ServicePoro.call( | |
arg1: 'foo', | |
on_success: -> (data) { render_json(data, root: "meta") } | |
) | |
end | |
end |
This file contains 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
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