Sha256: 618839781f3bfc82ab403a5cca1058cdb6bd60a3114340b374e53abcd2feff3e

Contents?: true

Size: 692 Bytes

Versions: 5

Compression:

Stored size: 692 Bytes

Contents

# frozen_string_literal: true

module Masks
  # Represents a device, used for interacting with a session.
  #
  # Device detection is optionally added with the +Device+ credential,
  # using the +device-detector+ gem.
  #
  # @see Masks::Credentials::Device Masks::Credentials::Device
  class Device < ApplicationModel
    attribute :session

    def fingerprint
      return unless detector.known?

      input = [
        detector.name,
        detector.os_name,
        detector.device_name,
        detector.device_type
      ].compact.join("-")

      Digest::SHA512.hexdigest(input)
    end

    def detector
      @detector ||= DeviceDetector.new(session.user_agent)
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
masks-0.4.0 app/models/masks/device.rb
masks-0.3.2 app/models/masks/device.rb
masks-0.3.1 app/models/masks/device.rb
masks-0.3.0 app/models/masks/device.rb
masks-0.2.0 app/models/masks/device.rb