<commit_before>require "ostruct"
require "active_record"

module Padlock
  class << self
    def config
      @@config ||= OpenStruct.new(
        table_name: "padlocks",
        user_foreign_key: "user_id",
        user_class_name: "User",
        timeout: 1.day
      )
    end

    def lock(user, *objects)
      objects.each do |object|
        unlock!(object)
        user.padlocks.create(lockable: object)
        object.reload
      end
    end

    def locked? object
      object.locked?
    end

    def unlock! *objects
      objects.each { |object| object.unlock! }
    end

    def unlocked? object
      object.unlocked?
    end

    def unlock_stale
      stale_locks.destroy_all
    end

    def touch *objects
      objects.each do |object|
        if object.locked?
          object.updated_at = Time.now
          object.save
        end
      end
    end

    private

    def timeout
      Time.now - config.timeout
    end

    def stale_locks
      Padlock::Instance.where("updated_at >= ?", timeout)
    end
  end
end

require "padlock/version"
require "padlock/instance"
require "padlock/lockable"
require "padlock/user"
require "padlock/integrations"
require "generators/padlock_generator"<commit_msg>Update padlock.rb<commit_after>require "ostruct"
require "active_record"

module Padlock
  class << self
    def config
      @config ||= OpenStruct.new(
        table_name: "padlocks",
        user_foreign_key: "user_id",
        user_class_name: "User",
        timeout: 1.day
      )
    end

    def lock(user, *objects)
      objects.each do |object|
        unlock!(object)
        user.padlocks.create(lockable: object)
        object.reload
      end
    end

    def locked? object
      object.locked?
    end

    def unlock! *objects
      objects.each(&:unlock!)
    end

    def unlocked? object
      object.unlocked?
    end

    def unlock_stale
      stale_locks.destroy_all
    end

    def touch *objects
      objects.select(&:locked?).each do |object|
        object.update_attribute(:updated_at, Time.now)
      end
    end

    private

    def timeout
      Time.now - config.timeout
    end

    def stale_locks
      Padlock::Instance.where("updated_at >= ?", timeout)
    end
  end
end

require "padlock/version"
require "padlock/instance"
require "padlock/lockable"
require "padlock/user"
require "padlock/integrations"
require "generators/padlock_generator"
{'fraction_non_alphanumeric': 0.08906379453189726, 'fraction_numerical': 0.0008285004142502071, 'mean_word_length': 2.3173076923076925, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '1946481', 'n_tokens_mistral': 767, 'n_tokens_neox': 730, 'n_words': 180}