<commit_before>module Oauned::Models::Authorization
  def self.included(klass)
    klass.class_eval do
      before_create    :set_default

      def expires_in
        (expires_at - Time.now).to_i
      end
      def expired?
        expires_in <= 0
      end

      def tokenize!
        self.destroy
        Connection.create!(:user_id => user.id, :application_id => application.id)
      end

      private
      def set_default
        self.code = SecureRandom.hex(20)
        self.expires_at = 1.hour.from_now
      end
    end
  end
end<commit_msg>avoid two useless sql queries<commit_after>module Oauned::Models::Authorization
  def self.included(klass)
    klass.class_eval do
      before_create    :set_default

      def expires_in
        (expires_at - Time.now).to_i
      end
      def expired?
        expires_in <= 0
      end

      def tokenize!
        self.destroy
        Connection.create!(:user_id => user_id, :application_id => application_id)
      end

      private
      def set_default
        self.code = SecureRandom.hex(20)
        self.expires_at = 1.hour.from_now
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.0763765541740675, 'fraction_numerical': 0.007104795737122558, 'mean_word_length': 2.0708446866485013, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4103938', 'n_tokens_mistral': 368, 'n_tokens_neox': 350, 'n_words': 77}