josedonizetti / ruby-duration

Immutable type that represents some amount of time with accuracy in seconds.
http://bit.ly/ruby-duration
MIT License
124 stars 23 forks source link

I18n broken dependency #1

Closed pda closed 13 years ago

pda commented 13 years ago

I18n is being depended on by Duration#format but not required anywhere.

Something in the test environment seems to be indirectly loading I18n, but I'm not sure what. Either way, in Rails and in the tests, it's loaded elsewhere, so the bug is not apparent.

However, outside of these environments:

ruby -I'lib' -r'ruby-duration' -e 'puts Duration.new.format("%s")'
.../ruby-duration/lib/duration.rb:149:in `format': \
  uninitialized constant Duration::I18n (NameError)

Can be fixed by loading i18n:

ruby -I'lib' -r'ruby-duration' -r'i18n' -e 'puts Duration.new.format("%s seconds")'
0 seconds

Tested with Ruby 1.9.2p0 on Linux and Mac OS.

Thanks for picking up the reins from the old duration gem.. apart from being abandoned it seems to be broken under Ruby 1.9 because of multi-byte chars declared in a US-ASCII context.. or something.

Cheers! Paul

azisaka commented 13 years ago

Hi, Paul.

I just released the patch for this issue. We mainly use this gem with Ruby on Rails and/or Mongoid, and both already require I18n, that's why the "explicit" require was missing.

Thanks for pointing it and sorry for the delay to release the patch.

pda commented 13 years ago

Cheers! Three days turnaround is plenty fast when you're doing it for free :)