Skip to content

Loading…

Apply position to routes annotations, enable index annotations #4

Merged
merged 3 commits into from

2 participants

@ffmike

I added a couple of options we need for a project with existing annotations, and fixed one trivial typo.

@cpjolicoeur cpjolicoeur merged commit 4411eac into guard:master
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
This page is out of date. Refresh to see the latest.
Showing with 44 additions and 4 deletions.
  1. +6 −0 README.rdoc
  2. +9 −2 lib/guard/annotate.rb
  3. +29 −2 spec/guard/annotate_spec.rb
View
6 README.rdoc
@@ -67,6 +67,12 @@ You can disable run at start with (default is true):
...
end
+You can annotate indexes on your models with (default is false):
+
+ guard 'annotate', :show_indexes => true
+ ...
+ end
+
== Development
- Source hosed at {GitHub}[https://github.com/cpjolicoeur/guard-annotate]
View
11 lib/guard/annotate.rb
@@ -15,6 +15,7 @@ def initialize( watchers=[], options={} )
options[:tests] = false if options[:tests].nil?
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?
end
def start
@@ -55,15 +56,21 @@ def annotate_tests_flags
options[:tests] ? "" : "--exclude tests,fixtures"
end
+ def show_indexes?
+ options[:show_indexes]
+ end
+
def run_annotate
UI.info 'Running annotate', :reset => true
started_at = Time.now
- @result = system("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?
+ @result = system(annotate_models_command)
Notifier::notify( @result, Time.now - started_at ) if notify?
if annotate_routes?
started_at = Time.now
- @result = system("bundle exec annotate -r")
+ @result = system("bundle exec annotate -r -p #{annotation_position}")
Notifier::notify( @result, Time.now - started_at ) if notify?
end
View
31 spec/guard/annotate_spec.rb
@@ -39,7 +39,22 @@
it "should allow the users to run routes if desired" do
subject = Guard::Annotate.new( [], :routes => true)
- subject.should_receive(:system).twice
+ subject.should_receive(:system).with("bundle exec annotate --exclude tests,fixtures -p before")
+ subject.should_receive(:system).with("bundle exec annotate -r -p before")
+ subject.start
+ end
+
+ it "should allow the user to customize routes annotation position (before)" do
+ subject = Guard::Annotate.new( [], :routes => true, :position => 'before')
+ subject.should_receive(:system).with("bundle exec annotate --exclude tests,fixtures -p before")
+ subject.should_receive(:system).with("bundle exec annotate -r -p before")
+ subject.start
+ end
+
+ it "should allow the user to customize routes annotation position (after)" do
+ subject = Guard::Annotate.new( [], :routes => true, :position => 'after')
+ subject.should_receive(:system).with("bundle exec annotate --exclude tests,fixtures -p after")
+ subject.should_receive(:system).with("bundle exec annotate -r -p after")
subject.start
end
end
@@ -49,12 +64,24 @@
subject.options[:tests].should be_false
end
- it "should allo user to run tests and fixtures annotations if desired" do
+ it "should allow user to run tests and fixtures annotations if desired" do
subject = Guard::Annotate.new( [], :tests => true )
subject.should_receive(:system).with("bundle exec annotate -p before")
subject.start
end
end
+
+ describe "indexes" do
+ it "should not add indexes to annotations by default" do
+ subject.options[:show_indexes].should be_false
+ end
+
+ it "should allow user to add indexes to annotations if desired" do
+ subject = Guard::Annotate.new( [], :show_indexes => true )
+ subject.should_receive(:system).with("bundle exec annotate --exclude tests,fixtures -p before --show-indexes")
+ subject.start
+ end
+ end
end
end
Something went wrong with that request. Please try again.