Class: MethodLog::SourceFile

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ SourceFile

Returns a new instance of SourceFile.



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

def initialize(options = {})
  @path = options[:path]
  @source = options[:source]
  @repository = options[:repository]
  @sha = options[:sha]
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

#shaObject (readonly)

Returns the value of attribute sha.



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

def sha
  @sha
end

Instance Method Details

#==(other) ⇒ Object



17
18
19
# File 'lib/method_log/source_file.rb', line 17

def ==(other)
  (path == other.path) && (source == other.source)
end

#hashObject



21
22
23
# File 'lib/method_log/source_file.rb', line 21

def hash
  @sha || [path, source].hash
end

#snippet(range) ⇒ Object



25
26
27
# File 'lib/method_log/source_file.rb', line 25

def snippet(range)
  lines = source.split($/)[range].join($/)
end

#sourceObject



13
14
15
# File 'lib/method_log/source_file.rb', line 13

def source
  @source ||= @repository.lookup(@sha).text
end