Class: Avo::Resources::Items::TabGroup::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/avo/resources/items/tab_group.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(style: nil) ⇒ Builder

Returns a new instance of Builder.



37
38
39
40
# File 'lib/avo/resources/items/tab_group.rb', line 37

def initialize(style: nil)
  @group = Avo::Resources::Items::TabGroup.new(style: style)
  @items_holder = Avo::Resources::Items::Holder.new
end

Instance Attribute Details

#items_holderObject (readonly)

Returns the value of attribute items_holder.



33
34
35
# File 'lib/avo/resources/items/tab_group.rb', line 33

def items_holder
  @items_holder
end

Class Method Details

.parse_block(**args, &block) ⇒ Object



28
29
30
# File 'lib/avo/resources/items/tab_group.rb', line 28

def parse_block(**args, &block)
  Docile.dsl_eval(new(**args), &block).build
end

Instance Method Details

#buildObject

Fetch the tab



63
64
65
66
# File 'lib/avo/resources/items/tab_group.rb', line 63

def build
  @group.items_holder = @items_holder
  @group
end

#field(field_name, **args, &block) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
# File 'lib/avo/resources/items/tab_group.rb', line 42

def field(field_name, **args, &block)
  parsed = Avo::Dsl::FieldParser.new(id: field_name, order_index: @items_index, **args, &block).parse
  field_instance = parsed.instance

  name = field_instance.name
  tab = Avo::Resources::Items::Tab.new name: name

  if field_instance.has_own_panel?
    tab.items_holder.add_item parsed.instance
  else
    # If the field is not in a panel, create one and add it
    panel = Avo::Resources::Items::Panel.new name: name
    panel.items_holder.add_item parsed.instance
    # Add that panel to the items_holder
    tab.items_holder.add_item panel
  end

  @items_holder.tabs tab
end