jackc / tod

Time of day and shift types for Ruby
MIT License
435 stars 56 forks source link

Add method for use in Rails database quoting #62

Closed bjackson2 closed 6 years ago

bjackson2 commented 6 years ago

This adds a method value_for_database to the Tod::TimeOfDay class. When ActiveRecord is preparing to 'quote' an object for use in a SQL query, it asks the object if it responds to this method. If so, it calls quote() with the return value rather than with the object itself.

This will allow usage of instances of Tod::TimeOfDay when building queries:

MyModel.where("open_at > ?", Tod::TimeOfDay.new(12, 30))
jackc commented 6 years ago

Nice, thanks!