Sha256: ce1389182853ac812956f8afebb379cafca481dc3d86307eb07ab11171b500a4

Contents?: true

Size: 718 Bytes

Versions: 7

Compression:

Stored size: 718 Bytes

Contents

require 'digest/sha1'

module OverridesTracker
  class Util
    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

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

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

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
overrides_tracker-0.3.1 lib/overrides_tracker/util.rb
overrides_tracker-0.3.0 lib/overrides_tracker/util.rb
overrides_tracker-0.2.3 lib/overrides_tracker/util.rb
overrides_tracker-0.2.1 lib/overrides_tracker/util.rb
overrides_tracker-0.2.0 lib/overrides_tracker/util.rb
overrides_tracker-0.1.13 lib/overrides_tracker/util.rb
overrides_tracker-0.1.12 lib/overrides_tracker/util.rb