Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

add simple_indexes option

  • Loading branch information...
commit ffceca9b0280a83200649736627f632b6299e58d 1 parent 513b837
@nofxx nofxx authored
View
1  VERSION
@@ -0,0 +1 @@
+2.3.2
View
4 VERSION.yml
@@ -1,4 +0,0 @@
----
-:major: 2
-:minor: 3
-:patch: 1
View
11 annotate.gemspec
@@ -1,12 +1,15 @@
+# Generated by jeweler
+# DO NOT EDIT THIS FILE
+# Instead, edit Jeweler::Tasks in Rakefile, and run `rake gemspec`
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = %q{annotate}
- s.version = "2.3.1"
+ s.version = "2.3.2"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Cuong Tran", "Marcos Piccinini"]
- s.date = %q{2009-07-02}
+ s.date = %q{2009-08-21}
s.default_executable = %q{annotate}
s.email = %q{x@nofxx.com}
s.executables = ["annotate"]
@@ -18,7 +21,7 @@ Gem::Specification.new do |s|
"History.txt",
"README.rdoc",
"Rakefile",
- "VERSION.yml",
+ "VERSION",
"annotate.gemspec",
"bin/annotate",
"lib/annotate.rb",
@@ -35,7 +38,7 @@ Gem::Specification.new do |s|
s.homepage = %q{http://github.com/nofxx/annotate}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
- s.rubygems_version = %q{1.3.4}
+ s.rubygems_version = %q{1.3.5}
s.summary = %q{Annotates Rails Models, routes, and others}
s.test_files = [
"spec/annotate/annotate_models_spec.rb",
View
26 bin/annotate
@@ -7,31 +7,35 @@ task = :annotate_models
OptionParser.new do |opts|
opts.banner = "Usage: annotate [options]"
- opts.on('-d', '--delete',
+ opts.on('-d', '--delete',
"Remove annotations from all model files") do
task = :remove_annotation
end
- opts.on('-p', '--position [before|after]', ['before', 'after'],
- "Place the annotations at the top (before) or the bottom (after) of the model file") do |p|
+ opts.on('-p', '--position [before|after]', ['before', 'after'],
+ "Place the annotations at the top (before) or the bottom (after) of the model file") do |p|
ENV['position'] = p
end
- opts.on('-r', '--routes',
+ opts.on('-r', '--routes',
"Annotate routes.rb with the output of 'rake routes'") do
task = :annotate_routes
end
- opts.on('-v', '--version',
- "Show the current version of this gem") do
- puts "Annotate v#{Annotate::VERSION}"; exit
+ opts.on('-v', '--version',
+ "Show the current version of this gem") do
+ puts "Annotate v#{Annotate::VERSION}"; exit
end
- opts.on('-m', '--show-migration',
+ opts.on('-m', '--show-migration',
"Include the migration version number in the annotation") do
ENV['include_version'] = "yes"
end
- opts.on('-i', '--show-indexes',
- "List the table's database indexes in the annotation") do
+ opts.on('-i', '--show-indexes',
+ "List the table's database indexes in the annotation") do
ENV['show_indexes'] = "yes"
end
- opts.on('--model-dir dir',
+ opts.on('-s', '--simple-indexes',
+ "Concat the column's related indexes in the annotation") do
+ ENV['simple_indexes'] = "yes"
+ end
+ opts.on('--model-dir dir',
"Annotate model files stored in dir rather than app/models") do |dir|
ENV['model_dir'] = dir
end
View
11 lib/annotate/annotate_models.rb
@@ -64,6 +64,17 @@ def get_schema_info(klass, header, options = {})
attrs << "#{col.geometry_type}, #{col.srid}"
end
+ # Check if the column has indices and print "indexed" if true
+ # If the indice include another colum, print it too.
+ if options[:simple_indexes] # Check out if this column is indexed
+ indices = klass.connection.indexes(klass.table_name)
+ if indices = indices.select { |ind| ind.columns.include? col.name }
+ indices.each do |ind|
+ ind = ind.columns.reject! { |i| i == col.name }
+ attrs << (ind.length == 0 ? "indexed" : "indexed => [#{ind.join(", ")}]")
+ end
+ end
+ end
info << sprintf("# %-#{max_size}.#{max_size}s:%-15.15s %s", col.name, col_type, attrs.join(", ")).rstrip + "\n"
end
View
3  lib/tasks/annotate_models.rake
@@ -5,9 +5,10 @@ task :annotate_models => :environment do
options[:position_in_class] = ENV['position_in_class'] || ENV['position'] || :before
options[:position_in_fixture] = ENV['position_in_fixture'] || ENV['position'] || :before
options[:show_indexes] = ENV['show_indexes']
+ options[:simple_indexes] = ENV['simple_indexes']
options[:model_dir] = ENV['model_dir']
options[:include_version] = ENV['include_version']
- options[:require] = ENV['require'].split(',')
+ options[:require] = ENV['require'].split(',') rescue []
AnnotateModels.do_annotations(options)
end
View
5 spec/annotate/annotate_models_spec.rb
@@ -23,6 +23,7 @@ def mock_column(stubs={})
it "should get schema info" do
AnnotateModels.get_schema_info(mock_klass(
+ :connection => mock("Conn", :indexes => []),
:table_name => "users",
:primary_key => "id",
:column_names => ["id","login"],
@@ -41,7 +42,7 @@ def mock_column(stubs={})
EOS
end
-
+
describe "#get_model_class" do
module ::ActiveRecord
class Base
@@ -61,7 +62,7 @@ def create(file, body="hi")
AnnotateModels.model_dir = @dir
create('foo.rb', <<-EOS)
class Foo < ActiveRecord::Base
- end
+ end
EOS
create('foo_with_macro.rb', <<-EOS)
class FooWithMacro < ActiveRecord::Base
Please sign in to comment.
Something went wrong with that request. Please try again.