Class: PlatformosCheck::YamlFile
- Inherits:
-
AppFile
- Object
- AppFile
- PlatformosCheck::YamlFile
show all
- Defined in:
- lib/platformos_check/yaml_file.rb
Instance Attribute Summary
Attributes inherited from AppFile
#storage, #version
Instance Method Summary
collapse
Methods inherited from AppFile
#==, #build_name, #dir_names, #dir_prefix, #graphql?, #liquid?, #module_name, #module_original_file?, #module_original_file_path, #module_overwrite_file?, #module_overwrite_file_path, #module_prefix, #name, #page?, #partial?, #path, #relative_path, #remove_extension, #source, #translation?
Constructor Details
#initialize(relative_path, storage) ⇒ YamlFile
Returns a new instance of YamlFile.
7
8
9
10
11
12
|
# File 'lib/platformos_check/yaml_file.rb', line 7
def initialize(relative_path, storage)
super
@loaded = false
@content = nil
@parser_error = nil
end
|
Instance Method Details
#content ⇒ Object
14
15
16
17
|
# File 'lib/platformos_check/yaml_file.rb', line 14
def content
load!
@content
end
|
#content_to_string ⇒ Object
36
37
38
39
40
41
42
43
44
|
# File 'lib/platformos_check/yaml_file.rb', line 36
def content_to_string
pretty = YAML.dump(@content)
return unless source.rstrip != pretty.rstrip
eof = source.end_with?("\n") ? "\n" : ""
pretty.gsub("\n", @eol) + eof
end
|
#parse_error ⇒ Object
19
20
21
22
|
# File 'lib/platformos_check/yaml_file.rb', line 19
def parse_error
load!
@parser_error
end
|
#update_contents(new_content = {}) ⇒ Object
24
25
26
27
28
|
# File 'lib/platformos_check/yaml_file.rb', line 24
def update_contents(new_content = {})
raise ArgumentError if new_content.is_a?(String)
@content = new_content
end
|
#write ⇒ Object
30
31
32
33
34
|
# File 'lib/platformos_check/yaml_file.rb', line 30
def write
pretty = content_to_string
@storage.write(@relative_path, pretty)
@source = pretty
end
|
#yaml? ⇒ Boolean
46
47
48
|
# File 'lib/platformos_check/yaml_file.rb', line 46
def yaml?
true
end
|