Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Bantik committed Jul 8, 2014
0 parents commit 91f4f8e
Show file tree
Hide file tree
Showing 9 changed files with 192 additions and 0 deletions.
22 changes: 22 additions & 0 deletions .gitignore
@@ -0,0 +1,22 @@
*.gem
*.rbc
.bundle
.config
.yardoc
Gemfile.lock
InstalledFiles
_yardoc
coverage
doc/
lib/bundler/man
pkg
rdoc
spec/reports
test/tmp
test/version_tmp
tmp
*.bundle
*.so
*.o
*.a
mkmf.log
4 changes: 4 additions & 0 deletions Gemfile
@@ -0,0 +1,4 @@
source 'https://rubygems.org'

# Specify your gem's dependencies in snuffle.gemspec
gemspec
22 changes: 22 additions & 0 deletions LICENSE.txt
@@ -0,0 +1,22 @@
Copyright (c) 2014 Bantik

MIT License

Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:

The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
29 changes: 29 additions & 0 deletions README.md
@@ -0,0 +1,29 @@
# Snuffle

TODO: Write a gem description

## Installation

Add this line to your application's Gemfile:

gem 'snuffle'

And then execute:

$ bundle

Or install it yourself as:

$ gem install snuffle

## Usage

TODO: Write usage instructions here

## Contributing

1. Fork it ( https://github.com/[my-github-username]/snuffle/fork )
2. Create your feature branch (`git checkout -b my-new-feature`)
3. Commit your changes (`git commit -am 'Add some feature'`)
4. Push to the branch (`git push origin my-new-feature`)
5. Create a new Pull Request
2 changes: 2 additions & 0 deletions Rakefile
@@ -0,0 +1,2 @@
require "bundler/gem_tasks"

5 changes: 5 additions & 0 deletions lib/snuffle.rb
@@ -0,0 +1,5 @@
require "snuffle/version"

module Snuffle
# Your code goes here...
end
76 changes: 76 additions & 0 deletions lib/snuffle/cli.rb
@@ -0,0 +1,76 @@
require 'thor'
require 'snuffle'

module Snuffle

class CLI < Thor

desc_text = "Formats are text (default, to STDOUT), html, and csv. "
desc_text << "Example: snuffle check foo/ -f html"

desc "check PATH_TO_FILE [-f FORMAT] [-t MAX_COMPLEXITY_ALLOWED]", desc_text
method_option :format, :type => :string, :default => 'text', :aliases => "-f"
method_option :threshold, :type => :numeric, :default => 0, :aliases => "-t"

def check(path="./")
file_list(path).each{ |path_to_file| parse(path_to_file) }
handle_index(summaries)
report
end

default_task :check

attr_accessor :summaries, :last_file

private

def file_list(start_file)
if File.directory?(start_file)
return Dir.glob(File.join(start_file, "**", "*")).select{|n| n =~ /\.rb$/}
else
return [start_file]
end
end

def formatter
case options['format']
when 'html'
Formatters::Html
when 'csv'
Formatters::Csv
else
Formatters::Text
end
end

def handle_index(file_summary)
return unless options['format'] == 'html'
index = Formatters::HtmlIndex.new(file_summary)
self.last_file = "#{index.output_path}/#{index.filename}"
index.export
end

def parse(path_to_file, options={})
file = ParsedFile.new(path_to_file: path_to_file)
parser = formatter.new(file)
parser.export
self.summaries ||= []
self.summaries << file.summary.merge(results_file: parser.path_to_results)
last_file = file
end

def report
unless options['format'] == "text"
puts "Results written to:"
puts last_file.present? && "#{last_file}" || results_files.join("\r\n")
end
report_complexity
end

def results_files
summaries.map{|s| s[:results_file]}
end

end

end
3 changes: 3 additions & 0 deletions lib/snuffle/version.rb
@@ -0,0 +1,3 @@
module Snuffle
VERSION = "0.0.1"
end
29 changes: 29 additions & 0 deletions snuffle.gemspec
@@ -0,0 +1,29 @@
# coding: utf-8
lib = File.expand_path('../lib', __FILE__)
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
require 'snuffle/version'

Gem::Specification.new do |spec|
spec.name = "snuffle"
spec.version = Snuffle::VERSION
spec.authors = ["Coraline Ada Ehmke", "Kerri Miller"]
spec.email = ["coraline@idolhands.com"]
spec.summary = %q{Snuffle detects latent objects in your Ruby code.}
spec.description = %q{Snuffle detects latent objects in your Ruby code.}
spec.homepage = ""
spec.license = "MIT"

spec.files = `git ls-files -z`.split("\x0")
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
spec.require_paths = ["lib"]

spec.add_dependency "parser"
spec.add_dependency "thor"

spec.add_development_dependency "bundler", "~> 1.6"
spec.add_development_dependency "rake"
spec.add_development_dependency "rspec"
spec.add_development_dependency "simplecov"

end

0 comments on commit 91f4f8e

Please sign in to comment.