diff --git a/lib/plumb/composable.rb b/lib/plumb/composable.rb index d45cdac..ba8f0f2 100644 --- a/lib/plumb/composable.rb +++ b/lib/plumb/composable.rb @@ -100,6 +100,7 @@ def self.included(base) # Wrap an object in a Composable instance. # Anything that includes Composable is a noop. # A Hash is assumed to be a HashClass schema. + # An Array with zero or 1 element is assumed to be an ArrayClass. # Any `#call(Result) => Result` interface is wrapped in a Step. # Anything else is assumed to be something you want to match against via `#===`. # @@ -115,6 +116,16 @@ def self.wrap(callable) callable elsif callable.is_a?(::Hash) HashClass.new(schema: callable) + elsif callable.is_a?(::Array) + element_type = case callable.size + when 0 + Types::Any + when 1 + callable.first + else + raise ArgumentError, '[element_type] syntax allows a single element type' + end + Types::Array[element_type] elsif callable.respond_to?(:call) Step.new(callable) else diff --git a/lib/plumb/hash_class.rb b/lib/plumb/hash_class.rb index c676e6f..5103158 100644 --- a/lib/plumb/hash_class.rb +++ b/lib/plumb/hash_class.rb @@ -140,28 +140,7 @@ def _inspect def wrap_keys_and_values(hash) hash.each.with_object({}) do |(k, v), ret| - ret[Key.wrap(k)] = wrap_value(v) - end - end - - def wrap_value(value) - case value - when ::Array - element_type = case value.size - when 0 - Types::Any - when 1 - value.first - else - raise ArgumentError, '[element_type] syntax allows a single element type' - end - Types::Array[element_type] - when ::Hash - schema wrap_keys_and_values(value) - when Callable - value - else #  leaf values - Composable.wrap(value) + ret[Key.wrap(k)] = Composable.wrap(v) end end