lib/bmg/support/tuple_transformer.rb in bmg-0.23.1 vs lib/bmg/support/tuple_transformer.rb in bmg-0.23.2
- old
+ new
@@ -1,8 +1,10 @@
module Bmg
class TupleTransformer
+ Callable = ->(t) { t.respond_to?(:call) }
+
def initialize(transformation)
@transformation = transformation
end
def self.new(arg)
@@ -24,11 +26,11 @@
private
def transform_tuple(tuple, with)
case with
- when Symbol, Proc, Regexp
+ when Symbol, Proc, Regexp, Callable
tuple.each_with_object({}){|(k,v),dup|
dup[k] = transform_attr(v, with)
}
when Hash
with.each_with_object(tuple.dup){|(k,v),dup|
@@ -70,16 +72,16 @@
elsif with == String
value.to_s
else
raise ArgumentError, "#{with} should respond to `parse`"
end
- when Proc
+ when Proc, Callable
with.call(value)
when Hash
with[value]
else
raise ArgumentError, "Unexpected transformation `#{with.inspect}`"
end
end
end # module TupleTransformer
-end # module Bmg
\ No newline at end of file
+end # module Bmg