annotate 2.4.1.beta1 → 2.5.0.pre1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,25 +1,25 @@
1
1
  # == Annotate Routes
2
- #
2
+ #
3
3
  # Based on:
4
- #
5
- #
4
+ #
5
+ #
6
6
  #
7
7
  # Prepends the output of "rake routes" to the top of your routes.rb file.
8
8
  # Yes, it's simple but I'm thick and often need a reminder of what my routes mean.
9
- #
9
+ #
10
10
  # Running this task will replace any exising route comment generated by the task.
11
11
  # Best to back up your routes file before running:
12
- #
12
+ #
13
13
  # Author:
14
14
  # Gavin Montague
15
15
  # gavin@leftbrained.co.uk
16
- #
16
+ #
17
17
  # Released under the same license as Ruby. No Support. No Warranty.module AnnotateRoutes
18
18
  #
19
- module AnnotateRoutes
19
+ module AnnotateRoutes
20
20
  PREFIX = "#== Route Map"
21
-
22
- def self.do_annotate
21
+
22
+ def self.do_annotate
23
23
  routes_rb = File.join("config", "routes.rb")
24
24
  header = PREFIX + "\n# Generated on #{Time.now.strftime("%d %b %Y %H:%M")}\n#"
25
25
  if File.exists? routes_rb
@@ -29,8 +29,8 @@ module AnnotateRoutes
29
29
  routes_map = routes_map.inject(header){|sum, line| sum<<"\n# "<<line}
30
30
  content = File.read(routes_rb)
31
31
  content, old = content.split(/^#== Route .*?\n/)
32
- File.open(routes_rb, "wb") do |f|
33
- f.puts content.sub!(/\n?\z/, "\n") + routes_map
32
+ File.open(routes_rb, "wb") do |f|
33
+ f.puts content.sub!(/\n?\z/, "\n") + routes_map
34
34
  end
35
35
  puts "Route file annotated."
36
36
  else
@@ -0,0 +1,6 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ # Make tasks visible for Rails also when used as gem.
5
+ Dir[File.join(File.dirname(__FILE__), '..', 'tasks', '**/*.rake')].each { |rake| load rake }
6
+ Dir[File.join(File.dirname(__FILE__), '..', '..', 'tasks', '**/*.rake')].each { |rake| load rake }
@@ -0,0 +1,5 @@
1
+ module Annotate
2
+ def self.version
3
+ "2.5.0.pre1"
4
+ end
5
+ end
@@ -0,0 +1,4 @@
1
+ Add a .rake file that automatically annotates models when you do a db:migrate
2
+ in development mode:
3
+
4
+ rails generate annotate_models:install
@@ -0,0 +1,14 @@
1
+ module AnnotateModels
2
+ module Generators
3
+ class InstallGenerator < Rails::Generators::Base
4
+ desc "Copy annotate_models rakefiles for automatic annotation"
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ # copy rake tasks
8
+ def copy_tasks
9
+ template "auto_annotate_models.rake", "lib/tasks/auto_annotate_models.rake"
10
+ end
11
+
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,20 @@
1
+ # NOTE: only doing this in development as some production environments (Heroku)
2
+ # NOTE: are sensitive to local FS writes, and besides -- it's just not proper
3
+ # NOTE: to have a dev-mode tool do its thing in production.
4
+ if(Rails.env.development?)
5
+ task :set_annotation_options do
6
+ ENV['position_in_class'] = "before"
7
+ ENV['position_in_fixture'] = "before"
8
+ ENV['position_in_factory'] = "before"
9
+ ENV['show_indexes'] = "true"
10
+ ENV['include_version'] = "false"
11
+ ENV['exclude_tests'] = "false"
12
+ ENV['exclude_fixtures'] = "false"
13
+ ENV['ignore_model_sub_dir'] = "false"
14
+ ENV['skip_on_db_migrate'] = "false"
15
+ ENV['format_rdoc'] = "false"
16
+ ENV['format_markdown'] = "false"
17
+ ENV['no_sort'] = "false"
18
+ ENV['force'] = "false"
19
+ end
20
+ end
@@ -1,21 +1,41 @@
1
+ annotate_lib = File.expand_path(File.dirname(File.dirname(__FILE__)))
2
+
3
+ if(!ENV['is_cli'])
4
+ task :set_annotation_options
5
+ task :annotate_models => :set_annotation_options
6
+ end
7
+
1
8
  desc "Add schema information (as comments) to model and fixture files"
2
9
  task :annotate_models => :environment do
3
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'annotate', 'annotate_models'))
4
- options={}
5
- options[:position_in_class] = ENV['position_in_class'] || ENV['position'] || :before
6
- options[:position_in_fixture] = ENV['position_in_fixture'] || ENV['position'] || :before
7
- options[:show_indexes] = ENV['show_indexes']
8
- options[:simple_indexes] = ENV['simple_indexes']
10
+ require "#{annotate_lib}/annotate/annotate_models"
11
+ require "#{annotate_lib}/annotate/active_record_patch"
12
+
13
+ true_re = /(true|t|yes|y|1)$/i
14
+
15
+ options={ :is_rake => true }
16
+ options[:position_in_class] = ENV['position_in_class'] || ENV['position'] || 'before'
17
+ options[:position_in_fixture] = ENV['position_in_fixture'] || ENV['position'] || 'before'
18
+ options[:position_in_factory] = ENV['position_in_factory'] || ENV['position'] || 'before'
19
+ options[:show_indexes] = ENV['show_indexes'] =~ true_re
20
+ options[:simple_indexes] = ENV['simple_indexes'] =~ true_re
9
21
  options[:model_dir] = ENV['model_dir']
10
- options[:include_version] = ENV['include_version']
22
+ options[:include_version] = ENV['include_version'] =~ true_re
11
23
  options[:require] = ENV['require'] ? ENV['require'].split(',') : []
24
+ options[:exclude_tests] = ENV['exclude_tests'] =~ true_re
25
+ options[:exclude_fixtures] = ENV['exclude_fixtures'] =~ true_re
26
+ options[:ignore_model_sub_dir] = ENV['ignore_model_sub_dir'] =~ true_re
27
+ options[:format_rdoc] = ENV['format_rdoc'] =~ true_re
28
+ options[:format_markdown] = ENV['format_markdown'] =~ true_re
29
+ options[:no_sort] = ENV['no_sort'] =~ true_re
30
+ options[:force] = ENV['force'] =~ true_re
12
31
  AnnotateModels.do_annotations(options)
13
32
  end
14
33
 
15
34
  desc "Remove schema information from model and fixture files"
16
35
  task :remove_annotation => :environment do
17
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'annotate', 'annotate_models'))
18
- options={}
36
+ require "#{annotate_lib}/annotate/annotate_models"
37
+ require "#{annotate_lib}/annotate/active_record_patch"
38
+ options={ :is_rake => true }
19
39
  options[:model_dir] = ENV['model_dir']
20
40
  AnnotateModels.remove_annotations(options)
21
41
  end
@@ -1,5 +1,6 @@
1
1
  desc "Prepends the route map to the top of routes.rb"
2
- task :annotate_routes do
3
- require File.expand_path(File.join(File.dirname(__FILE__), '..', 'annotate', 'annotate_routes'))
2
+ task :annotate_routes => :environment do
3
+ annotate_lib = File.expand_path(File.dirname(File.dirname(__FILE__)))
4
+ require "#{annotate_lib}/annotate/annotate_routes"
4
5
  AnnotateRoutes.do_annotate
5
6
  end
data/tasks/migrate.rake CHANGED
@@ -13,9 +13,9 @@ namespace :db do
13
13
  namespace :migrate do
14
14
  [:change, :up, :down, :reset, :redo].each do |t|
15
15
  task t do
16
- Annotate::Migration.update_annotations
16
+ Annotate::Migration.update_annotations
17
17
  end
18
- end
18
+ end
19
19
  end
20
20
  end
21
21
 
@@ -24,9 +24,9 @@ module Annotate
24
24
  @@working = false
25
25
 
26
26
  def self.update_annotations
27
- unless @@working
27
+ unless @@working || (ENV['skip_on_db_migrate'] =~ /(true|t|yes|y|1)$/i)
28
28
  @@working = true
29
- Rake::Task['annotate_models'].invoke
29
+ Rake::Task['annotate_models'].invoke
30
30
  end
31
31
  end
32
32
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: annotate
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.4.1.beta1
4
+ version: 2.5.0.pre1
5
5
  prerelease: 6
6
6
  platform: ruby
7
7
  authors:
@@ -12,21 +12,26 @@ authors:
12
12
  autorequire:
13
13
  bindir: bin
14
14
  cert_chain: []
15
- date: 2011-09-02 00:00:00.000000000Z
15
+ date: 2012-06-08 00:00:00.000000000 Z
16
16
  dependencies:
17
17
  - !ruby/object:Gem::Dependency
18
- name: rspec
19
- requirement: &2154511620 !ruby/object:Gem::Requirement
18
+ name: rake
19
+ requirement: !ruby/object:Gem::Requirement
20
20
  none: false
21
21
  requirements:
22
22
  - - ! '>='
23
23
  - !ruby/object:Gem::Version
24
24
  version: '0'
25
- type: :development
25
+ type: :runtime
26
26
  prerelease: false
27
- version_requirements: *2154511620
28
- description: When run, inserts table descriptions from db.schema into a comment block
29
- of relevant source code.
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ description: Annotates Rails/ActiveRecord Models, routes, fixtures, and others based
34
+ on the database schema.
30
35
  email:
31
36
  - alex@stinky.com
32
37
  - ctran@pragmaquest.com
@@ -38,28 +43,27 @@ extensions: []
38
43
  extra_rdoc_files:
39
44
  - README.rdoc
40
45
  files:
41
- - History.txt
42
46
  - README.rdoc
43
- - Rakefile
44
- - VERSION.yml
45
- - annotate.gemspec
46
- - bin/annotate
47
- - lib/annotate.rb
47
+ - History.txt
48
+ - !binary |-
49
+ YmluL2Fubm90YXRl
50
+ - lib/annotate/active_record_patch.rb
48
51
  - lib/annotate/annotate_models.rb
49
52
  - lib/annotate/annotate_routes.rb
53
+ - lib/annotate/tasks.rb
54
+ - lib/annotate/version.rb
55
+ - lib/annotate.rb
56
+ - lib/generators/annotate_models/install_generator.rb
57
+ - lib/generators/annotate_models/templates/auto_annotate_models.rake
58
+ - lib/generators/annotate_models/USAGE
50
59
  - lib/tasks/annotate_models.rake
51
60
  - lib/tasks/annotate_routes.rake
52
- - spec/annotate/annotate_models_spec.rb
53
- - spec/annotate/annotate_routes_spec.rb
54
- - spec/annotate_spec.rb
55
- - spec/spec.opts
56
- - spec/spec_helper.rb
57
61
  - tasks/migrate.rake
58
- - todo.txt
59
62
  homepage: http://github.com/ctran/annotate_models
60
63
  licenses: []
61
64
  post_install_message:
62
- rdoc_options: []
65
+ rdoc_options:
66
+ - --charset=UTF-8
63
67
  require_paths:
64
68
  - lib
65
69
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -68,6 +72,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
68
72
  - - ! '>='
69
73
  - !ruby/object:Gem::Version
70
74
  version: '0'
75
+ segments:
76
+ - 0
77
+ hash: -2416321078825126796
71
78
  required_rubygems_version: !ruby/object:Gem::Requirement
72
79
  none: false
73
80
  requirements:
@@ -76,14 +83,9 @@ required_rubygems_version: !ruby/object:Gem::Requirement
76
83
  version: 1.3.1
77
84
  requirements: []
78
85
  rubyforge_project: annotate
79
- rubygems_version: 1.8.10
86
+ rubygems_version: 1.8.21
80
87
  signing_key:
81
88
  specification_version: 3
82
- summary: Annotates Rails models, routes, fixtures, and others based on the database
89
+ summary: Annotates Rails Models, routes, fixtures, and others based on the database
83
90
  schema.
84
- test_files:
85
- - spec/annotate/annotate_models_spec.rb
86
- - spec/annotate/annotate_routes_spec.rb
87
- - spec/annotate_spec.rb
88
- - spec/spec.opts
89
- - spec/spec_helper.rb
91
+ test_files: []
data/Rakefile DELETED
@@ -1,51 +0,0 @@
1
- require 'rubygems'
2
- require 'rake'
3
-
4
- # want other tests/tasks run by default? Add them to the list
5
- task :default => [:spec]
6
-
7
- require 'jeweler'
8
- Jeweler::Tasks.new do |gem|
9
- gem.name = "annotate"
10
- gem.summary = "Annotates Rails models, routes, fixtures, and others based on the database schema."
11
- gem.description = "When run, inserts table descriptions from db.schema into a comment block of relevant source code."
12
- gem.email = ["alex@stinky.com", 'ctran@pragmaquest.com', "x@nofxx.com", "turadg@aleahmad.net"]
13
- gem.homepage = "http://github.com/ctran/annotate_models"
14
- gem.authors = ['Cuong Tran', "Alex Chaffee", "Marcos Piccinini", "Turadg Aleahmad"]
15
-
16
- gem.rubyforge_project = "annotate"
17
-
18
- gem.add_development_dependency "rspec"
19
-
20
- gem.test_files = `git ls-files -- {spec,features}/*`.split("\n")
21
- gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
22
- gem.require_path = 'lib'
23
-
24
- # note that Jeweler automatically reads the version from VERSION.yml
25
- # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
26
- end
27
-
28
- Jeweler::GemcutterTasks.new
29
-
30
-
31
- require "rspec/core/rake_task" # RSpec 2.0
32
- RSpec::Core::RakeTask.new(:spec) do |t|
33
- t.pattern = 'spec/*_spec.rb'
34
- # TODO this leaves out the specs on the library itself
35
- end
36
-
37
- # FIXME not working yet
38
- RSpec::Core::RakeTask.new(:rcov) do |t|
39
- t.pattern = 'spec/**/*_spec.rb'
40
- t.rcov = true
41
- end
42
-
43
- # FIXME warns "already initialized constant Task"
44
- # FIXME throws "uninitialized constant RDoc::VISIBILITIES"
45
- # require 'rdoc/task'
46
- # RDoc::Task.new do |rdoc|
47
- # rdoc.main = "README.rdoc"
48
- # rdoc.rdoc_files.include("README.rdoc", "lib/**/*.rb")
49
- # # require 'lib/annotate'
50
- # # rdoc.title = "annotate #{Annotate.version}"
51
- # end
data/VERSION.yml DELETED
@@ -1,5 +0,0 @@
1
- ---
2
- :major: 2
3
- :minor: 4
4
- :patch: 1
5
- :build: 'beta1'
data/annotate.gemspec DELETED
@@ -1,58 +0,0 @@
1
- # Generated by jeweler
2
- # DO NOT EDIT THIS FILE DIRECTLY
3
- # Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
4
- # -*- encoding: utf-8 -*-
5
-
6
- Gem::Specification.new do |s|
7
- s.name = "annotate"
8
- s.version = "2.4.1.beta1"
9
-
10
- s.required_rubygems_version = Gem::Requirement.new("> 1.3.1") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Cuong Tran", "Alex Chaffee", "Marcos Piccinini", "Turadg Aleahmad"]
12
- s.date = "2011-09-02"
13
- s.description = "When run, inserts table descriptions from db.schema into a comment block of relevant source code."
14
- s.email = ["alex@stinky.com", "ctran@pragmaquest.com", "x@nofxx.com", "turadg@aleahmad.net"]
15
- s.executables = ["annotate"]
16
- s.extra_rdoc_files = [
17
- "README.rdoc"
18
- ]
19
- s.files = [
20
- "History.txt",
21
- "README.rdoc",
22
- "Rakefile",
23
- "VERSION.yml",
24
- "annotate.gemspec",
25
- "bin/annotate",
26
- "lib/annotate.rb",
27
- "lib/annotate/annotate_models.rb",
28
- "lib/annotate/annotate_routes.rb",
29
- "lib/tasks/annotate_models.rake",
30
- "lib/tasks/annotate_routes.rake",
31
- "spec/annotate/annotate_models_spec.rb",
32
- "spec/annotate/annotate_routes_spec.rb",
33
- "spec/annotate_spec.rb",
34
- "spec/spec.opts",
35
- "spec/spec_helper.rb",
36
- "tasks/migrate.rake",
37
- "todo.txt"
38
- ]
39
- s.homepage = "http://github.com/ctran/annotate_models"
40
- s.require_paths = ["lib"]
41
- s.rubyforge_project = "annotate"
42
- s.rubygems_version = "1.8.10"
43
- s.summary = "Annotates Rails models, routes, fixtures, and others based on the database schema."
44
- s.test_files = ["spec/annotate/annotate_models_spec.rb", "spec/annotate/annotate_routes_spec.rb", "spec/annotate_spec.rb", "spec/spec.opts", "spec/spec_helper.rb"]
45
-
46
- if s.respond_to? :specification_version then
47
- s.specification_version = 3
48
-
49
- if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
50
- s.add_development_dependency(%q<rspec>, [">= 0"])
51
- else
52
- s.add_dependency(%q<rspec>, [">= 0"])
53
- end
54
- else
55
- s.add_dependency(%q<rspec>, [">= 0"])
56
- end
57
- end
58
-
@@ -1,92 +0,0 @@
1
- require File.dirname(__FILE__) + '/../spec_helper.rb'
2
- require 'annotate/annotate_models'
3
- require 'rubygems'
4
- require 'active_support'
5
-
6
- describe AnnotateModels do
7
-
8
- def mock_klass(stubs={})
9
- @mock_file ||= mock("Klass", stubs)
10
- end
11
-
12
- def mock_column(stubs={})
13
- @mock_column ||= mock("Column", stubs)
14
- end
15
-
16
- it { AnnotateModels.quote(nil).should eql("NULL") }
17
- it { AnnotateModels.quote(true).should eql("TRUE") }
18
- it { AnnotateModels.quote(false).should eql("FALSE") }
19
- it { AnnotateModels.quote(25).should eql("25") }
20
- it { AnnotateModels.quote(25.6).should eql("25.6") }
21
- it { AnnotateModels.quote(1e-20).should eql("1.0e-20") }
22
-
23
- it "should get schema info" do
24
-
25
- AnnotateModels.get_schema_info(mock_klass(
26
- :connection => mock("Conn", :indexes => []),
27
- :table_name => "users",
28
- :primary_key => "id",
29
- :column_names => ["id","login"],
30
- :columns => [
31
- mock_column(:type => "integer", :default => nil, :null => false, :name => "id", :limit => nil),
32
- mock_column(:type => "string", :default => nil, :null => false, :name => "name", :limit => 50)
33
- ]), "Schema Info").should eql(<<-EOS)
34
- # Schema Info
35
- #
36
- # Table name: users
37
- #
38
- # id :integer not null, primary key
39
- # id :integer not null, primary key
40
- #
41
-
42
- EOS
43
-
44
- end
45
-
46
- describe "#get_model_class" do
47
- module ::ActiveRecord
48
- class Base
49
- end
50
- end
51
-
52
- def create(file, body="hi")
53
- File.open(@dir + '/' + file, "w") do |f|
54
- f.puts(body)
55
- end
56
- end
57
-
58
- before :all do
59
- require "tmpdir"
60
- @dir = Dir.tmpdir + "/#{Time.now.to_i}" + "/annotate_models"
61
- FileUtils.mkdir_p(@dir)
62
- AnnotateModels.model_dir = @dir
63
- create('foo.rb', <<-EOS)
64
- class Foo < ActiveRecord::Base
65
- end
66
- EOS
67
- create('foo_with_macro.rb', <<-EOS)
68
- class FooWithMacro < ActiveRecord::Base
69
- acts_as_awesome :yah
70
- end
71
- EOS
72
- create('foo_with_capitals.rb', <<-EOS)
73
- class FooWithCAPITALS < ActiveRecord::Base
74
- acts_as_awesome :yah
75
- end
76
- EOS
77
- end
78
- it "should work" do
79
- klass = AnnotateModels.get_model_class("foo.rb")
80
- klass.name.should == "Foo"
81
- end
82
- it "should not care about unknown macros" do
83
- klass = AnnotateModels.get_model_class("foo_with_macro.rb")
84
- klass.name.should == "FooWithMacro"
85
- end
86
- it "should find models with non standard capitalization" do
87
- klass = AnnotateModels.get_model_class("foo_with_capitals.rb")
88
- klass.name.should == "FooWithCAPITALS"
89
- end
90
- end
91
-
92
- end