Class: Remap::Rule::Wrap

Inherits:
Concrete
  • Object
show all
Defined in:
lib/remap/rule/wrap.rb

Overview

Wraps rule in a type

Examples:

Maps { name: “Ford” } to { cars: [“Ford”] }

class Mapper < Remap::Base
  define do
    to :cars do
      wrap(:array) do
        map :name
      end
    end
  end
end

Mapper.call({ name: "Ford" }) # => { cars: ["Ford"] }

Instance Method Summary collapse

Instance Method Details

#callObject

Wraps the output from #rule in a #type

See Also:



31
32
33
34
35
# File 'lib/remap/rule/wrap.rb', line 31

def call(...)
  rule.call(...).fmap do |value|
    Array.wrap(value)
  end
end

#ruleRule

Returns:



26
# File 'lib/remap/rule/wrap.rb', line 26

attribute :rule, Types::Rule

#type:array

Returns:

  • (:array)


23
# File 'lib/remap/rule/wrap.rb', line 23

attribute :type, Value(:array)