Module: DiffInfluence::Core
- Defined in:
- lib/diff_influence/core.rb,
lib/diff_influence/core_1x.rb
Defined Under Namespace
Classes: EMeth
Class Method Summary collapse
- .debug_log(msg) ⇒ Object
- .exec ⇒ Object
- .file_paths ⇒ Object
- .files ⇒ Object
- .git_diff(file_path) ⇒ Object
- .git_status ⇒ Object
- .influence_search(file_path) ⇒ Object
- .native_grep(keyword = "") ⇒ Object
- .os_grep(keyword = "") ⇒ Object
- .search_methods(file_path) ⇒ Object
Class Method Details
.debug_log(msg) ⇒ Object
13 14 15 |
# File 'lib/diff_influence/core.rb', line 13 def self.debug_log(msg) puts "[DEBUG] #{msg}" if DiffInfluence::Config.debug end |
.exec ⇒ Object
107 108 109 110 111 112 |
# File 'lib/diff_influence/core.rb', line 107 def self.exec self.file_paths.each do |fp| self.influence_search fp end exit 0 end |
.file_paths ⇒ Object
21 22 23 |
# File 'lib/diff_influence/core.rb', line 21 def self.file_paths @@files ||= self.git_status.lines.map{|line| line.split.last} end |
.files ⇒ Object
85 86 87 |
# File 'lib/diff_influence/core.rb', line 85 def self.files @@files ||= Dir.glob(DiffInfluence::Config.search_paths.map{|d| "#{d}/**/**.{#{DiffInfluence::Config.search_extensions.join(",")}}"}) end |
.git_diff(file_path) ⇒ Object
25 26 27 |
# File 'lib/diff_influence/core.rb', line 25 def self.git_diff(file_path) `git --no-pager diff --no-ext-diff -U1000000 #{file_path}` end |
.git_status ⇒ Object
17 18 19 |
# File 'lib/diff_influence/core.rb', line 17 def self.git_status `git status | grep modified` end |
.influence_search(file_path) ⇒ Object
89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/diff_influence/core.rb', line 89 def self.influence_search(file_path) searched_methods = [] self.search_methods(file_path).each do |method| if method.name.nil? || method.name.empty? || searched_methods.include?(method.name) next else searched_methods.push method.name end puts "### Searching method[#{method.name}] (from #{file_path}:#{method.index})" if DiffInfluence::Config.os_grep self.os_grep method.name else self.native_grep method.name end puts end end |
.native_grep(keyword = "") ⇒ Object
75 76 77 78 79 80 81 82 83 |
# File 'lib/diff_influence/core.rb', line 75 def self.native_grep(keyword="") self.files.each do |file| File.readlines(file).each_with_index do |line, idx| if line =~ /(\.|@)#{keyword}(\s|\()/ puts "#{file}:#{idx+1} #{line}" end end end end |
.os_grep(keyword = "") ⇒ Object
69 70 71 72 73 |
# File 'lib/diff_influence/core.rb', line 69 def self.os_grep(keyword="") DiffInfluence::Config.search_paths.each do |pd| puts `grep -r -E '(\\.|@)#{keyword}(\\s|\\()' #{pd}` end end |
.search_methods(file_path) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/diff_influence/core.rb', line 29 def self.search_methods(file_path) methods = [] last_method = nil cnt = 0 lines = self.git_diff(file_path).lines lines.each_with_index do |line, idx| if line =~ /(\s|\t|;)def/ last_method = lines[idx].split("def ").last.chomp.gsub("self\.","") self.debug_log "Method line => #{last_method}" end case line when /\A\+\+\+/, /\A---/, /\Adiff/, /\Aindex/, /\A@@/ self.debug_log "Ignore line => #{line}" next when /\A\+/, /\A\-/ cnt += 1 if line =~ /\A\+/ self.debug_log "idx:#{idx}, cnt:#{cnt}, #{line}" t = case line when /\A-(\s|\t)*def/ "remove" when /\A\+(\s|\t)*def/ "add" else "effect" end methods.push EMeth.new( name: last_method, type: t, raw: line, index: cnt ) else cnt += 1 end end self.debug_log methods.to_s methods end |