lib/phlex/helpers.rb

Lines

96%

24 of 25 covered

Branches

94%

17 of 18 covered

Methods

100%

2 of 2 covered

Not run
32
1# frozen_string_literal: true
2
3# @api private
41module Phlex::Helpers
51 private def mix(*args)
635 args.each_with_object({}) do |object, result|
772 result.merge!(object) do |_key, old, new|
832 case [old, new].freeze
9 in [Array, Array] | [Set, Set]
103 old + new
11 in [Array, Set]
121 old + new.to_a
13 in [Array, String | Symbol]
142 old + [new]
15 in [Hash, Hash]
162 mix(old, new)
17 in [Set, Array]
181 old.to_a + new
19 in [Set, String | Symbol]
202 old.to_a + [new]
21 in [String | Symbol, Array]
222 [old] + new
23 in [String | Symbol, Set]
242 [old] + new.to_a
25 in [String, String]
265 "#{old} #{new}"
27 in [String | Symbol, String | Symbol]
285 [old, new]
29 in [_, Hash]
302 { _: old, **new }
31 in [Hash, _]
320 { **old, _: new }in never taken
33 in [_, nil]
343 old
35 else
362 new
37 end
38 end
39
4072 result.transform_keys! do |key|
4178 (Symbol === key && key.end_with?("!")) ? key.name.chop.to_sym : key
42 end
43 end
44 end
45
461 private def grab(**bindings)
472 if bindings.size > 1
481 bindings.values
49 else
501 bindings.values.first
51 end
52 end
53end