Class: Onload::File

Inherits:
Object show all
Defined in:
lib/onload/file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path) ⇒ File

Returns a new instance of File.



7
8
9
# File 'lib/onload/file.rb', line 7

def initialize(path)
  @path = path
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/onload/file.rb', line 5

def path
  @path
end

Instance Method Details

#outfileObject



21
22
23
24
25
26
# File 'lib/onload/file.rb', line 21

def outfile
  @outfile ||= begin
    base_name = "#{Onload.basename(path)}.rb"
    ::File.join(::File.dirname(path), base_name)
  end
end

#writeObject



11
12
13
14
15
16
17
18
19
# File 'lib/onload/file.rb', line 11

def write
  source = ::File.read(path)

  ::File.extname(path).scan(/\.\w+/).each do |ext|
    source = Onload.processors[ext].call(source)
  end

  ::File.write(outfile, source)
end