Skip to content

Instantly share code, notes, and snippets.

@csamuel
Created July 1, 2010 18:45
Show Gist options
  • Save csamuel/460377 to your computer and use it in GitHub Desktop.
Save csamuel/460377 to your computer and use it in GitHub Desktop.
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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment