Sha256: d5d6faa7873fc4eae1b8f4184235aac65ba217791d2949634337f6acc52a7883

Contents?: true

Size: 569 Bytes

Versions: 3

Compression:

Stored size: 569 Bytes

Contents

# frozen_string_literal: true
require "json"

module ThemeCheck
  class JsonFile < ThemeFile
    def initialize(relative_path, storage)
      super
      @loaded = false
      @content = nil
      @parser_error = nil
    end

    def content
      load!
      @content
    end

    def parse_error
      load!
      @parser_error
    end

    def json?
      true
    end

    private

    def load!
      return if @loaded

      @content = JSON.parse(source)
    rescue JSON::ParserError => e
      @parser_error = e
    ensure
      @loaded = true
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
theme-check-1.3.0 lib/theme_check/json_file.rb
theme-check-1.2.0 lib/theme_check/json_file.rb
theme-check-1.1.0 lib/theme_check/json_file.rb