From b0156e5f54dc0681bdfd54ec6cfc95d7d0a85a75 Mon Sep 17 00:00:00 2001 From: Nicolas Sanguinetti Date: Tue, 13 Feb 2024 17:50:34 -0500 Subject: [PATCH] Improve ergonomics of Column#options[:database] --- lib/dtb/column.rb | 8 +++++++- test/column_test.rb | 2 ++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/lib/dtb/column.rb b/lib/dtb/column.rb index b5acabb..a32e5e4 100644 --- a/lib/dtb/column.rb +++ b/lib/dtb/column.rb @@ -44,7 +44,7 @@ class Column < QueryBuilder # @!group Options - # @!method options[:database] + # @!attribute [rw] database # Whether to affect the query or not. If this is false, this Column's # {#call} method does nothing (just returns its input). This is useful for # laying out purely presentational columns on data tables, such as actions @@ -73,6 +73,12 @@ def header i18n_lookup(:columns, default: "") end + # @return [Boolean] whether this column actually affects the query or not. + # @see #database + def database? + options[:database] + end + # @visibility private def evaluate? options[:database] && super diff --git a/test/column_test.rb b/test/column_test.rb index 0bce479..3ebd56e 100644 --- a/test/column_test.rb +++ b/test/column_test.rb @@ -14,6 +14,7 @@ def test_modifies_query_by_default assert col.evaluate? assert col.render? assert_equal true, col.options[:database] + assert col.database? assert_equal 1, col.call(0) end @@ -23,6 +24,7 @@ def test_can_skip_query_if_not_database refute col.evaluate? assert col.render? assert_equal false, col.options[:database] + refute col.database? assert_equal 0, col.call(0) end