├── .gitignore ├── lib └── guard │ ├── rails_best_practices │ ├── templates │ │ └── Guardfile │ ├── version.rb │ └── notifier.rb │ └── rails_best_practices.rb ├── Rakefile ├── spec ├── support │ └── platform_helper.rb ├── spec_helper.rb └── guard │ └── rails_best_practices │ └── notifier_spec.rb ├── Gemfile ├── guard-rails_best_practices.gemspec └── README.md /.gitignore: -------------------------------------------------------------------------------- 1 | *.gem 2 | .bundle 3 | Gemfile.lock 4 | pkg/* 5 | -------------------------------------------------------------------------------- /lib/guard/rails_best_practices/templates/Guardfile: -------------------------------------------------------------------------------- 1 | guard 'rails_best_practices' do 2 | watch(%r{^app/(.+)\.rb$}) 3 | end 4 | -------------------------------------------------------------------------------- /lib/guard/rails_best_practices/version.rb: -------------------------------------------------------------------------------- 1 | module Guard 2 | module RailsBestPracticesVersion 3 | VERSION = "0.1.3" 4 | end 5 | end 6 | -------------------------------------------------------------------------------- /Rakefile: -------------------------------------------------------------------------------- 1 | require "bundler/gem_tasks" 2 | require 'rspec/core/rake_task' 3 | 4 | task :default => :build 5 | 6 | RSpec::Core::RakeTask.new('spec') 7 | -------------------------------------------------------------------------------- /spec/support/platform_helper.rb: -------------------------------------------------------------------------------- 1 | def mac? 2 | Config::CONFIG['target_os'] =~ /darwin/i 3 | end 4 | 5 | def linux? 6 | Config::CONFIG['target_os'] =~ /linux/i 7 | end -------------------------------------------------------------------------------- /Gemfile: -------------------------------------------------------------------------------- 1 | source "http://rubygems.org" 2 | 3 | gem 'guard', '>= 0.9' 4 | gem 'rails_best_practices', '>= 1.1.0' 5 | 6 | # Specify your gem's dependencies in guard-rails_best_practices.gemspec 7 | gemspec 8 | -------------------------------------------------------------------------------- /spec/spec_helper.rb: -------------------------------------------------------------------------------- 1 | require 'rubygems' 2 | require 'guard/rails_best_practices' 3 | require 'rspec' 4 | 5 | RSpec.configure do |config| 6 | config.color_enabled = true 7 | config.formatter = 'documentation' 8 | end -------------------------------------------------------------------------------- /spec/guard/rails_best_practices/notifier_spec.rb: -------------------------------------------------------------------------------- 1 | require 'spec_helper' 2 | 3 | describe Guard::RailsBestPractices::Notifier do 4 | subject { Guard::RailsBestPractices::Notifier } 5 | 6 | it 'should call Guard::Notifier' do 7 | ::Guard::Notifier.should_receive(:notify).with( 8 | "Rails Best Practices checklist has been run successfully\nin 5.50 seconds.", 9 | :title => 'Rails Best Practices checklist complete', 10 | :image => :success 11 | ) 12 | subject.notify(true, 5.5) 13 | end 14 | end -------------------------------------------------------------------------------- /lib/guard/rails_best_practices/notifier.rb: -------------------------------------------------------------------------------- 1 | # encoding: utf-8 2 | # 3 | # Borrowed from guard-annotate 4 | module Guard 5 | class RailsBestPractices 6 | class Notifier 7 | 8 | class << self 9 | def guard_message( result, duration ) 10 | case result 11 | when true 12 | "Rails Best Practices checklist has been run successfully\nin %0.2f seconds." % [duration] 13 | else 14 | "Rails Best Practices checklist run has failed!\nPlease check manually." 15 | end 16 | end 17 | 18 | def guard_image( result ) 19 | result ? :success : :failed 20 | end 21 | 22 | def notify( result, duration ) 23 | message = guard_message( result, duration ) 24 | image = guard_image( result ) 25 | 26 | ::Guard::Notifier.notify( message, :title => 'Rails Best Practices checklist complete', :image => image ) 27 | end 28 | end 29 | 30 | end 31 | end 32 | end 33 | -------------------------------------------------------------------------------- /guard-rails_best_practices.gemspec: -------------------------------------------------------------------------------- 1 | # -*- encoding: utf-8 -*- 2 | $:.push File.expand_path("../lib", __FILE__) 3 | require "guard/rails_best_practices/version" 4 | 5 | Gem::Specification.new do |s| 6 | s.name = "guard-rails_best_practices" 7 | s.version = Guard::RailsBestPracticesVersion::VERSION 8 | s.authors = ["Logan Koester"] 9 | s.email = ["lkoester@agoragames.com"] 10 | s.homepage = "http://rubygems.org/gems/guard-rails_best_practices" 11 | s.summary = %q{Guard for rails_best_practices, a code metric tool to check the quality of rails code.} 12 | s.description = %q{Guard for rails_best_practices, a code metric tool to check the quality of rails code.} 13 | 14 | s.rubyforge_project = "guard-rails_best_practices" 15 | 16 | s.files = Dir.glob('{lib}/**/*') + %w[README.md] 17 | s.require_paths = ["lib"] 18 | 19 | s.add_dependency "guard", ">= 2.10.1" 20 | s.add_dependency "rails_best_practices", ">= 1.1.0" 21 | 22 | s.add_development_dependency 'rspec', '~> 2.5' 23 | end 24 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Guard - Rails Best Practices 2 | 3 | BDD your [Rails Best Practices](http://rails-bestpractices.com/) checklist alongside your specs 4 | with [Guard](https://github.com/guard/guard). 5 | 6 | By adding your own checklists, this can be a great way to enforce those code style documents that everyone on your 7 | team has forgotten! 8 | 9 | ## Install 10 | 11 | In your Rails 3.0+ application, add the `guard`, `rails_best_practices`, and `guard-rails_best_practices` gems to your `Gemfile`: 12 | 13 | group :development do 14 | gem 'rails_best_practices' 15 | gem 'guard' 16 | gem 'guard-rails_best_practices' 17 | end 18 | 19 | Add guard definitions to your `Guardfile` by running: 20 | 21 | guard init rails_best_practices 22 | 23 | Guard will now inform you of Rails Best Practices warnings. 24 | 25 | ## Options 26 | 27 | These options are available (with the following defaults): 28 | 29 | options[:vendor] = true # Include vendor/ 30 | options[:spec] = true # Include spec/ 31 | options[:test] = true # Include test/ 32 | options[:features] = true # Include features/ 33 | options[:exclude] = '' # Exclude [PATTERN] 34 | options[:run_at_start] = true # Run checklist when guard starts 35 | 36 | See https://github.com/railsbp/rails_best_practices for details. 37 | 38 | It is recommended that you run `rails_best_practices -g` to generate a `rails_best_practices.yml` file for your application, 39 | so you can tune the checklists to your own unique tastes. 40 | 41 | You can also extend `rails_best_practices` by [writing your own checklists](https://github.com/railsbp/rails_best_practices/wiki/How-to-write-your-own-check-list) . 42 | 43 | ## Authors 44 | 45 | [Logan Koester](http://github.com/logankoester) 46 | -------------------------------------------------------------------------------- /lib/guard/rails_best_practices.rb: -------------------------------------------------------------------------------- 1 | require 'guard' 2 | 3 | require File.join(File.dirname(__FILE__), "rails_best_practices/version") 4 | 5 | module Guard 6 | class RailsBestPractices < Guard::Plugin 7 | autoload :Notifier, 'guard/rails_best_practices/notifier' 8 | 9 | def initialize(options = {}) 10 | rbp_opts = { :vendor => true, 11 | :spec => true, 12 | :test => true, 13 | :features => true 14 | } 15 | guard_opts = { :run_at_start => true } 16 | options = rbp_opts.merge options 17 | options = guard_opts.merge options 18 | 19 | super 20 | end 21 | 22 | def start 23 | run_bestpractices if options[:run_at_start] 24 | end 25 | 26 | def stop 27 | true 28 | end 29 | 30 | def reload 31 | run_bestpractices 32 | end 33 | 34 | def run_all 35 | run_bestpractices 36 | end 37 | 38 | def run_on_changes(paths) 39 | run_bestpractices 40 | end 41 | 42 | def run_on_removals(paths) 43 | end 44 | 45 | def notify? 46 | !!options[:notify] 47 | end 48 | 49 | private 50 | def run_bestpractices 51 | started_at = Time.now 52 | 53 | run_options = options.select { |key, value| value && ![:run_at_start, :notify].include?(key) }.keys.map do |opt| 54 | if [:format, :exclude, :only].include?(opt) 55 | [ opt.to_s, options[opt] ].join(' ') 56 | else 57 | opt.to_s.gsub('_','-') 58 | end 59 | end 60 | 61 | cmd = (['rails_best_practices'] + run_options).join(' --') 62 | 63 | UI.info "Running Rails Best Practices checklist with command\n=> #{cmd}\n", :reset => true 64 | 65 | @result = system(cmd) 66 | 67 | Notifier::notify( @result, Time.now - started_at ) if notify? 68 | @result 69 | end 70 | 71 | end 72 | end 73 | --------------------------------------------------------------------------------