Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@

* N/A

## [0.2.1] - 2026-02-23

### Fixed
- Avoid `ArgumentError: comparison of Symbol with 0 failed` when `Rails.logger` is wrapped by SemanticLogger (or any logger whose `level` is not an integer). Override warnings now only compare level when it is an integer.

## [0.2.0] - 2026-02-19

### Changed
Expand Down
5 changes: 4 additions & 1 deletion lib/declarative_initialization/internal.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ def warn_override(klass, key, block_reader:)
def warn_override?
return true if defined?(Rails) && Rails.respond_to?(:env) && (Rails.env.development? || Rails.env.test?)

logger.level <= Logger::DEBUG
level = logger.level
return false unless level.is_a?(Integer)

level <= Logger::DEBUG
end

def override_location(klass, key)
Expand Down
2 changes: 1 addition & 1 deletion lib/declarative_initialization/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module DeclarativeInitialization
VERSION = "0.2.0"
VERSION = "0.2.1"
end
13 changes: 13 additions & 0 deletions spec/reader_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,19 @@ def foo = @foo * 100
allow(DeclarativeInitialization::Internal).to receive(:warn_override?).and_return(true)
end

describe "warn_override? with non-standard loggers (e.g. SemanticLogger)" do
it "does not compare symbol level with Integer (avoids ArgumentError)" do
semantic_logger = instance_double(Logger, level: :info)
allow(DeclarativeInitialization::Internal).to receive(:logger).and_return(semantic_logger)
allow(DeclarativeInitialization::Internal).to receive(:warn_override?).and_call_original
# Ensure we hit the level check (not the Rails dev/test early return)
rails_env = Struct.new(:development?, :test?).new(false, false)
stub_const("Rails", Class.new { define_singleton_method(:env) { rails_env } })

expect(DeclarativeInitialization::Internal.warn_override?).to eq(false)
end
end

def attr_override_warning(key, location: "on this class")
"[Anonymous Class] Method ##{key} already exists #{location} -- overriding with init-arg reader"
end
Expand Down