Class: RecordViewHelper::RecordValueSetting
- Inherits:
-
Object
- Object
- RecordViewHelper::RecordValueSetting
- Defined in:
- lib/record_view_helper/record_value_setting.rb
Overview
columns with formats, links, etc.
Instance Attribute Summary collapse
-
#attrs ⇒ Object
readonly
attr settings.
-
#formats ⇒ Object
readonly
format settings.
-
#header_attrs ⇒ Object
readonly
header attr settings.
-
#links ⇒ Object
readonly
link settings.
Class Method Summary collapse
Instance Method Summary collapse
-
#attr(column, attr) ⇒ void
set column value dom tag attrs.
-
#column(column, format: nil, link: nil, attr: nil, header_attr: nil) ⇒ void
set column.
-
#columns ⇒ Array<Symbol>
calculated columns.
-
#except(*columns) ⇒ void
add except columns.
-
#format(column, format = nil) {|record| ... } ⇒ void
set column format.
-
#header_attr(column, header_attr) ⇒ void
set column header dom tag attrs.
-
#initialize(columns, table_name, only: nil, except: nil, formats: nil, links: nil, attrs: nil, header_attrs: nil) ⇒ RecordValueSetting
constructor
A new instance of RecordValueSetting.
-
#link(column, link = nil) {|record| ... } ⇒ void
set column link setting.
-
#only(*columns) ⇒ void
add only columns.
-
#table_name(table_name = nil) ⇒ Symbol
set and get table name.
Constructor Details
#initialize(columns, table_name, only: nil, except: nil, formats: nil, links: nil, attrs: nil, header_attrs: nil) ⇒ RecordValueSetting
Returns a new instance of RecordValueSetting.
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/record_view_helper/record_value_setting.rb', line 44 def initialize( # rubocop:disable Metrics/ParameterLists columns, table_name, only: nil, except: nil, formats: nil, links: nil, attrs: nil, header_attrs: nil ) @columns = columns @table_name = table_name @only = only || [] @except = except || [] @formats = formats || {} @links = links || {} @attrs = attrs || {} @header_attrs = header_attrs || {} end |
Instance Attribute Details
#attrs ⇒ Object (readonly)
attr settings
12 13 14 |
# File 'lib/record_view_helper/record_value_setting.rb', line 12 def attrs @attrs end |
#formats ⇒ Object (readonly)
format settings
8 9 10 |
# File 'lib/record_view_helper/record_value_setting.rb', line 8 def formats @formats end |
#header_attrs ⇒ Object (readonly)
header attr settings
14 15 16 |
# File 'lib/record_view_helper/record_value_setting.rb', line 14 def header_attrs @header_attrs end |
#links ⇒ Object (readonly)
link settings
10 11 12 |
# File 'lib/record_view_helper/record_value_setting.rb', line 10 def links @links end |
Class Method Details
.build_from_hash!(columns, table_name, options = {}) ⇒ RecordValueSetting
build from hash
caution: this method deletes given hash options’ key
23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/record_view_helper/record_value_setting.rb', line 23 def self.build_from_hash!(columns, table_name, = {}) new( columns, .delete(:table_name) || table_name, only: .delete(:only), except: .delete(:except), formats: .delete(:formats), links: .delete(:links), attrs: .delete(:attrs), header_attrs: .delete(:header_attrs), ) end |
Instance Method Details
#attr(column, attr) ⇒ void
This method returns an undefined value.
set column value dom tag attrs
148 149 150 |
# File 'lib/record_view_helper/record_value_setting.rb', line 148 def attr(column, attr) @attrs[column] = attr end |
#column(column, format: nil, link: nil, attr: nil, header_attr: nil) ⇒ void
This method returns an undefined value.
set column
175 176 177 178 179 180 |
# File 'lib/record_view_helper/record_value_setting.rb', line 175 def column(column, format: nil, link: nil, attr: nil, header_attr: nil) @formats[column] if format @links[column] if link @attrs[column] if attr @header_attrs[column] = header_attr if header_attr end |
#columns ⇒ Array<Symbol>
calculated columns
184 185 186 |
# File 'lib/record_view_helper/record_value_setting.rb', line 184 def columns (@only.presence || @columns).map(&:to_sym) - @except.map(&:to_sym) end |
#except(*columns) ⇒ void
This method returns an undefined value.
add except columns
99 100 101 |
# File 'lib/record_view_helper/record_value_setting.rb', line 99 def except(*columns) @except += columns.flatten end |
#format(column, format = nil) {|record| ... } ⇒ void
This method returns an undefined value.
set column format
119 120 121 |
# File 'lib/record_view_helper/record_value_setting.rb', line 119 def format(column, format = nil, &block) @formats[column] = block_given? ? block : format end |
#header_attr(column, header_attr) ⇒ void
This method returns an undefined value.
set column header dom tag attrs
160 161 162 |
# File 'lib/record_view_helper/record_value_setting.rb', line 160 def header_attr(column, header_attr) @header_attrs[column] = header_attr end |
#link(column, link = nil) {|record| ... } ⇒ void
This method returns an undefined value.
set column link setting
136 137 138 |
# File 'lib/record_view_helper/record_value_setting.rb', line 136 def link(column, link = nil, &block) @links[column] = block_given? ? block : link end |
#only(*columns) ⇒ void
This method returns an undefined value.
add only columns
87 88 89 |
# File 'lib/record_view_helper/record_value_setting.rb', line 87 def only(*columns) @only += columns.flatten end |
#table_name(table_name = nil) ⇒ Symbol
set and get table name
71 72 73 74 75 76 77 |
# File 'lib/record_view_helper/record_value_setting.rb', line 71 def table_name(table_name = nil) if table_name @table_name = table_name else @table_name end end |