Skip to content

Commit

Permalink
Improve ergonomics of Column#options[:database]
Browse files Browse the repository at this point in the history
  • Loading branch information
foca committed Feb 13, 2024
1 parent 5d8b510 commit b0156e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 7 additions & 1 deletion lib/dtb/column.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions test/column_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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

Expand Down

0 comments on commit b0156e5

Please sign in to comment.