Class: Compony::ExposedIntentsDsl

Inherits:
Dslblend::Base
  • Object
show all
Defined in:
lib/compony/exposed_intents_dsl.rb

Instance Method Summary collapse

Constructor Details

#initialize(previously_exposed_intents) ⇒ ExposedIntentsDsl

Returns a new instance of ExposedIntentsDsl.



3
4
5
6
# File 'lib/compony/exposed_intents_dsl.rb', line 3

def initialize(previously_exposed_intents)
  super()
  @exposed_intents = previously_exposed_intents
end

Instance Method Details

#add(before: nil) ⇒ Object (protected)

DSL method Adds or replaces an intent to those exposed by the component based on the intent name (override the name if you need to avoid a naming collision). Intents specified this way can be retrieved and rendered by the parent component or by calling root_intents in case of standalone access.

Parameters:

  • before (Symbol) (defaults to: nil)

    If specified, will insert the intent before the other. When replacing, an element keeps its position unless before:` is passed.



14
15
16
17
# File 'lib/compony/exposed_intents_dsl.rb', line 14

def add(*, before: nil, **)
  intent = Compony.intent(*, **)
  @exposed_intents.natural_push(intent.name, intent, before:)
end

#remove(intent_name) ⇒ Object (protected)

DSL method Removes an exposed intent previously added to this component

Parameters:

  • intent_name (Symbol)

    The name of the intent to remove



22
23
24
25
26
27
# File 'lib/compony/exposed_intents_dsl.rb', line 22

def remove(intent_name)
  existing_index = @exposed_intents.find_index { |el| el.name == intent_name.to_sym }
  if existing_index
    @exposed_intents.delete_at(existing_index)
  end
end