diff_influence 0.1.0 → 0.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b4d55ee171f05f93366111120e33f56a834b3e28
4
- data.tar.gz: 9a804afacfabf149ddca92860e8f6a12f036f7de
3
+ metadata.gz: 5eba67ab25882f71a3576b52acbc8b381e0f7280
4
+ data.tar.gz: dae12e5394b4cf018482cb2bc718521526a11819
5
5
  SHA512:
6
- metadata.gz: ee1fb841a6de0f192a6859070f098c991be007cff67bf59d58a476b7708654523941fcf094dbef3804e44b9ec5beefd8042f80eb9196827119486d41934a5364
7
- data.tar.gz: 2bea09cf03472c98533206dec2c7f96ba8821e1d5caf31cd9d05e250994ab88e191fb7745a79d824b6934672137249b887baf9ca6f707ca3bb300dc0bf56554d
6
+ metadata.gz: dc91ec4e06ec21e54dafe2674e456dc8f35fa782003c6ab7f6452af6f2a41d40126eca393580ded039021b55d0d09df46e6d37c61a32ecdbc9cd5acb57917769
7
+ data.tar.gz: 46487ffedc69981a28b4f6b35eedd5e652bd55e16142ec308705574c4dd632692fac811a6839c2c924f5f39c4d59ab9551c24d8543e59296bdfe505c541b088b
data/.travis.yml CHANGED
@@ -1,5 +1,23 @@
1
+ branches:
2
+ only:
3
+ - master
4
+ - release
5
+ - develop
1
6
  sudo: false
2
7
  language: ruby
3
8
  rvm:
4
- - 2.3.1
5
- before_install: gem install bundler -v 1.12.3
9
+ - 1.8.7
10
+ - 1.9.3
11
+ - 2.0.0
12
+ - 2.1.0
13
+ - 2.2.0
14
+ - 2.3.0
15
+ - 2.4.0
16
+ before_install: gem install bundler
17
+ cache:
18
+ directories:
19
+ - vendor/bundle
20
+ install: bundle install --path=vendor/bundle
21
+ script:
22
+ - ruby --version
23
+ - bundle exec rake spec
data/README.md CHANGED
@@ -1,10 +1,14 @@
1
1
  # Diff Influence
2
2
 
3
+ [![Build Status](https://travis-ci.org/metalels/diff_influence.svg?branch=master)](https://travis-ci.org/metalels/diff_influence)
4
+ [![Gem Version](https://badge.fury.io/rb/diff_influence.svg)](https://badge.fury.io/rb/diff_influence)
5
+
3
6
  Search influence of git diff.
4
7
 
5
8
  ## Requirement ##
6
9
 
7
- * git ( use git diff command )
10
+ * Git ( support only git diff command. )
11
+ * Ruby ( support only Ruby 1.8.7 or later. )
8
12
 
9
13
  ## Installation ##
10
14
 
@@ -24,7 +28,7 @@ Or install it yourself as:
24
28
 
25
29
  ## Usage ##
26
30
 
27
- ``
31
+ ```
28
32
  ==============================================================================
29
33
  []: optional
30
34
 
@@ -32,7 +36,6 @@ Usage: diff-influence [Options]
32
36
 
33
37
  Options:
34
38
 
35
- -p --commit commit_id,commit_id git commit id(s) uses diff (default: none)
36
39
  -p --path path,path,... path(s) to search file (default: app,lib)
37
40
  -e --ext extension,extension,... extension(s) to search file (default: rb)
38
41
  -g --grep use grep command with OS
@@ -40,9 +43,10 @@ Usage: diff-influence [Options]
40
43
 
41
44
  Feature Options:
42
45
 
46
+ -c --commit commit_id,commit_id git commit id(s) uses diff (default: none)
43
47
  -o --output path to output file (default: STDOUT)
44
48
  ==============================================================================
45
- ``
49
+ ```
46
50
 
47
51
  ## Authors ##
48
52
 
data/bin/console CHANGED
@@ -6,9 +6,10 @@ require "diff_influence"
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
8
8
 
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- require "pry"
11
- Pry.start
12
-
13
- #require "irb"
14
- #IRB.start
9
+ if RUBY_VERSION < "1.9.0"
10
+ require "irb"
11
+ IRB.start
12
+ else
13
+ require "pry"
14
+ Pry.start
15
+ end
@@ -0,0 +1,6 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ src = File.read "lib/diff_influence/core.rb"
4
+ src = src.gsub(/(\w+):\s/, ':\1 => ')
5
+ src = src.gsub(/\.lines/, '.lines.to_a')
6
+ File.write "lib/diff_influence/core_1x.rb", src
@@ -9,7 +9,6 @@ Usage: diff_influence [Options]
9
9
 
10
10
  Options:
11
11
 
12
- -p --commit commit_id,commit_id git commit id(s) uses diff (default: none)
13
12
  -p --path path,path,... path(s) to search file (default: app,lib)
14
13
  -e --ext extension,extension,... extension(s) to search file (default: rb)
15
14
  -g --grep use grep command with OS
@@ -17,6 +16,7 @@ Usage: diff_influence [Options]
17
16
 
18
17
  Feature Options:
19
18
 
19
+ -c --commit commit_id,commit_id git commit id(s) uses diff (default: none)
20
20
  -o --output path to output file (default: STDOUT)
21
21
  ==============================================================================
22
22
  EOS
@@ -89,6 +89,7 @@ Usage: diff_influence [Options]
89
89
  self.exit_with_message 2, true
90
90
  end
91
91
  end
92
+ true
92
93
  end
93
94
  end
94
95
  end
@@ -1,6 +1,5 @@
1
1
  module DiffInfluence
2
2
  module Core
3
- PREF_DIRS=["lib", "app"]
4
3
  EMeth=Struct.new(:name, :type, :raw, :index)
5
4
  EMeth.class_eval do
6
5
  def initialize(attr={})
@@ -11,6 +10,10 @@ module DiffInfluence
11
10
  end
12
11
  end
13
12
 
13
+ def self.debug_log(msg)
14
+ puts "[DEBUG] #{msg}" if DiffInfluence::Config.debug
15
+ end
16
+
14
17
  def self.git_status
15
18
  `git status | grep modified`
16
19
  end
@@ -23,24 +26,23 @@ module DiffInfluence
23
26
  `git --no-pager diff --no-ext-diff -U1000000 #{file_path}`
24
27
  end
25
28
 
26
- def self.file(file_path)
27
- File.read(file_path).lines
28
- end
29
-
30
29
  def self.search_methods(file_path)
31
30
  methods = []
32
31
  last_method = nil
33
32
  cnt = 0
34
33
  lines = self.git_diff(file_path).lines
35
34
  lines.each_with_index do |line, idx|
36
- last_method = lines[idx].split("def ").last.chomp.gsub("self\.","") if line =~ /(\s|\t)*def/
35
+ if line =~ /(\s|\t|;)def/
36
+ last_method = lines[idx].split("def ").last.chomp.gsub("self\.","")
37
+ self.debug_log "Method line => #{last_method}"
38
+ end
37
39
  case line
38
40
  when /\A\+\+\+/, /\A---/, /\Adiff/, /\Aindex/, /\A@@/
39
- puts "Ignore line: #{line}" if DiffInfluence::Config.debug
41
+ self.debug_log "Ignore line => #{line}"
40
42
  next
41
43
  when /\A\+/, /\A\-/
42
44
  cnt += 1 if line =~ /\A\+/
43
- puts "idx:#{idx}, cnt:#{cnt}, #{line}" if DiffInfluence::Config.debug
45
+ self.debug_log "idx:#{idx}, cnt:#{cnt}, #{line}"
44
46
 
45
47
  t = case line
46
48
  when /\A-(\s|\t)*def/
@@ -60,7 +62,7 @@ module DiffInfluence
60
62
  cnt += 1
61
63
  end
62
64
  end
63
- puts methods if DiffInfluence::Config.debug
65
+ self.debug_log methods.to_s
64
66
  methods
65
67
  end
66
68
 
@@ -0,0 +1,114 @@
1
+ module DiffInfluence
2
+ module Core
3
+ EMeth=Struct.new(:name, :type, :raw, :index)
4
+ EMeth.class_eval do
5
+ def initialize(attr={})
6
+ self.name = attr[:name]
7
+ self.type = attr[:type]
8
+ self.raw = attr[:raw]
9
+ self.index = attr[:index]
10
+ end
11
+ end
12
+
13
+ def self.debug_log(msg)
14
+ puts "[DEBUG] #{msg}" if DiffInfluence::Config.debug
15
+ end
16
+
17
+ def self.git_status
18
+ `git status | grep modified`
19
+ end
20
+
21
+ def self.file_paths
22
+ @@files ||= self.git_status.lines.to_a.map{|line| line.split.last}
23
+ end
24
+
25
+ def self.git_diff(file_path)
26
+ `git --no-pager diff --no-ext-diff -U1000000 #{file_path}`
27
+ end
28
+
29
+ def self.search_methods(file_path)
30
+ methods = []
31
+ last_method = nil
32
+ cnt = 0
33
+ lines = self.git_diff(file_path).lines.to_a
34
+ lines.each_with_index do |line, idx|
35
+ if line =~ /(\s|\t|;)def/
36
+ last_method = lines[idx].split("def ").last.chomp.gsub("self\.","")
37
+ self.debug_log "Method line => #{last_method}"
38
+ end
39
+ case line
40
+ when /\A\+\+\+/, /\A---/, /\Adiff/, /\Aindex/, /\A@@/
41
+ self.debug_log "Ignore line => #{line}"
42
+ next
43
+ when /\A\+/, /\A\-/
44
+ cnt += 1 if line =~ /\A\+/
45
+ self.debug_log "idx:#{idx}, cnt:#{cnt}, #{line}"
46
+
47
+ t = case line
48
+ when /\A-(\s|\t)*def/
49
+ "remove"
50
+ when /\A\+(\s|\t)*def/
51
+ "add"
52
+ else
53
+ "effect"
54
+ end
55
+ methods.push EMeth.new(
56
+ :name => last_method,
57
+ :type => t,
58
+ :raw => line,
59
+ :index => cnt
60
+ )
61
+ else
62
+ cnt += 1
63
+ end
64
+ end
65
+ self.debug_log methods.to_s
66
+ methods
67
+ end
68
+
69
+ def self.os_grep(keyword="")
70
+ DiffInfluence::Config.search_paths.each do |pd|
71
+ puts `grep -r -E '(\\.|@)#{keyword}(\\s|\\()' #{pd}`
72
+ end
73
+ end
74
+
75
+ def self.native_grep(keyword="")
76
+ self.files.each do |file|
77
+ File.readlines(file).each_with_index do |line, idx|
78
+ if line =~ /(\.|@)#{keyword}(\s|\()/
79
+ puts "#{file}:#{idx+1} #{line}"
80
+ end
81
+ end
82
+ end
83
+ end
84
+
85
+ def self.files
86
+ @@files ||= Dir.glob(DiffInfluence::Config.search_paths.map{|d| "#{d}/**/**.{#{DiffInfluence::Config.search_extensions.join(",")}}"})
87
+ end
88
+
89
+ def self.influence_search(file_path)
90
+ searched_methods = []
91
+ self.search_methods(file_path).each do |method|
92
+ if method.name.nil? || method.name.empty? || searched_methods.include?(method.name)
93
+ next
94
+ else
95
+ searched_methods.push method.name
96
+ end
97
+ puts "### Searching method[#{method.name}] (from #{file_path}:#{method.index})"
98
+ if DiffInfluence::Config.os_grep
99
+ self.os_grep method.name
100
+ else
101
+ self.native_grep method.name
102
+ end
103
+ puts
104
+ end
105
+ end
106
+
107
+ def self.exec
108
+ self.file_paths.each do |fp|
109
+ self.influence_search fp
110
+ end
111
+ exit 0
112
+ end
113
+ end
114
+ end
@@ -1,3 +1,3 @@
1
1
  module DiffInfluence
2
- VERSION = "0.1.0"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,3 +1,8 @@
1
1
  require "diff_influence/version"
2
- require "diff_influence/core"
3
2
  require "diff_influence/config"
3
+
4
+ if RUBY_VERSION < "2.0.0"
5
+ require "diff_influence/core_1x"
6
+ else
7
+ require "diff_influence/core"
8
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: diff_influence
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - metalels
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-02-16 00:00:00.000000000 Z
11
+ date: 2017-02-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -82,12 +82,14 @@ files:
82
82
  - README.md
83
83
  - Rakefile
84
84
  - bin/console
85
+ - bin/convert_for_under_200.rb
85
86
  - bin/setup
86
87
  - diff_influence.gemspec
87
88
  - exe/diff-influence
88
89
  - lib/diff_influence.rb
89
90
  - lib/diff_influence/config.rb
90
91
  - lib/diff_influence/core.rb
92
+ - lib/diff_influence/core_1x.rb
91
93
  - lib/diff_influence/version.rb
92
94
  homepage: https://github.com/metalels/diff_influence
93
95
  licenses: []
@@ -108,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
108
110
  version: '0'
109
111
  requirements: []
110
112
  rubyforge_project:
111
- rubygems_version: 2.6.8
113
+ rubygems_version: 2.5.1
112
114
  signing_key:
113
115
  specification_version: 4
114
116
  summary: search diff influence.