Method: Coco::PresentedComponent.new

Defined in:
app/components/coco/presented_component.rb

.new(subject = :none, **kwargs) ⇒ Object

Allow initializing PresentedComponent instances by optionally passing the subject as the first argument. Ensures presented components can still be rendered using ViewComponent’s ‘.with_collection` method.

Example.new(example_model, **opts)

[View source]

18
19
20
21
22
23
24
25
26
27
28
# File 'app/components/coco/presented_component.rb', line 18

def new(subject = :none, **kwargs)
  if subject == :none
    subject = kwargs.fetch(collection_parameter.to_sym) do
      raise ArgumentError, "Presented components require a subject to be provided when initializing"
    end
  end

  instance = kwargs.any? ? super : super(subject)
  instance.subject = subject
  instance
end