Sha256: f018ff306dc39429b8c0e6bbb2b0707a6693e603081fe570ebfae28970402088

Contents?: true

Size: 772 Bytes

Versions: 18

Compression:

Stored size: 772 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

    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

18 entries across 18 versions & 1 rubygems

Version Path
sidekiq-unique-jobs-7.0.13 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-7.1.6 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-7.1.5 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-7.1.3 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-7.1.2 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-7.1.1 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-7.1.0 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-7.0.12 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-7.0.11 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-7.0.10 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-7.0.9 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-7.0.8 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-7.0.7 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-7.0.6 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-7.0.5 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-7.0.4 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-7.0.3 lib/sidekiq_unique_jobs/json.rb
sidekiq-unique-jobs-7.0.2 lib/sidekiq_unique_jobs/json.rb