Class: Sprockets::SourceFile

Inherits:
Object
  • Object
show all
Defined in:
lib/sprockets/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.



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

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

Instance Attribute Details

#environmentObject (readonly)

Returns the value of attribute environment.



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

def environment
  @environment
end

#interpolate_constantsObject

Returns the value of attribute interpolate_constants.



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

def interpolate_constants
  @interpolate_constants
end

#pathnameObject (readonly)

Returns the value of attribute pathname.



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

def pathname
  @pathname
end

Instance Method Details

#==(source_file) ⇒ Object



46
47
48
# File 'lib/sprockets/lib/sprockets/source_file.rb', line 46

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

#each_source_line(&block) ⇒ Object



38
39
40
# File 'lib/sprockets/lib/sprockets/source_file.rb', line 38

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

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



42
43
44
# File 'lib/sprockets/lib/sprockets/source_file.rb', line 42

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

#mtimeObject



50
51
52
53
54
# File 'lib/sprockets/lib/sprockets/source_file.rb', line 50

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

#source_linesObject



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

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