Class: ActiveadminDynamicTable::Configurator
- Inherits:
-
Object
- Object
- ActiveadminDynamicTable::Configurator
- Defined in:
- lib/activeadmin_dynamic_table/configurator.rb
Instance Method Summary collapse
- #applicable_columns ⇒ Object
- #columns ⇒ Object
-
#initialize(context, settings) ⇒ Configurator
constructor
A new instance of Configurator.
- #register_column(method, *args, &block) ⇒ Object
- #registered_columns ⇒ Object
- #width_for(key) ⇒ Object
Constructor Details
#initialize(context, settings) ⇒ Configurator
5 6 7 8 9 |
# File 'lib/activeadmin_dynamic_table/configurator.rb', line 5 def initialize(context, settings) @context = context @settings = settings @api_calls = [] end |
Instance Method Details
#applicable_columns ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'lib/activeadmin_dynamic_table/configurator.rb', line 37 def applicable_columns applicable_columns = [] settings.each do |config| applicable_column = @api_calls.detect do |register_call| register_call.key == config.column end applicable_columns << applicable_column if applicable_column.present? end applicable_columns end |
#columns ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/activeadmin_dynamic_table/configurator.rb', line 27 def columns applicable_columns.each do |applicable_column| next @context.id_column *applicable_column.args if applicable_column.method == :id_column next @context.actions(applicable_column.args[1] || applicable_column.args[0], &applicable_column.block) if applicable_column.method == :actions next @context.index_column *applicable_column.args if applicable_column.method == :index_column @context.public_send(applicable_column.method, *applicable_column.args, &applicable_column.block) end end |
#register_column(method, *args, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/activeadmin_dynamic_table/configurator.rb', line 11 def register_column(method, *args, &block) = args[1] || args[0] config = settings_hash[[:key]] || ColumnSettings.new([:key]) config.default_width = [:width] api_call = RegisteredColumn.new method: method, key: [:key], is_default: [:default], args: args, block: block, config: config @api_calls << api_call end |
#registered_columns ⇒ Object
51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/activeadmin_dynamic_table/configurator.rb', line 51 def registered_columns @api_calls.map do |api_call| args = api_call.args { key: api_call.key, selected: selected?(api_call.key), args: args, } end end |
#width_for(key) ⇒ Object
63 64 65 66 67 68 69 |
# File 'lib/activeadmin_dynamic_table/configurator.rb', line 63 def width_for(key) col = settings_hash[key] return ColumnSettings.new(nil).width if col.nil? col.width end |