mojombo / chronic

Chronic is a pure Ruby natural language date parser.
http://injekt.github.com/chronic
MIT License
3.23k stars 451 forks source link

Autoload? #94

Closed Miyuki333 closed 12 years ago

Miyuki333 commented 12 years ago

Since chronic loads quite a bit of files, it can be somewhat of a drag when you require it in a web page. Why not use autoload to keep load times minimal depending on how or if chronic is actually used? There are no obvious drawbacks to doing so, and a lot of other projects have already done something similar. Here is what chronic.rb looks like after I made the necessary changes:

require 'time'
require 'date'

#*snip*

module Chronic
  VERSION = "0.6.7"

  class << self
    #*snip*
  end

  self.debug = false
  self.time_class = Time

  autoload :Handler, 'chronic/handler'
  autoload :Handlers, 'chronic/handlers'
  autoload :MiniDate, 'chronic/mini_date'
  autoload :Tag, 'chronic/tag'
  autoload :Span, 'chronic/span'
  autoload :Token, 'chronic/token'
  autoload :Grabber, 'chronic/grabber'
  autoload :Pointer, 'chronic/pointer'
  autoload :Scalar, 'chronic/scalar'
  autoload :Ordinal, 'chronic/ordinal'
  autoload :OrdinalDay, 'chronic/ordinal'
  autoload :Separator, 'chronic/separator'
  autoload :TimeZone, 'chronic/time_zone'
  autoload :Numerizer, 'chronic/numerizer'
  autoload :Season, 'chronic/season'

  autoload :Repeater, 'chronic/repeater'
  autoload :RepeaterYear, 'chronic/repeaters/repeater_year'
  autoload :RepeaterSeason, 'chronic/repeaters/repeater_season'
  autoload :RepeaterSeasonName, 'chronic/repeaters/repeater_season_name'
  autoload :RepeaterMonth, 'chronic/repeaters/repeater_month'
  autoload :RepeaterMonthName, 'chronic/repeaters/repeater_month_name'
  autoload :RepeaterFortnight, 'chronic/repeaters/repeater_fortnight'
  autoload :RepeaterWeek, 'chronic/repeaters/repeater_week'
  autoload :RepeaterWeekend, 'chronic/repeaters/repeater_weekend'
  autoload :RepeaterWeekday, 'chronic/repeaters/repeater_weekday'
  autoload :RepeaterDay, 'chronic/repeaters/repeater_day'
  autoload :RepeaterDayName, 'chronic/repeaters/repeater_day_name'
  autoload :RepeaterDayPortion, 'chronic/repeaters/repeater_day_portion'
  autoload :RepeaterHour, 'chronic/repeaters/repeater_hour'
  autoload :RepeaterMinute, 'chronic/repeaters/repeater_minute'
  autoload :RepeaterSecond, 'chronic/repeaters/repeater_second'
  autoload :RepeaterTime, 'chronic/repeaters/repeater_time'

end

require 'chronic/chronic'

class Time

#*snip*

end
leejarvis commented 12 years ago

If this all passes fine on Ruby 1.8.6+ then I'm happy to do so. Could you knock up a patch and submit a pull, @An0Hit0?