Class: ThemeCheck::ThemeFile
- Inherits:
-
Object
- Object
- ThemeCheck::ThemeFile
- Defined in:
- lib/theme_check/theme_file.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#storage ⇒ Object
readonly
Returns the value of attribute storage.
-
#version ⇒ Object
readonly
Returns the value of attribute version.
Instance Method Summary collapse
- #==(other) ⇒ Object (also: #eql?)
-
#initialize(relative_path, storage) ⇒ ThemeFile
constructor
A new instance of ThemeFile.
- #json? ⇒ Boolean
- #liquid? ⇒ Boolean
- #name ⇒ Object
- #path ⇒ Object
- #relative_path ⇒ Object
-
#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).
Constructor Details
#initialize(relative_path, storage) ⇒ ThemeFile
Returns a new instance of ThemeFile.
8 9 10 11 12 13 14 |
# File 'lib/theme_check/theme_file.rb', line 8 def initialize(relative_path, storage) @relative_path = relative_path @storage = storage @source = nil @version = nil @eol = "\n" end |
Instance Attribute Details
#storage ⇒ Object (readonly)
Returns the value of attribute storage.
6 7 8 |
# File 'lib/theme_check/theme_file.rb', line 6 def storage @storage end |
#version ⇒ Object (readonly)
Returns the value of attribute version.
6 7 8 |
# File 'lib/theme_check/theme_file.rb', line 6 def version @version end |
Instance Method Details
#==(other) ⇒ Object Also known as: eql?
59 60 61 |
# File 'lib/theme_check/theme_file.rb', line 59 def ==(other) other.is_a?(self.class) && relative_path == other.relative_path end |
#json? ⇒ Boolean
51 52 53 |
# File 'lib/theme_check/theme_file.rb', line 51 def json? false end |
#liquid? ⇒ Boolean
55 56 57 |
# File 'lib/theme_check/theme_file.rb', line 55 def liquid? false end |
#name ⇒ Object
24 25 26 |
# File 'lib/theme_check/theme_file.rb', line 24 def name relative_path.sub_ext('').to_s end |
#path ⇒ Object
16 17 18 |
# File 'lib/theme_check/theme_file.rb', line 16 def path @storage.path(@relative_path) end |
#relative_path ⇒ Object
20 21 22 |
# File 'lib/theme_check/theme_file.rb', line 20 def relative_path @relative_pathname ||= Pathname.new(@relative_path) 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.
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/theme_check/theme_file.rb', line 40 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", "\n") end |