Skip to content

Commit

Permalink
add annotate options: simple-indexes, show-migration and format
Browse files Browse the repository at this point in the history
  • Loading branch information
mknapik committed Apr 1, 2013
1 parent 1b2bb92 commit bb55b2e
Show file tree
Hide file tree
Showing 4 changed files with 117 additions and 10 deletions.
20 changes: 19 additions & 1 deletion README.rdoc
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -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): 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 end


Expand Down
45 changes: 37 additions & 8 deletions lib/guard/annotate.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class Annotate < Guard


autoload :Notifier, 'guard/annotate/notifier' autoload :Notifier, 'guard/annotate/notifier'


def initialize( watchers=[], options={} ) def initialize(watchers=[], options={})
super super


options[:notify] = true if options[:notify].nil? options[:notify] = true if options[:notify].nil?
Expand All @@ -17,6 +17,9 @@ def initialize( watchers=[], options={} )
options[:routes] = false if options[:routes].nil? options[:routes] = false if options[:routes].nil?
options[:run_at_start] = true if options[:run_at_start].nil? options[:run_at_start] = true if options[:run_at_start].nil?
options[:show_indexes] = false if options[:show_indexes].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 end


def start def start
Expand All @@ -35,10 +38,10 @@ def run_all
true true
end end


def run_on_changes( paths=[] ) def run_on_changes(paths=[])
run_annotate run_annotate
end 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 private


Expand All @@ -55,25 +58,51 @@ def annotate_routes?
end end


def annotate_tests_flags def annotate_tests_flags
options[:tests] ? "" : "--exclude tests,fixtures" options[:tests] ? '' : '--exclude tests,fixtures'
end end


def show_indexes? def show_indexes?
options[:show_indexes] options[:show_indexes]
end 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 def run_annotate
UI.info 'Running annotate', :reset => true UI.info 'Running annotate', :reset => true
started_at = Time.now started_at = Time.now
annotate_models_options, annotate_options = '', ''

annotate_models_command = "bundle exec annotate #{annotate_tests_flags} -p #{annotation_position}" 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) @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? if annotate_routes?
started_at = Time.now started_at = Time.now
@result = system("bundle exec annotate -r -p #{annotation_position}") annotate_routes_command = "bundle exec annotate -r -p #{annotation_position}"
Notifier::notify( @result, Time.now - started_at ) if notify?
annotate_routes_command += annotate_options
@result = system(annotate_routes_command)
Notifier::notify(@result, Time.now - started_at) if notify?
end end


@result @result
Expand Down
2 changes: 1 addition & 1 deletion lib/guard/annotate/version.rb
Original file line number Original file line Diff line number Diff line change
@@ -1,6 +1,6 @@
# encoding: utf-8 # encoding: utf-8
module Guard module Guard
module AnnotateVersion module AnnotateVersion
VERSION = "1.0.0" VERSION = '1.0.1'
end end
end end
60 changes: 60 additions & 0 deletions spec/guard/annotate_spec.rb
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -85,6 +85,66 @@
subject.start subject.start
end end
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 describe "run_at_start" do
it "should run at start by default" do it "should run at start by default" do
Expand Down

0 comments on commit bb55b2e

Please sign in to comment.