Class: Rail::Precompiler::Storage

Inherits:
Object
  • Object
show all
Defined in:
lib/rail/precompiler.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(root = 'public') ⇒ Storage

Returns a new instance of Storage.



6
7
8
# File 'lib/rail/precompiler.rb', line 6

def initialize(root = 'public')
  @root = root
end

Instance Attribute Details

#rootObject (readonly)

Returns the value of attribute root.



4
5
6
# File 'lib/rail/precompiler.rb', line 4

def root
  @root
end

Instance Method Details

#write(file, stream) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
# File 'lib/rail/precompiler.rb', line 10

def write(file, stream)
  file = File.join(root, file)

  unless File.exist?(File.dirname(file))
    FileUtils.mkdir_p(File.dirname(file))
  end

  File.open(file, 'w') do |file|
    stream.each { |chunk| file.write(chunk) }
  end
end