Class: ThemeCheck::AssetFile

Inherits:
ThemeFile show all
Defined in:
lib/theme_check/asset_file.rb

Instance Attribute Summary

Attributes inherited from ThemeFile

#storage, #version

Instance Method Summary collapse

Methods inherited from ThemeFile

#==, #json?, #liquid?, #path, #relative_path, #source

Constructor Details

#initialize(relative_path, storage) ⇒ AssetFile

Returns a new instance of AssetFile.



6
7
8
9
10
# File 'lib/theme_check/asset_file.rb', line 6

def initialize(relative_path, storage)
  super
  @loaded = false
  @content = nil
end

Instance Method Details

#gzipped_sizeObject



25
26
27
# File 'lib/theme_check/asset_file.rb', line 25

def gzipped_size
  @gzipped_size ||= Zlib.gzip(source).bytesize
end

#nameObject



29
30
31
# File 'lib/theme_check/asset_file.rb', line 29

def name
  relative_path.to_s
end

#rewriterObject



12
13
14
# File 'lib/theme_check/asset_file.rb', line 12

def rewriter
  @rewriter ||= ThemeFileRewriter.new(@relative_path, source)
end

#writeObject



16
17
18
19
20
21
22
23
# File 'lib/theme_check/asset_file.rb', line 16

def write
  content = rewriter.to_s
  if source != content
    @storage.write(@relative_path, content.gsub("\n", @eol))
    @source = content
    @rewriter = nil
  end
end