Class: TudlaContracts::Integrations::ViewDefinitions::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/tudla_contracts/integrations/view_definitions/base.rb

Overview

Base class for all view definitions Subclasses must implement the #visible? method

Instance Attribute Summary collapse

Instance Method Summary collapse

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

Returns:

  • (Boolean)


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