-
-
Save banister/2c40d5a24c00fb298381 to your computer and use it in GitHub Desktop.
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 ServiceObject | |
NULL_LAMBDA = ->(*) { } | |
def self.callbacks(*args) | |
args.each do |v| | |
attr_writer *args.map { |v| "#{v}_callback"} | |
define_method("#{v}_callback") do | |
instance_variable_get("@#{v}_callback") || NULL_LAMBDA | |
end | |
define_method(v) do |&callback| | |
send("#{v}_callback=", callback) | |
end | |
end | |
end | |
def self.call(*args, &block) | |
new(*args).tap do |service| | |
yield(service) if block_given? | |
service.process if service.respond_to?(:process) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment