Permalink
Browse files

Initial spike

  • Loading branch information...
0 parents commit 220c65c5049f0012a2fe31a2058ddf9d1d5f0491 @iain committed May 1, 2011
@@ -0,0 +1,4 @@
+*.gem
+.bundle
+Gemfile.lock
+pkg/*
1 .rvmrc
@@ -0,0 +1 @@
+rvm 1.9.2@pillory
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+# Specify your gem's dependencies in pillory.gemspec
+gemspec
@@ -0,0 +1,2 @@
+require 'bundler'
+Bundler::GemHelper.install_tasks
@@ -0,0 +1,8 @@
+#!/usr/bin/env ruby
+
+$LOAD_PATH.unshift(File.expand_path('../../lib', __FILE__))
+
+require "pillory"
+require "pillory/command"
+
+Pillory.run Pillory::Command.new(ARGV).parsed_options
@@ -0,0 +1,20 @@
+require 'pillory/runner'
+require 'pillory/configuration'
+require 'pillory/notifier'
+
+module Pillory
+
+ def self.run(options)
+ output = Runner.output(options, configuration)
+ Notifier.notify(output, options)
+ end
+
+ def self.configure(&block)
+ Configuration.configure(&block)
+ end
+
+ def self.configuration
+ Configuration.instance
+ end
+
+end
@@ -0,0 +1,46 @@
+require 'pillory/collectors'
+
+module Pillory
+
+ class Collector
+
+ def self.output(*args)
+ collector = new(*args)
+ collector.run
+ collector.output
+ end
+
+ attr_reader :name, :args
+
+ def initialize(name, *args)
+ @name, @args = name.to_s, args
+ end
+
+ def run
+ collector.run!
+ end
+
+ def output
+ { name => collector.output }
+ end
+
+ def collector
+ @collector ||= Collectors.get(class_name, name).new(*args)
+ end
+
+ def class_name
+ @camelized ||= camelize(name)
+ end
+
+ # Ripped from ActiveSupport
+ def camelize(lower_case_and_underscored_word, first_letter_in_uppercase = true)
+ if first_letter_in_uppercase
+ lower_case_and_underscored_word.to_s.gsub(/\/(.?)/) { "::#{$1.upcase}" }.gsub(/(?:^|_)(.)/) { $1.upcase }
+ else
+ lower_case_and_underscored_word.to_s[0].chr.downcase + camelize(lower_case_and_underscored_word)[1..-1]
+ end
+ end
+
+ end
+
+end
@@ -0,0 +1,26 @@
+module Pillory
+
+ module Collectors
+
+ def self.get(class_name, name)
+ if const_defined?(class_name)
+ const_get(class_name)
+ else
+ require collectors[name]
+ const_get(class_name)
+ end
+ end
+
+ def self.collect(name, options = {})
+ collector = collector(name).new(options)
+ collector.run!
+ collector.output
+ end
+
+ def self.collectors
+ @collectors ||= Hash.new { |hash, key| hash[key] = "pillory/collectors/#{key}" }
+ end
+
+ end
+
+end
@@ -0,0 +1,74 @@
+require 'ansi/code'
+require 'open3'
+
+module Pillory
+
+ module Collectors
+
+ class Base
+ include ANSI::Code
+
+ attr_accessor :stdout, :stderr, :exit_status, :main
+
+ attr_reader :patterns, :path
+
+ def initialize(options = {})
+ @patterns = options[:patterns]
+ @path = options[:path]
+ end
+
+ def run
+ raise NotImplementedError
+ end
+
+ def run!
+ puts magenta { "Running #{self.class.to_s}" }
+ Dir.chdir path do
+ @main = run
+ end
+ end
+
+ def files
+ Array(patterns).map { |pattern| Dir.glob(pattern) }.flatten
+ end
+
+ def output
+ { 'main' => main, 'stdout' => stdout, 'stderr' => stderr, 'exit_status' => exit_status }
+ end
+
+ def stdout
+ @stdout ||= ""
+ end
+
+ def stderr
+ @stderr ||= ""
+ end
+
+ def capture(*command)
+ Open3.popen3 *command do |stdin, stdout, stderr, wait_thr|
+ stdout.each_char do |char|
+ print char if show_stdout?
+ self.stdout << char
+ end
+ stderr.each_char do |char|
+ print char if show_stderr?
+ self.stderr << char
+ end
+ self.exit_status = wait_thr.value.to_i
+ end
+ nil
+ end
+
+ def show_stdout?
+ false
+ end
+
+ def show_stderr?
+ false
+ end
+
+ end
+
+ end
+
+end
@@ -0,0 +1,22 @@
+require 'pillory/collectors/base'
+
+module Pillory
+
+ module Collectors
+
+ class Changes < Base
+
+ def run
+ changes = {}
+ `git ls-files`.each_line do |file|
+ cmd = "git log --oneline --full-history --follow --no-merges #{file.strip} | wc -l"
+ changes[file.strip] = `#{cmd}`.to_i
+ end
+ changes
+ end
+
+ end
+
+ end
+
+end
@@ -0,0 +1,58 @@
+require 'pillory/collectors/file_based'
+
+module Pillory
+
+ module Collectors
+
+ class Cucumber < FileBased
+
+ attr_reader :bin, :features
+
+ def initialize(options = {})
+ super
+ @bin = options[:bin] || "cucumber"
+ @format = options[:format] || "progress"
+ @color = options[:color] || true
+ @profile = options[:profile] || "default"
+ @features = options[:features] || "features"
+ end
+
+ private
+
+ def command(file)
+ [ {"PILLORY" => lib_dir }, "#{bin} --format Pillory::CucumberFormatter --out #{file.path} #{format} #{profile} #{color} #{features}" ]
+ end
+
+ def format
+ "--format #{@format}"
+ end
+
+ def profile
+ "--profile #{@profile}"
+ end
+
+ def color
+ @color ? "--color" : "--no-color"
+ end
+
+ def lib_dir
+ File.expand_path('../../cucumber_formatter', __FILE__)
+ end
+
+ def tempfile_name
+ %w(cucumber .yml)
+ end
+
+ def show_stdout?
+ true
+ end
+
+ def show_stderr?
+ true
+ end
+
+ end
+
+ end
+
+end
@@ -0,0 +1,41 @@
+require 'pillory/collectors/base'
+require 'tempfile'
+
+module Pillory
+
+ module Collectors
+
+ class FileBased < Base
+
+ def run
+ with_tempfile do |file|
+ capture(*Array(command(file)))
+ end
+ end
+
+ private
+
+ def command(file)
+ raise NotImplementedError
+ end
+
+ def with_tempfile
+ file = Tempfile.new(tempfile_name)
+ begin
+ yield(file)
+ result = file.read
+ ensure
+ file.close
+ end
+ result
+ end
+
+ def tempfile_name
+ raise NotImplementedError
+ end
+
+ end
+
+ end
+
+end
@@ -0,0 +1,17 @@
+require 'pillory/collectors/base'
+
+module Pillory
+
+ module Collectors
+
+ class Flay < Base
+
+ def run
+ capture "flay #{files.join(' ')}"
+ end
+
+ end
+
+ end
+
+end
@@ -0,0 +1,15 @@
+module Pillory
+
+ module Collectors
+
+ class Flog < Base
+
+ def run
+ capture "flog --all --group --continue #{files.join(' ')}"
+ end
+
+ end
+
+ end
+
+end
@@ -0,0 +1,17 @@
+require 'pillory/collectors/base'
+
+module Pillory
+
+ module Collectors
+
+ class Git < Base
+
+ def run
+ capture "git rev-parse HEAD"
+ end
+
+ end
+
+ end
+
+end
@@ -0,0 +1,17 @@
+require 'pillory/collectors/base'
+
+module Pillory
+
+ module Collectors
+
+ class RailsBestPractices < Base
+
+ def run
+ capture "rails_best_practices --without-color"
+ end
+
+ end
+
+ end
+
+end
Oops, something went wrong.

0 comments on commit 220c65c

Please sign in to comment.