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



29
30
31
32
33
34
# File 'lib/onload/file.rb', line 29

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

#write(ignore_file: nil) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/onload/file.rb', line 11

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

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

  ::File.write(outfile, source).tap do
    if ignore_file
      ignore_file.add(outfile)
    elsif Onload.config.ignore_path
      ignore_file = IgnoreFile.load(Onload.config.ignore_path)
      ignore_file.add(outfile)
      ignore_file.persist!
    end
  end
end