Skip to content

Commit 6334ed3

Browse files
justin808claude
andcommitted
Add compact_blank polyfill for Rails 5.2-6.0 compatibility
The previous commit added `require "active_support/core_ext/enumerable"` but this doesn't provide `compact_blank` on Rails < 6.1 because that method was only introduced in Rails 6.1. This commit adds a proper polyfill that: 1. Checks if compact_blank already exists (Rails 6.1+) 2. If not, defines it on both Enumerable and Array using reject(&:blank?) 3. Also requires "active_support/core_ext/object/blank" for the blank? method The polyfill correctly mirrors Rails 6.1+ behavior: - Removes nil, empty strings (""), whitespace strings (" ") - Removes false (since false.blank? == true in ActiveSupport) - Keeps truthy values like non-empty strings, true, numbers This ensures the gem works correctly on all supported Rails versions (>= 5.2). 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <[email protected]>
1 parent 0dc07ac commit 6334ed3

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

lib/react_on_rails/configuration.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
# frozen_string_literal: true
22

33
require "active_support/core_ext/enumerable"
4+
require "active_support/core_ext/object/blank"
5+
6+
# Polyfill for compact_blank (added in Rails 6.1) to support Rails 5.2-6.0
7+
unless [].respond_to?(:compact_blank)
8+
module Enumerable
9+
def compact_blank
10+
reject(&:blank?)
11+
end
12+
end
13+
14+
class Array
15+
def compact_blank
16+
reject(&:blank?)
17+
end
18+
end
19+
end
420

521
# rubocop:disable Metrics/ClassLength
622

0 commit comments

Comments
 (0)