Created
September 27, 2011 04:02
-
-
Save garybernhardt/1244313 to your computer and use it in GitHub Desktop.
Before/after let comparison
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 Delegator | |
takes :request, :route_path, :resource, :delegate_name | |
let(:delegate_method) { @resource.record_class.method(method_name) } | |
let(:method_name) { @delegate_name.split('.').last.to_sym } | |
def delegate | |
delegate_method.call(*delegate_args) | |
end | |
def delegate_args | |
inference_sources = InferenceSources.new(@request, | |
@route_path, | |
@request.path_info).sources | |
InfersArgs.new(delegate_method, inference_sources).args | |
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 Delegator | |
def initialize(request, route_path, resource, delegate_name) | |
@request = request | |
@route_path = route_path | |
@resource = resource | |
@delegate_name = delegate_name | |
end | |
def delegate | |
delegate_method.call(*delegate_args) | |
end | |
def delegate_args | |
inference_sources = InferenceSources.new(@request, | |
@route_path, | |
@request.path_info).sources | |
InfersArgs.new(delegate_method, inference_sources).args | |
end | |
def delegate_method | |
@resource.record_class.method(method_name) | |
end | |
def method_name | |
@delegate_name.split('.').last.to_sym | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment