Sha256: 21f73baebd15f9f4e0cb7b88108e22d73744828227a993ad2083fb8fd8ac827d

Contents?: true

Size: 535 Bytes

Versions: 25

Compression:

Stored size: 535 Bytes

Contents

# frozen_string_literal: true

module PlatformosCheck
  module JsonHelpers
    def format_json_parse_error(error)
      message = error.message[/\d+: (.+)$/, 1] || 'Invalid syntax'
      "#{message} in JSON"
    end

    def pretty_json(hash, start_level: 1, indent: "  ")
      start_indent = indent * start_level

      <<~JSON

        #{start_indent}#{JSON.pretty_generate(
          hash,
          indent:,
          array_nl: "\n#{start_indent}",
          object_nl: "\n#{start_indent}"
        )}
      JSON
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
platformos-check-0.4.14 lib/platformos_check/json_helpers.rb
platformos-check-0.4.13 lib/platformos_check/json_helpers.rb
platformos-check-0.4.12 lib/platformos_check/json_helpers.rb
platformos-check-0.4.11 lib/platformos_check/json_helpers.rb
platformos-check-0.4.10 lib/platformos_check/json_helpers.rb
platformos-check-0.4.9 lib/platformos_check/json_helpers.rb
platformos-check-0.4.8 lib/platformos_check/json_helpers.rb
platformos-check-0.4.7 lib/platformos_check/json_helpers.rb
platformos-check-0.4.6 lib/platformos_check/json_helpers.rb
platformos-check-0.4.5 lib/platformos_check/json_helpers.rb
platformos-check-0.4.4 lib/platformos_check/json_helpers.rb
platformos-check-0.4.3 lib/platformos_check/json_helpers.rb
platformos-check-0.4.2 lib/platformos_check/json_helpers.rb
platformos-check-0.4.1 lib/platformos_check/json_helpers.rb
platformos-check-0.4.0 lib/platformos_check/json_helpers.rb
platformos-check-0.3.3 lib/platformos_check/json_helpers.rb
platformos-check-0.3.1 lib/platformos_check/json_helpers.rb
platformos-check-0.3.0 lib/platformos_check/json_helpers.rb
platformos-check-0.2.2 lib/platformos_check/json_helpers.rb
platformos-check-0.2.1 lib/platformos_check/json_helpers.rb