Module: Odor

Defined in:
lib/odor.rb,
lib/odor/version.rb

Constant Summary collapse

VERSION =
"0.0.1"

Class Method Summary collapse

Class Method Details

.check_file(file_name) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
# File 'lib/odor.rb', line 12

def self.check_file(file_name)
  issues(file_name).each do |hint|
    line_changes(file_name).each do |num|
      if hint.include?(num.to_s)
        puts hint
        @smell_detected = true
        break
      end
    end
  end
end

.file_diff(file_name) ⇒ Object



28
29
30
31
32
33
34
35
# File 'lib/odor.rb', line 28

def self.file_diff(file_name)
  changes = %x[git diff -U0 #{file_name}].split("\n")
  changes.shift(4)

  line_changes = []
  changes.each { |c| line_changes << c if !c.nil? && c.start_with?('@') }
  return line_changes
end

.issues(file_name) ⇒ Object



24
25
26
# File 'lib/odor.rb', line 24

def self.issues(file_name)
  %x[rails_best_practices -f text #{file_name} --silent --without-color].split("\n")
end

.line_changes(file_name) ⇒ Object

TODO split into mutiple methods



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/odor.rb', line 38

def self.line_changes(file_name)
  lines = []

  file_diff(file_name).each do |s|
    s = s.split
    s.shift(2)

    li = s.first[1, 12].split(',')
    li.last.to_i.times do |i|
      lines << li.first.to_i + i
    end
  end

  return lines
end

.run(*args) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/odor.rb', line 4

def self.run(*args)
  %x[git status -s].split("\n").each do |line|
    check_file(line.split.last)
  end

  puts "No smells found" unless @smell_detected
end