Skip to content

Commit

Permalink
Implement Fallbacks#inspect and Fallbacks#empty?
Browse files Browse the repository at this point in the history
  • Loading branch information
fatkodima committed Mar 5, 2024
1 parent baf8a88 commit aca633e
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
Original file line number Diff line number Diff line change
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
Original file line number Diff line number Diff line change
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 aca633e

Please sign in to comment.