From 30390f4aece1f3e59e180bd0a21fb07445cd4942 Mon Sep 17 00:00:00 2001 From: John Bintz Date: Fri, 27 May 2011 14:41:07 -0400 Subject: [PATCH] initial commit --- .gitignore | 4 ++++ Gemfile | 4 ++++ Rakefile | 2 ++ guard-rails.gemspec | 21 +++++++++++++++++++++ lib/guard/rails.rb | 28 ++++++++++++++++++++++++++++ lib/guard/rails/version.rb | 6 ++++++ 6 files changed, 65 insertions(+) create mode 100644 .gitignore create mode 100644 Gemfile create mode 100644 Rakefile create mode 100644 guard-rails.gemspec create mode 100644 lib/guard/rails.rb create mode 100644 lib/guard/rails/version.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..4040c6c --- /dev/null +++ b/.gitignore @@ -0,0 +1,4 @@ +*.gem +.bundle +Gemfile.lock +pkg/* diff --git a/Gemfile b/Gemfile new file mode 100644 index 0000000..99cc2e5 --- /dev/null +++ b/Gemfile @@ -0,0 +1,4 @@ +source "http://rubygems.org" + +# Specify your gem's dependencies in guard-rails.gemspec +gemspec diff --git a/Rakefile b/Rakefile new file mode 100644 index 0000000..14cfe0b --- /dev/null +++ b/Rakefile @@ -0,0 +1,2 @@ +require 'bundler' +Bundler::GemHelper.install_tasks diff --git a/guard-rails.gemspec b/guard-rails.gemspec new file mode 100644 index 0000000..7910dbc --- /dev/null +++ b/guard-rails.gemspec @@ -0,0 +1,21 @@ +# -*- encoding: utf-8 -*- +$:.push File.expand_path("../lib", __FILE__) +require "guard/rails/version" + +Gem::Specification.new do |s| + s.name = "guard-rails" + s.version = Guard::Rails::VERSION + s.platform = Gem::Platform::RUBY + s.authors = ["TODO: Write your name"] + s.email = ["TODO: Write your email address"] + s.homepage = "" + s.summary = %q{TODO: Write a gem summary} + s.description = %q{TODO: Write a gem description} + + s.rubyforge_project = "guard-rails" + + s.files = `git ls-files`.split("\n") + s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n") + s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) } + s.require_paths = ["lib"] +end diff --git a/lib/guard/rails.rb b/lib/guard/rails.rb new file mode 100644 index 0000000..c30806a --- /dev/null +++ b/lib/guard/rails.rb @@ -0,0 +1,28 @@ +require 'guard' +require 'guard/guard' + +module Guard + class Rails < ::Guard::Guard + attr_reader :options + + def initialize(watchers = [], options = {}) + @options = { :port => 3000, :environment => 'development', :start_on_start => true }.merge(options) + end + + def start + UI.info "Guard::Rails restarting app on port #{options[:port]} using #{options[:environment]} environment." + run_all if options[:start_on_start] + end + + def run_all + Notifier.notify("Rails restarting on port #{options[:port]} in #{options[:environment]}", :title => "Restarting Rails...", :image => :pending) + system %{sh -c '[[ -f tmp/pids/#{options[:environment]}.pid ]] && kill $(cat tmp/pids/#{options[:environment]}.pid)'} + system %{rails s -d e #{options[:environment]} -p #{options[:port]}} + end + + def run_on_change(paths) + run_all + end + end +end + diff --git a/lib/guard/rails/version.rb b/lib/guard/rails/version.rb new file mode 100644 index 0000000..918a3e7 --- /dev/null +++ b/lib/guard/rails/version.rb @@ -0,0 +1,6 @@ +module Guard + class Rails + VERSION = '0.0.1' + end +end +