Class: Plutonium::Definition::DisplayLayout::Builder

Inherits:
Object
  • Object
show all
Defined in:
lib/plutonium/definition/display_layout.rb

Overview

Collects section/ungrouped calls from a display_layout block, in order. Builds the same Section struct FormLayout uses — the two layouts share a resolver, so they share a value type.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeBuilder

Returns a new instance of Builder.



39
40
41
42
# File 'lib/plutonium/definition/display_layout.rb', line 39

def initialize
  @sections = []
  @ungrouped_seen = false
end

Instance Attribute Details

#sectionsObject (readonly)

Returns the value of attribute sections.



37
38
39
# File 'lib/plutonium/definition/display_layout.rb', line 37

def sections
  @sections
end

Instance Method Details

#section(key, *fields, **options) ⇒ Object



44
45
46
47
48
49
50
51
# File 'lib/plutonium/definition/display_layout.rb', line 44

def section(key, *fields, **options)
  if key == FormLayout::UNGROUPED_KEY
    raise ArgumentError,
      "`section :#{FormLayout::UNGROUPED_KEY}` is reserved — use the `ungrouped` macro"
  end
  reject_columns!(options)
  @sections << FormLayout::Section.new(key:, fields: fields.freeze, options: options.freeze)
end

#ungrouped(**options) ⇒ Object

Raises:

  • (ArgumentError)


53
54
55
56
57
58
59
60
# File 'lib/plutonium/definition/display_layout.rb', line 53

def ungrouped(**options)
  raise ArgumentError, "`ungrouped` may only be declared once" if @ungrouped_seen
  @ungrouped_seen = true
  reject_columns!(options)
  @sections << FormLayout::Section.new(
    key: FormLayout::UNGROUPED_KEY, fields: [].freeze, options: options.freeze
  )
end