Refactor and fix as-of-time join sources
Refactor and fix as-of-time join sources

The build failure https://travis-ci.org/ifad/chronomodel/jobs/273285231
highlighted a crash on Rails 4.2 of the .count method invoked on chrono
associations.

The reason is that AR in 4.2 expects the join sources to be Arel::Table
objects, but in chrono associations we replace them with virtual tables
fetching from the history at a given as-of-time using Arel::SqlLiteral.

The problem was sidestepped in a30c1b50 by monkeypatching the singleton
class of each join source, only for a specific has-many-through case.

This patch removes the singleton monkeypatch, that also has performance
issues - because it invalidates the method cache - by introducing a new
class inheriting from Arel::SqlLiteral and preserves the interface that
AR expects.

ifad/chronomodel