Class: Compony::ManageIntentsDsl
- Inherits:
-
Dslblend::Base
- Object
- Dslblend::Base
- Compony::ManageIntentsDsl
- Defined in:
- lib/compony/manage_intents_dsl.rb
Instance Method Summary collapse
-
#add(*args, before: nil, **kwargs) ⇒ 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).
-
#initialize(previously_exposed_intents, **intent_opts) ⇒ ManageIntentsDsl
constructor
A new instance of ManageIntentsDsl.
-
#remove(intent_name) ⇒ Object
protected
DSL method Removes an exposed intent previously added to this component.
Constructor Details
#initialize(previously_exposed_intents, **intent_opts) ⇒ ManageIntentsDsl
Returns a new instance of ManageIntentsDsl.
3 4 5 6 7 |
# File 'lib/compony/manage_intents_dsl.rb', line 3 def initialize(previously_exposed_intents, **intent_opts) super() @exposed_intents = previously_exposed_intents @intent_opts = intent_opts end |
Instance Method Details
#add(*args, before: nil, **kwargs) ⇒ 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.
15 16 17 18 19 20 21 22 |
# File 'lib/compony/manage_intents_dsl.rb', line 15 def add(*args, before: nil, **kwargs) intent = Compony.intent(*args, **@intent_opts, **kwargs) @exposed_intents.natural_push(intent.name, intent, before:) rescue NameError => e # Ignore if the component is not actually defined Rails.logger.debug do "Skipping intent for arguments #{args.inspect}, #{kwargs.inspect}: #{e.inspect}." end end |
#remove(intent_name) ⇒ Object (protected)
DSL method Removes an exposed intent previously added to this component
27 28 29 30 31 32 |
# File 'lib/compony/manage_intents_dsl.rb', line 27 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 |