Permalink
Browse files

add annotate options: simple-indexes, show-migration and format

  • Loading branch information...
1 parent 1b2bb92 commit bb55b2ecb18eab4b6da050c24a603c856ce32981 @mknapik mknapik committed Apr 1, 2013
Showing with 117 additions and 10 deletions.
  1. +19 −1 README.rdoc
  2. +37 −8 lib/guard/annotate.rb
  3. +1 −1 lib/guard/annotate/version.rb
  4. +60 −0 spec/guard/annotate_spec.rb
View
@@ -69,7 +69,25 @@ You can disable run at start with (default is true):
You can annotate indexes on your models with (default is false):
- guard 'annotate', :show_indexes => true
+ guard 'annotate', :show_indexes => true do
+ ...
+ end
+
+You can add simple indexes to the column information (default is false):
+
+ guard 'annotate', :simple_indexes => true do
+ ...
+ end
+
+You can show migration version number in the annotation (default is false):
+
+ guard 'annotate', :show_migration => true do
+ ...
+ end
+
+You can annotate in three different formats: :bare, :rdoc and :markdown (default is :bare):
+
+ guard 'annotate', :format => :rdoc do
...
end
View
@@ -8,7 +8,7 @@ class Annotate < Guard
autoload :Notifier, 'guard/annotate/notifier'
- def initialize( watchers=[], options={} )
+ def initialize(watchers=[], options={})
super
options[:notify] = true if options[:notify].nil?
@@ -17,6 +17,9 @@ def initialize( watchers=[], options={} )
options[:routes] = false if options[:routes].nil?
options[:run_at_start] = true if options[:run_at_start].nil?
options[:show_indexes] = false if options[:show_indexes].nil?
+ options[:simple_indexes] = false if options[:simple_indexes].nil?
+ options[:show_migration] = false if options[:show_migration].nil?
+ options[:format] = nil if options[:format].nil? or not [:bare, :markdown, :rdoc].include? options[:format].to_sym
end
def start
@@ -35,10 +38,10 @@ def run_all
true
end
- def run_on_changes( paths=[] )
+ def run_on_changes(paths=[])
run_annotate
end
- alias :run_on_change :run_on_changes if VERSION < "1.1.0"
+ alias :run_on_change :run_on_changes if VERSION < '1.1.0'
private
@@ -55,25 +58,51 @@ def annotate_routes?
end
def annotate_tests_flags
- options[:tests] ? "" : "--exclude tests,fixtures"
+ options[:tests] ? '' : '--exclude tests,fixtures'
end
def show_indexes?
options[:show_indexes]
end
+ def annotate_format
+ options[:format]
+ end
+
+ def annotate_format?
+ not options[:format].nil?
+ end
+
+ def simple_indexes?
+ options[:simple_indexes]
+ end
+
+ def show_migration?
+ options[:show_migration]
+ end
+
def run_annotate
UI.info 'Running annotate', :reset => true
started_at = Time.now
+ annotate_models_options, annotate_options = '', ''
+
annotate_models_command = "bundle exec annotate #{annotate_tests_flags} -p #{annotation_position}"
- annotate_models_command += " --show-indexes" if show_indexes?
+ annotate_models_options += ' --show-indexes' if show_indexes?
+ annotate_models_options += ' --simple-indexes' if simple_indexes?
+ annotate_models_options += ' --show-migration' if show_migration?
+ annotate_options += " --format=#{annotate_format}" if annotate_format?
+
+ annotate_models_command += annotate_models_options + annotate_options
@result = system(annotate_models_command)
- Notifier::notify( @result, Time.now - started_at ) if notify?
+ Notifier::notify(@result, Time.now - started_at) if notify?
if annotate_routes?
started_at = Time.now
- @result = system("bundle exec annotate -r -p #{annotation_position}")
- Notifier::notify( @result, Time.now - started_at ) if notify?
+ annotate_routes_command = "bundle exec annotate -r -p #{annotation_position}"
+
+ annotate_routes_command += annotate_options
+ @result = system(annotate_routes_command)
+ Notifier::notify(@result, Time.now - started_at) if notify?
end
@result
@@ -1,6 +1,6 @@
# encoding: utf-8
module Guard
module AnnotateVersion
- VERSION = "1.0.0"
+ VERSION = '1.0.1'
end
end
@@ -85,6 +85,66 @@
subject.start
end
end
+
+ describe "simple indexes" do
+ it "should not add simple indexes to annotations by default" do
+ subject.options[:simple_indexes].should be_false
+ end
+
+ it "should allow user to add simple indexes to annotations if desired" do
+ subject = Guard::Annotate.new( [], :simple_indexes => true )
+ subject.should_receive(:system).with("bundle exec annotate --exclude tests,fixtures -p before --simple-indexes")
+ subject.start
+ end
+ end
+
+ describe "show migration" do
+ it "should not show migration version in annotations by default" do
+ subject.options[:show_migration].should be_false
+ end
+
+ it "should allow user to add migration version in annotations if desired" do
+ subject = Guard::Annotate.new( [], :show_migration => true )
+ subject.should_receive(:system).with("bundle exec annotate --exclude tests,fixtures -p before --show-migration")
+ subject.start
+ end
+ end
+
+ describe "annotation format" do
+ it "should not add format type to annotations by default" do
+ subject.options[:show_migration].should be_false
+ end
+
+ describe "invalid" do
+ it "should not add format type if option given is invalid" do
+ subject = Guard::Annotate.new( [], :format => :invalid_option)
+ subject.options[:show_migration].should be_false
+ subject.should_receive(:system).with("bundle exec annotate --exclude tests,fixtures -p before")
+ subject.start
+ end
+ end
+ describe "bare" do
+ it "should allow user to choose format of annotations if desired" do
+ subject = Guard::Annotate.new( [], :format => :bare )
+ subject.should_receive(:system).with("bundle exec annotate --exclude tests,fixtures -p before --format=bare")
+ subject.start
+ end
+ end
+ describe "rdoc" do
+ it "should allow user to choose format of annotations if desired" do
+ subject = Guard::Annotate.new( [], :format => :rdoc )
+ subject.should_receive(:system).with("bundle exec annotate --exclude tests,fixtures -p before --format=rdoc")
+ subject.start
+ end
+ end
+ describe "markdown" do
+ it "should allow user to choose format of annotations if desired" do
+ subject = Guard::Annotate.new( [], :format => :markdown )
+ subject.should_receive(:system).with("bundle exec annotate --exclude tests,fixtures -p before --format=markdown")
+ subject.start
+ end
+ end
+ end
describe "run_at_start" do
it "should run at start by default" do

0 comments on commit bb55b2e

Please sign in to comment.