Sha256: 3da5f93e1c7a91baeb1bd71063d450b78afeb64088199eacdc123ce3012c6478

Contents?: true

Size: 941 Bytes

Versions: 3

Compression:

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

    def json?
      true
    end

    def liquid?
      false
    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.10.0 lib/theme_check/json_file.rb
theme-check-0.9.1 lib/theme_check/json_file.rb
theme-check-0.9.0 lib/theme_check/json_file.rb