Created
July 1, 2010 18:45
-
-
Save csamuel/460377 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
def using(*args, &block) | |
case args.first | |
when Hash # Maven hash mapping | |
using :maven, *args | |
when Binding # Erb binding | |
using :erb, *args | |
when Symbol # Mapping from a method | |
raise ArgumentError, "Unknown mapping type: #{args.first}" unless respond_to?("#{args.first}_transform", true) | |
configure(*args, &block) | |
when Regexp # Mapping using a regular expression | |
raise ArgumentError, 'Expected regular expression followed by mapping hash' unless args.size == 2 && Hash === args[1] | |
@mapper_type, @config = *args | |
else | |
unless args.empty? && block.nil? | |
raise ArgumentError, 'Expected proc, method or a block' if args.size > 1 || (args.first && block) | |
@mapper_type = :callback | |
config = args.first || block | |
raise ArgumentError, 'Expected proc, method or callable' unless config.respond_to?(:call) | |
@config = config | |
end | |
end | |
self | |
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment