Class: CafeCar::Table::Builder
Instance Attribute Summary collapse
Instance Method Summary
collapse
#assign_option!, #assign_options!, #get_options
#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
#ui ⇒ Object
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
24
|
# File 'lib/cafe_car/table/builder.rb', line 24
def has?(method) = model.info.fields.has?(method)
|
#html_safe? ⇒ 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 logo(method = policy.logo_attribute, *, **, &)
cell(method, *, label: nil, blank: "", **, &) if method
end
|
#model_name ⇒ Object
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_attributes ⇒ Object
38
|
# File 'lib/cafe_car/table/builder.rb', line 38
def remaining_attributes = policy.listable_attributes - @shown_attributes.keys
|
#shown ⇒ Object
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_attribute ⇒ Object
36
|
# File 'lib/cafe_car/table/builder.rb', line 36
def timestamp_attribute = %w[updated_at created_at].find { has? _1 }
|
#timestamps ⇒ Object
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_s ⇒ Object
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)
|