Skip to content

Commit

Permalink
Merge pull request #683 from fatkodima/add-inspect-to-fallbacks
Browse files Browse the repository at this point in the history
Implement `Fallbacks#inspect` and `Fallbacks#empty?`
  • Loading branch information
radar committed Mar 5, 2024
2 parents 284ae1b + 9e86475 commit 5fb9e63
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 0 deletions.
8 changes: 8 additions & 0 deletions lib/i18n/locale/fallbacks.rb
Expand Up @@ -79,6 +79,14 @@ def map(*args, &block)
end
end

def empty?
@map.empty? && @defaults.empty?
end

def inspect
"#<#{self.class.name} @map=#{@map.inspect} @defaults=#{@defaults.inspect}>"
end

protected

def compute(tags, include_defaults = true, exclude = [])
Expand Down
11 changes: 11 additions & 0 deletions test/locale/fallbacks_test.rb
Expand Up @@ -170,4 +170,15 @@ def setup
result = @fallbacks.map { |key, value| [key, value] }
assert_equal([[:"de-AT", [:"de-DE"]]], result)
end

test "empty? is compatible with Hash#empty?" do
refute_predicate(@fallbacks, :empty?)
refute_predicate(Fallbacks.new(:'en-US'), :empty?)
refute_predicate(Fallbacks.new(:"de-AT" => :"de-DE"), :empty?)
assert_predicate(Fallbacks.new, :empty?)
end

test "#inspect" do
assert_equal('#<I18n::Locale::Fallbacks @map={:"de-AT"=>[:"de-DE"]} @defaults=[:"en-US", :en]>', @fallbacks.inspect)
end
end

0 comments on commit 5fb9e63

Please sign in to comment.