Class: Skyrocket::AssetWriter

Inherits:
Object
  • Object
show all
Defined in:
lib/skyrocket/asset_writer.rb

Instance Method Summary collapse

Instance Method Details

#delete(output_path) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/skyrocket/asset_writer.rb', line 23

def delete(output_path)
  File.delete(output_path)
  dir_parts = output_path.split(File::SEPARATOR)[0..-2]
  dir_parts.length.times do |index|
    neg_index = -1 - index
    path = dir_parts[0..neg_index].join(File::SEPARATOR)
    if Dir.entries(path) == ['.','..']
      Dir.rmdir(path)
    else
      break
    end
  end
end

#write(asset) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/skyrocket/asset_writer.rb', line 6

def write(asset)
  if(File.exist?(asset.output_path))
    existing = File.read(asset.output_path)
    if existing != asset.content
      File.write_file(asset.output_path, asset.content)
      :modified
    else
      :no_change
    end
  else
    dirname = File.dirname(asset.output_path)
    FileUtils.mkdir_p(dirname) 
    File.write_file(asset.output_path, asset.content)
    :created
  end
end