Sha256: a5060262fd32dc054cf3a406355898a5579e0937153981c48bd90d8e05062a79

Contents?: true

Size: 786 Bytes

Versions: 4

Compression:

Stored size: 786 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 update_contents(new_content = '{}')
      @content = new_content
    end

    def write
      if source != @content
        @storage.write(@relative_path, content)
        @source = content
      end
    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

4 entries across 4 versions & 1 rubygems

Version Path
theme-check-1.5.2 lib/theme_check/json_file.rb
theme-check-1.5.1 lib/theme_check/json_file.rb
theme-check-1.5.0 lib/theme_check/json_file.rb
theme-check-1.4.0 lib/theme_check/json_file.rb