Sha256: e8d7c2206dad60001cd0eab8a23d0af1adb8b5cd02b6dee9445f60d70f70ecf8

Contents?: true

Size: 1.58 KB

Versions: 19

Compression:

Stored size: 1.58 KB

Contents

require 'base62-rb'
require_relative 'repository'

module Inferno
  module Repositories
    class ValidatorSessions < Repository
      def save(params)
        validator_session_id = params[:validator_session_id]
        validator_name = params[:validator_name]
        test_suite_id = params[:test_suite_id]
        raw_suite_options = params[:suite_options]
        time = Time.now

        suite_options =
          if raw_suite_options.blank?
            '[]'
          else
            raw_suite_options.sort.to_s
          end

        db.insert_conflict(
          target: [:test_suite_id,
                   :suite_options,
                   :validator_name],
          update: { validator_session_id:,
                    test_suite_id:,
                    suite_options:,
                    validator_name: }
        ).insert(
          id: SecureRandom.uuid,
          validator_session_id:,
          test_suite_id:,
          validator_name:,
          suite_options:,
          last_accessed: time
        )
      end

      def find_validator_session_id(test_suite_id, validator_name, suite_options)
        suite_options = suite_options.nil? ? '[]' : suite_options.sort.to_s
        session = self.class::Model
          .find(test_suite_id:, validator_name:, suite_options:)
        return nil if session.nil?

        time = Time.now
        session.update(last_accessed: time)
        session[:validator_session_id]
      end

      class Model < Sequel::Model(db)
        def before_save
          time = Time.now
          self.last_accessed ||= time
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
inferno_core-0.6.1 lib/inferno/repositories/validator_sessions.rb
inferno_core-0.6.0 lib/inferno/repositories/validator_sessions.rb
inferno_core-0.5.4 lib/inferno/repositories/validator_sessions.rb
inferno_core-0.5.3 lib/inferno/repositories/validator_sessions.rb
inferno_core-0.5.2 lib/inferno/repositories/validator_sessions.rb
inferno_core-0.5.1 lib/inferno/repositories/validator_sessions.rb
inferno_core-0.5.0 lib/inferno/repositories/validator_sessions.rb
inferno_core-0.4.44 lib/inferno/repositories/validator_sessions.rb
inferno_core-0.4.43 lib/inferno/repositories/validator_sessions.rb
inferno_core-0.4.42 lib/inferno/repositories/validator_sessions.rb
inferno_core-0.4.41 lib/inferno/repositories/validator_sessions.rb
inferno_core-0.4.40 lib/inferno/repositories/validator_sessions.rb
inferno_core-0.4.39 lib/inferno/repositories/validator_sessions.rb
inferno_core-0.4.38 lib/inferno/repositories/validator_sessions.rb
inferno_core-0.4.35 lib/inferno/repositories/validator_sessions.rb
inferno_core-0.4.34 lib/inferno/repositories/validator_sessions.rb
inferno_core-0.4.33 lib/inferno/repositories/validator_sessions.rb
inferno_core-0.4.32 lib/inferno/repositories/validator_sessions.rb
inferno_core-0.4.31 lib/inferno/repositories/validator_sessions.rb