title: Using where method with specific time versions on a class with Paper_trail
body: <p>I'm auditing the state column of the User model with PaperTrail. I need to search all entries with the state "active" BUT at a specific time in history. Something like this:</p>
  
  <pre><code>User.where('version_at(time).state = ?', "active)
  </code></pre>
  
  <p>PaperTrail has that version_at(date) method but it is an instance method and I could not find a class one.</p>
  
  <p>Currently I'm doing the following but is highly inelegant and it does thousands of queries to get what I need:</p>
  
  <pre><code>assigning_users_ids = []
    User.each do |user|
      if user.version_at(@date).state == "active"
        assigning_users_ids &lt;&lt; { user_id: user.id, profile_id: user.profile_id}
      end
    end
  </code></pre>
  
  <p>Now I have all the user ids and profiles in an array and I need to separate them by profile:</p>
  
  <pre><code>  @assignable_starter_ids = []
    @assignable_general_ids = []
    @assignable_pro_ids = []
    @assignable_reduce_ids = []
    assigning_users_ids.each do |a|
      case a[:profile_id]
      when Profile.starter.id
        @assignable_starter_ids &lt;&lt; a[:user_id]
      when Profile.general.id
        @assignable_general_ids &lt;&lt; a[:user_id]
      when Profile.pro.id
        @assignable_pro_ids &lt;&lt; a[:user_id]
      when Profile.reduce.id
        @assignable_reduce_ids &lt;&lt; a[:user_id]
      end
    end
    @assignable_starter = User.where(id: @assignable_starter_ids)
    ...
  </code></pre>
  
  <p>Edit1: This is an example query as a result of .user.version_at(@date)</p>
  
  <pre><code>PaperTrail::Version Load (0.5ms)  SELECT  `versions`.* FROM `versions` WHERE `versions`.`item_id` = 1 AND `versions`.`item_type` = 'User' AND (`versions`.`created_at` &gt; '2016-01-01')  ORDER BY `versions`.`created_at` ASC, `versions`.`id` ASC LIMIT 1  
  CACHE (0.0ms)  SELECT  `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1  [["id", 1]]
  </code></pre>
  
  <p>Edit2: This is version_at method in PaperTrail files:</p>
  
  <pre><code>def version_at(timestamp, reify_options={})
    # Because a version stores how its object looked *before* the change,
    # we need to look for the first version created *after* the timestamp.
    v = send(self.class.versions_association_name).subsequent(timestamp, true).first
    return v.reify(reify_options) if v
    self unless self.destroyed?
  end
  </code></pre>
  
  <p>PaperTrail stores how and object looked before the audited change.So, it looks for the first version saved AFTER the given time. It there is a version it creates the object (without saving it) as it was at that file. If there is no new version, it returns the current object as it is. I'm lowering my expectations...</p>
  
  <p>Also, PaperTrail saves all the object attributes in one string...</p>