Class: Sprockets::SourceFile

Inherits:
Object
  • Object
show all
Defined in:
lib/sprockets/source_file.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(environment, pathname) ⇒ SourceFile

Returns a new instance of SourceFile.



5
6
7
8
# File 'lib/sprockets/source_file.rb', line 5

def initialize(environment, pathname)
  @environment = environment
  @pathname = pathname
end

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



3
4
5
# File 'lib/sprockets/source_file.rb', line 3

def environment
  @environment
end

#pathnameObject (readonly)

Returns the value of attribute pathname.



3
4
5
# File 'lib/sprockets/source_file.rb', line 3

def pathname
  @pathname
end

Instance Method Details

#==(source_file) ⇒ Object



44
45
46
# File 'lib/sprockets/source_file.rb', line 44

def ==(source_file)
  pathname == source_file.pathname
end

#each_source_line(&block) ⇒ Object



36
37
38
# File 'lib/sprockets/source_file.rb', line 36

def each_source_line(&block)
  source_lines.each(&block)
end

#find(location, kind = :file) ⇒ Object



40
41
42
# File 'lib/sprockets/source_file.rb', line 40

def find(location, kind = :file)
  pathname.parent_pathname.find(location, kind)
end

#mtimeObject



48
49
50
51
52
# File 'lib/sprockets/source_file.rb', line 48

def mtime
  File.mtime(pathname.absolute_location)
rescue Errno::ENOENT
  0
end

#source_linesObject



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/sprockets/source_file.rb', line 10

def source_lines
  @lines ||= begin
    lines = []

    comments = []
    File.open(pathname.absolute_location) do |file|
      file.each do |line|
        lines << line = SourceLine.new(self, line, file.lineno)

        if line.begins_pdoc_comment? || comments.any?
          comments << line
        end

        if line.ends_multiline_comment?
          if line.ends_pdoc_comment?
            comments.each { |l| l.comment! }
          end
          comments.clear
        end
      end
    end

    lines
  end
end