Sha256: 27690eb6372ec4740eb8113db72f909d81e4173dcd026e6a507f232fa2706756

Contents?: true

Size: 1.25 KB

Versions: 24

Compression:

Stored size: 1.25 KB

Contents

# frozen_string_literal: true

module SidekiqUniqueJobs
  #
  # Class Info provides information about a lock
  #
  # @author Mikael Henriksson <mikael@zoolutions.se>
  #
  class LockInfo < Redis::String
    #
    # Returns the value for this key as a hash
    #
    #
    # @return [Hash]
    #
    def value
      @value ||= load_json(super)
    end

    #
    # Check if this redis string is blank
    #
    #
    # @return [Boolean]
    #
    def none?
      value.nil? || value.empty?
    end

    #
    # Check if this redis string has a value
    #
    #
    # @return [Boolean]
    #
    def present?
      !none?
    end

    #
    # Quick access to the hash members for the value
    #
    # @param [String, Symbol] key the key who's value to retrieve
    #
    # @return [Object]
    #
    def [](key)
      value[key.to_s] if value.is_a?(Hash)
    end

    #
    # Writes the lock info to redis
    #
    # @param [Hash] obj the information to store at key
    #
    # @return [Hash]
    #
    def set(obj)
      return unless SidekiqUniqueJobs.config.lock_info
      raise InvalidArgument, "argument `obj` (#{obj}) needs to be a hash" unless obj.is_a?(Hash)

      json = dump_json(obj)
      @value = load_json(json)
      super(json)
      value
    end
  end
end

Version data entries

24 entries across 24 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-7.0.0.beta25 lib/sidekiq_unique_jobs/lock_info.rb
sidekiq-unique-jobs-7.0.0.beta24 lib/sidekiq_unique_jobs/lock_info.rb
sidekiq-unique-jobs-7.0.0.beta23 lib/sidekiq_unique_jobs/lock_info.rb
sidekiq-unique-jobs-7.0.0.beta22 lib/sidekiq_unique_jobs/lock_info.rb
sidekiq-unique-jobs-7.0.0.beta21 lib/sidekiq_unique_jobs/lock_info.rb
sidekiq-unique-jobs-7.0.0.beta20 lib/sidekiq_unique_jobs/lock_info.rb
sidekiq-unique-jobs-7.0.0.beta19 lib/sidekiq_unique_jobs/lock_info.rb
sidekiq-unique-jobs-7.0.0.beta18 lib/sidekiq_unique_jobs/lock_info.rb
sidekiq-unique-jobs-7.0.0.beta17 lib/sidekiq_unique_jobs/lock_info.rb
sidekiq-unique-jobs-7.0.0.beta16 lib/sidekiq_unique_jobs/lock_info.rb
sidekiq-unique-jobs-7.0.0.beta15 lib/sidekiq_unique_jobs/lock_info.rb
sidekiq-unique-jobs-7.0.0.beta14 lib/sidekiq_unique_jobs/lock_info.rb
sidekiq-unique-jobs-7.0.0.beta13 lib/sidekiq_unique_jobs/lock_info.rb
sidekiq-unique-jobs-7.0.0.beta12 lib/sidekiq_unique_jobs/lock_info.rb
sidekiq-unique-jobs-7.0.0.beta11 lib/sidekiq_unique_jobs/lock_info.rb
sidekiq-unique-jobs-7.0.0.beta10 lib/sidekiq_unique_jobs/lock_info.rb
sidekiq-unique-jobs-7.0.0.beta9 lib/sidekiq_unique_jobs/lock_info.rb
sidekiq-unique-jobs-7.0.0.beta8 lib/sidekiq_unique_jobs/lock_info.rb
sidekiq-unique-jobs-7.0.0.beta7 lib/sidekiq_unique_jobs/lock_info.rb
sidekiq-unique-jobs-7.0.0.beta6 lib/sidekiq_unique_jobs/lock_info.rb