Sha256: a36533fd7d3a28bae3454cf94b27d4bcc48d8d391c525ac148dffa5cb11a4b36

Contents?: true

Size: 960 Bytes

Versions: 37

Compression:

Stored size: 960 Bytes

Contents

# frozen_string_literal: true

module SidekiqUniqueJobs
  # Handles loading and dumping of json
  #
  # @author Mikael Henriksson <mikael@mhenrixon.com>
  module JSON
    module_function

    #
    # Parses a JSON string into an object
    #
    # @param [String] string the object to parse
    #
    # @return [Object]
    #
    def load_json(string)
      return if string.nil? || string.empty?

      ::JSON.parse(string)
    end

    #
    # Prevents trying JSON.load from raising errors given argument is a hash
    #
    # @param [String, Hash] string the JSON string to parse
    #
    # @return [Hash,Array]
    #
    def safe_load_json(string)
      return string if string.is_a?(Hash)

      load_json(string)
    end

    #
    # Dumps an object into a JSON string
    #
    # @param [Object] object a JSON convertible object
    #
    # @return [String] a JSON string
    #
    def dump_json(object)
      ::JSON.generate(object)
    end
  end
end

Version data entries

37 entries across 37 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-8.0.10 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-7.1.33 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-7.1.32 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-8.0.9 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-8.0.8 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-8.0.7 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-8.0.6 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-7.1.31 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-8.0.5 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-8.0.4 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-7.1.30 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-8.0.3 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-8.0.2 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-8.0.1 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-8.0.0 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-7.1.29 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-7.1.28 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-7.1.27 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-7.1.26 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-7.1.25 lib/sidekiq_unique_jobs/json.rb