Class: TudlaContracts::Integrations::ViewDefinitions::Base
- Inherits:
-
Object
- Object
- TudlaContracts::Integrations::ViewDefinitions::Base
- Defined in:
- lib/tudla_contracts/integrations/view_definitions/base.rb
Overview
Base class for all view definitions Subclasses must implement the #visible? method
Direct Known Subclasses
Instance Attribute Summary collapse
-
#component_class ⇒ Object
readonly
Returns the value of attribute component_class.
-
#condition ⇒ Object
readonly
Returns the value of attribute condition.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#label ⇒ Object
readonly
Returns the value of attribute label.
-
#priority ⇒ Object
readonly
Returns the value of attribute priority.
Instance Method Summary collapse
-
#initialize(id:, label:, component_class:, priority: 10, if: nil) ⇒ Base
constructor
A new instance of Base.
-
#visible?(context, *args) ⇒ Boolean
Helper to check visibility within a specific context.
Constructor Details
#initialize(id:, label:, component_class:, priority: 10, if: nil) ⇒ Base
Returns a new instance of Base.
11 12 13 14 15 16 17 18 |
# File 'lib/tudla_contracts/integrations/view_definitions/base.rb', line 11 def initialize(id:, label:, component_class:, priority: 10, if: nil) @id = id @label = label @component_class = component_class @priority = priority # Capture the conditional logic (lambda/proc) @condition = binding.local_variable_get(:if) end |
Instance Attribute Details
#component_class ⇒ Object (readonly)
Returns the value of attribute component_class.
9 10 11 |
# File 'lib/tudla_contracts/integrations/view_definitions/base.rb', line 9 def component_class @component_class end |
#condition ⇒ Object (readonly)
Returns the value of attribute condition.
9 10 11 |
# File 'lib/tudla_contracts/integrations/view_definitions/base.rb', line 9 def condition @condition end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
9 10 11 |
# File 'lib/tudla_contracts/integrations/view_definitions/base.rb', line 9 def id @id end |
#label ⇒ Object (readonly)
Returns the value of attribute label.
9 10 11 |
# File 'lib/tudla_contracts/integrations/view_definitions/base.rb', line 9 def label @label end |
#priority ⇒ Object (readonly)
Returns the value of attribute priority.
9 10 11 |
# File 'lib/tudla_contracts/integrations/view_definitions/base.rb', line 9 def priority @priority end |
Instance Method Details
#visible?(context, *args) ⇒ Boolean
Helper to check visibility within a specific context
21 22 23 24 25 26 |
# File 'lib/tudla_contracts/integrations/view_definitions/base.rb', line 21 def visible?(context, *args) return true if @condition.nil? # Execute the condition in the context of the view (context) context.instance_exec(*args, &@condition) end |