Class: Protos::Mix

Inherits:
Object
  • Object
show all
Defined in:
lib/protos/mix.rb

Constant Summary collapse

MERGEABLE_ATTRIBUTES =

DOCS: This class is responsible for safely merging in both user supplied and default attributes. When a user adds { data: { controller: “foo” }} to their component. This will merge the value in so that any default controllers do not get overridden.

Set.new(%i[class data]).freeze

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.callObject



12
# File 'lib/protos/mix.rb', line 12

def self.call(...) = new.call(...)

Instance Method Details

#call(old_hash, *hashes) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/protos/mix.rb', line 14

def call(old_hash, *hashes)
  hashes
    .compact
    .each_with_object(old_hash) do |new_hash, result|
      merge(result, new_hash, top_level: true)
    end
end