Class: CafeCar::Table::Builder

Inherits:
Object
  • Object
show all
Includes:
OptionHelpers, ProcHelpers
Defined in:
lib/cafe_car/table/builder.rb

Direct Known Subclasses

ObjectsBuilder, RowBuilder, CafeCar::TableBuilder

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OptionHelpers

#assign_option!, #assign_options!, #get_options

Methods included from ProcHelpers

#call_procs!, #clone_or_call!

Constructor Details

#initialize(template, **options, &block) ⇒ Builder

Returns a new instance of Builder.



9
10
11
12
13
14
15
16
# File 'lib/cafe_car/table/builder.rb', line 9

def initialize(template, **options, &block)
  @template         = template
  @options          = options
  @block            = block
  @ui               = @template.ui.Table
  @shown_attributes = {}
  assign_options!
end

Instance Attribute Details

#uiObject (readonly)

Returns the value of attribute ui.



6
7
8
# File 'lib/cafe_car/table/builder.rb', line 6

def ui
  @ui
end

Instance Method Details

#cell(method) ⇒ Object



20
# File 'lib/cafe_car/table/builder.rb', line 20

def cell(method, ...) = shown!(method).then { nil }

#has?(method) ⇒ Boolean

Returns:

  • (Boolean)


24
# File 'lib/cafe_car/table/builder.rb', line 24

def has?(method) = model.info.fields.has?(method)

#html_safe?Boolean

Returns:

  • (Boolean)


48
# File 'lib/cafe_car/table/builder.rb', line 48

def html_safe? = true

#logo(method = policy.logo_attribute) ⇒ Object



30
31
32
# File 'lib/cafe_car/table/builder.rb', line 30

def (method = policy.logo_attribute, *, **, &)
  cell(method, *, label: nil, blank: "", **, &) if method
end

#model_nameObject



18
# File 'lib/cafe_car/table/builder.rb', line 18

def model_name = model.model_name

#remaining(except: []) ⇒ Object



40
41
42
43
44
45
46
# File 'lib/cafe_car/table/builder.rb', line 40

def remaining(except: [])
  capture do
    (remaining_attributes - [ *except ]).each do |attr|
      ui << cell(policy.info(attr).displayable.method)
    end
  end
end

#remaining_attributesObject



38
# File 'lib/cafe_car/table/builder.rb', line 38

def remaining_attributes = policy.listable_attributes - @shown_attributes.keys

#shownObject



22
# File 'lib/cafe_car/table/builder.rb', line 22

def shown             = @shown_attributes

#shown!(method) ⇒ Object



21
# File 'lib/cafe_car/table/builder.rb', line 21

def shown!(method)    = @shown_attributes[method] = true

#timestamp_attributeObject



36
# File 'lib/cafe_car/table/builder.rb', line 36

def timestamp_attribute = %w[updated_at created_at].find { has? _1 }

#timestampsObject



34
# File 'lib/cafe_car/table/builder.rb', line 34

def timestamps(...) = cell(timestamp_attribute, ...)

#title(method = policy.title_attribute) ⇒ Object



26
27
28
# File 'lib/cafe_car/table/builder.rb', line 26

def title(method = policy.title_attribute, *, **, &)
  cell(method, *, href: true, blank: "(none)", **, &)
end

#to_sObject



49
# File 'lib/cafe_car/table/builder.rb', line 49

def to_s       = @to_s ||= to_html.to_s

#~@Object



50
# File 'lib/cafe_car/table/builder.rb', line 50

def ~@         = @template.concat(to_s)