Class: ThemeCheck::JsonFile
Instance Attribute Summary
Attributes inherited from ThemeFile
#storage, #version
Instance Method Summary
collapse
Methods inherited from ThemeFile
#==, #liquid?, #name, #path, #relative_path, #source
Constructor Details
#initialize(relative_path, storage) ⇒ JsonFile
Returns a new instance of JsonFile.
6
7
8
9
10
11
|
# File 'lib/theme_check/json_file.rb', line 6
def initialize(relative_path, storage)
super
@loaded = false
@content = nil
@parser_error = nil
end
|
Instance Method Details
#content ⇒ Object
13
14
15
16
|
# File 'lib/theme_check/json_file.rb', line 13
def content
load!
@content
end
|
#json? ⇒ Boolean
39
40
41
|
# File 'lib/theme_check/json_file.rb', line 39
def json?
true
end
|
#parse_error ⇒ Object
18
19
20
21
|
# File 'lib/theme_check/json_file.rb', line 18
def parse_error
load!
@parser_error
end
|
#update_contents(new_content = {}) ⇒ Object
23
24
25
26
|
# File 'lib/theme_check/json_file.rb', line 23
def update_contents(new_content = {})
raise ArgumentError if new_content.is_a?(String)
@content = new_content
end
|
#write ⇒ Object
28
29
30
31
32
33
34
35
36
37
|
# File 'lib/theme_check/json_file.rb', line 28
def write
pretty = JSON.pretty_generate(@content)
if source.rstrip != pretty.rstrip
eof = source.end_with?("\n") ? "\n" : ""
@storage.write(@relative_path, pretty.gsub("\n", @eol) + eof)
@source = pretty
end
end
|