odor 0.0.1

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.
@@ -0,0 +1,5 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
5
+ *.swp
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in odor.gemspec
4
+ gemspec
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
@@ -0,0 +1,13 @@
1
+ #!/usr/bin/env ruby
2
+ require 'odor'
3
+
4
+ trap("INT") do
5
+ puts("\n ! Command cancelled.")
6
+ exit
7
+ end
8
+
9
+ # resolve bin path, ignoring symlinks
10
+ require "pathname"
11
+ bin_file = Pathname.new(__FILE__).realpath
12
+
13
+ Odor.run(*ARGV)
@@ -0,0 +1,53 @@
1
+ require "odor/version"
2
+
3
+ module Odor
4
+ def self.run(*args)
5
+ %x[git status -s].split("\n").each do |line|
6
+ check_file(line.split.last)
7
+ end
8
+
9
+ puts "No smells found" unless @smell_detected
10
+ end
11
+
12
+ def self.check_file(file_name)
13
+ issues(file_name).each do |hint|
14
+ line_changes(file_name).each do |num|
15
+ if hint.include?(num.to_s)
16
+ puts hint
17
+ @smell_detected = true
18
+ break
19
+ end
20
+ end
21
+ end
22
+ end
23
+
24
+ def self.issues(file_name)
25
+ %x[rails_best_practices -f text #{file_name} --silent --without-color].split("\n")
26
+ end
27
+
28
+ def self.file_diff(file_name)
29
+ changes = %x[git diff -U0 #{file_name}].split("\n")
30
+ changes.shift(4)
31
+
32
+ line_changes = []
33
+ changes.each { |c| line_changes << c if !c.nil? && c.start_with?('@') }
34
+ return line_changes
35
+ end
36
+
37
+ # TODO split into mutiple methods
38
+ def self.line_changes(file_name)
39
+ lines = []
40
+
41
+ file_diff(file_name).each do |s|
42
+ s = s.split
43
+ s.shift(2)
44
+
45
+ li = s.first[1, 12].split(',')
46
+ li.last.to_i.times do |i|
47
+ lines << li.first.to_i + i
48
+ end
49
+ end
50
+
51
+ return lines
52
+ end
53
+ end
@@ -0,0 +1,3 @@
1
+ module Odor
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "odor/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "odor"
7
+ s.version = Odor::VERSION
8
+ s.authors = ["Dave Elliott"]
9
+ s.email = ["ddazza@gmail.com"]
10
+ s.homepage = "https://github.com/davidelliott/"
11
+ s.summary = %q{Lists smells in code changes}
12
+ s.description = %q{Outputs a list of bits of code which should be reviewed as they could potentialy lead to later problem from current code changes}
13
+
14
+ s.rubyforge_project = "odor"
15
+
16
+ s.files = `git ls-files`.split("\n")
17
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
19
+ s.require_paths = ["lib"]
20
+
21
+ # s.add_development_dependency "rspec", "~>2.8.0"
22
+ s.add_runtime_dependency "rails_best_practices", "~>1.9.0"
23
+ end
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'bundler/setup'
3
+ require 'odor'
4
+
5
+ Rspec.configure do |config|
6
+ end
metadata ADDED
@@ -0,0 +1,66 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: odor
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Dave Elliott
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-03-07 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails_best_practices
16
+ requirement: &18700240 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: 1.9.0
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: *18700240
25
+ description: Outputs a list of bits of code which should be reviewed as they could
26
+ potentialy lead to later problem from current code changes
27
+ email:
28
+ - ddazza@gmail.com
29
+ executables:
30
+ - odor
31
+ extensions: []
32
+ extra_rdoc_files: []
33
+ files:
34
+ - .gitignore
35
+ - Gemfile
36
+ - Rakefile
37
+ - bin/odor
38
+ - lib/odor.rb
39
+ - lib/odor/version.rb
40
+ - odor.gemspec
41
+ - spec/spec_helper.rb
42
+ homepage: https://github.com/davidelliott/
43
+ licenses: []
44
+ post_install_message:
45
+ rdoc_options: []
46
+ require_paths:
47
+ - lib
48
+ required_ruby_version: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
54
+ required_rubygems_version: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ! '>='
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubyforge_project: odor
62
+ rubygems_version: 1.8.11
63
+ signing_key:
64
+ specification_version: 3
65
+ summary: Lists smells in code changes
66
+ test_files: []