Sha256: 7708bd1bd4299a21aa1761903630d97f39629141a8c5e54e08428049028d23ed

Contents?: true

Size: 870 Bytes

Versions: 3

Compression:

Stored size: 870 Bytes

Contents

# frozen_string_literal: true
require "json"
require "pathname"

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

    def path
      @storage.path(@relative_path)
    end

    def relative_path
      @relative_pathname ||= Pathname.new(@relative_path)
    end

    def source
      @source ||= @storage.read(@relative_path)
    end

    def content
      load!
      @content
    end

    def parse_error
      load!
      @parser_error
    end

    def name
      relative_path.sub_ext('').to_s
    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-0.8.3 lib/theme_check/json_file.rb
theme-check-0.8.2 lib/theme_check/json_file.rb
theme-check-0.8.1 lib/theme_check/json_file.rb