Class: PlatformosCheck::AppFile
- Inherits:
-
Object
- Object
- PlatformosCheck::AppFile
show all
- Defined in:
- lib/platformos_check/app_file.rb
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(relative_path, storage) ⇒ AppFile
Returns a new instance of AppFile.
9
10
11
12
13
14
15
|
# File 'lib/platformos_check/app_file.rb', line 9
def initialize(relative_path, storage)
@relative_path = relative_path
@storage = storage
@source = nil
@version = nil
@eol = "\n"
end
|
Instance Attribute Details
#storage ⇒ Object
Returns the value of attribute storage.
7
8
9
|
# File 'lib/platformos_check/app_file.rb', line 7
def storage
@storage
end
|
#version ⇒ Object
Returns the value of attribute version.
7
8
9
|
# File 'lib/platformos_check/app_file.rb', line 7
def version
@version
end
|
Instance Method Details
#==(other) ⇒ Object
Also known as:
eql?
107
108
109
|
# File 'lib/platformos_check/app_file.rb', line 107
def ==(other)
other.is_a?(self.class) && relative_path == other.relative_path
end
|
#build_name ⇒ Object
33
34
35
36
37
38
39
40
|
# File 'lib/platformos_check/app_file.rb', line 33
def build_name
n = remove_extension(relative_path.sub(dir_prefix, '')).to_s
return n if module_name.nil?
return n if n.start_with?(module_prefix)
"#{module_prefix}#{n}"
end
|
#dir_prefix ⇒ Object
42
43
44
|
# File 'lib/platformos_check/app_file.rb', line 42
def dir_prefix
nil
end
|
#graphql? ⇒ Boolean
91
92
93
|
# File 'lib/platformos_check/app_file.rb', line 91
def graphql?
false
end
|
#liquid? ⇒ Boolean
87
88
89
|
# File 'lib/platformos_check/app_file.rb', line 87
def liquid?
false
end
|
#module_name ⇒ Object
50
51
52
53
54
55
|
# File 'lib/platformos_check/app_file.rb', line 50
def module_name
@module_name ||= begin
dir_names = @relative_path.split(File::SEPARATOR).reject(&:empty?)
dir_names.first == 'modules' ? dir_names[1] : nil
end
end
|
#module_prefix ⇒ Object
46
47
48
|
# File 'lib/platformos_check/app_file.rb', line 46
def module_prefix
@module_prefix ||= "modules#{File::SEPARATOR}#{module_name}#{File::SEPARATOR}"
end
|
#name ⇒ Object
25
26
27
|
# File 'lib/platformos_check/app_file.rb', line 25
def name
@name ||= dir_prefix.nil? ? remove_extension(relative_path).to_s : build_name
end
|
#page? ⇒ Boolean
95
96
97
|
# File 'lib/platformos_check/app_file.rb', line 95
def page?
false
end
|
#partial? ⇒ Boolean
99
100
101
|
# File 'lib/platformos_check/app_file.rb', line 99
def partial?
false
end
|
#path ⇒ Object
17
18
19
|
# File 'lib/platformos_check/app_file.rb', line 17
def path
@storage.path(@relative_path)
end
|
#relative_path ⇒ Object
21
22
23
|
# File 'lib/platformos_check/app_file.rb', line 21
def relative_path
@relative_pathname ||= Pathname.new(@relative_path)
end
|
#remove_extension(path) ⇒ Object
29
30
31
|
# File 'lib/platformos_check/app_file.rb', line 29
def remove_extension(path)
path.sub_ext('')
end
|
#source ⇒ Object
For the corrector to work properly, we should have a simple mental model of the internal representation of eol characters (Windows uses rn, Linux uses n).
Parser::Source::Buffer strips the r from the source file, so if you are autocorrecting the file you might lose that info and cause a git diff. It also makes the node.start_index/end_index calculation break. That’s not cool.
So in here we track whether the source file has rn in it and we’ll make sure that the file we write has the same eol as the source file.
69
70
71
72
73
74
75
76
77
78
79
80
81
|
# File 'lib/platformos_check/app_file.rb', line 69
def source
return @source if @source
if @storage.versioned?
@source, @version = @storage.read_version(@relative_path)
else
@source = @storage.read(@relative_path)
end
@eol = @source.include?("\r\n") ? "\r\n" : "\n"
@source = @source
.gsub(/\r(?!\n)/, "\r\n")
.gsub("\r\n", "\n")
end
|
#translation? ⇒ Boolean
103
104
105
|
# File 'lib/platformos_check/app_file.rb', line 103
def translation?
false
end
|
#yaml? ⇒ Boolean
83
84
85
|
# File 'lib/platformos_check/app_file.rb', line 83
def yaml?
false
end
|