Class: OverridesTracker::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/overrides_tracker/util.rb

Class Method Summary collapse

Class Method Details

.method_hash(method) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/overrides_tracker/util.rb', line 5

def self.method_hash(method)
  {
    sha: method_sha(method),
    location: method.source_location,
    body: outdented_method_body(method),
    is_part_of_app: method.source_location[0].include?(Dir.pwd)
  }
rescue StandardError
  {
    sha: nil,
    location: nil,
    body: nil,
    is_part_of_app: false
  }
end

.method_sha(method) ⇒ Object



27
28
29
# File 'lib/overrides_tracker/util.rb', line 27

def self.method_sha(method)
  Digest::SHA1.hexdigest(method.source.gsub(/\s+/, ' '))
end

.outdented_method_body(method) ⇒ Object



21
22
23
24
25
# File 'lib/overrides_tracker/util.rb', line 21

def self.outdented_method_body(method)
  body = method.source
  indent = body.match(/^\W+/).to_s
  body.lines.map { |l| l.sub(indent, '') }.join
end