Commit 17c6cad2 by Dmitry Lihachev

jewelerize this

parent aafb09fc
lib/**/*.rb
bin/*
-
features/**/*.feature
LICENSE.txt
.DS_Store
doc/*
rdoc/*
coverage/*
spec/debug.log
pkg/*
.rvmrc
\ No newline at end of file
# rcov generated
coverage
# rdoc generated
rdoc
# yard generated
doc
.yardoc
# bundler
.bundle
# jeweler generated
pkg
# Have editor/IDE/OS specific files you need to ignore? Consider using a global gitignore:
#
# * Create a file at ~/.gitignore
# * Include files you want ignored
# * Run: git config --global core.excludesfile ~/.gitignore
#
# After doing this, these files will be ignored in all your git projects,
# saving you from having to 'pollute' every project you touch with them
#
# Not sure what to needs to be ignored for particular editors/OSes? Here's some ideas to get you started. (Remember, remove the leading # of the line)
#
# For MacOS:
#
#.DS_Store
#
# For TextMate
#*.tmproj
#tmtags
#
# For emacs:
#*~
#\#*
#.\#*
#
# For vim:
#*.swp
--color
source :rubygems
group :development do
gem "rspec"
gem "bundler"
gem "jeweler"
gem "rcov"
gem "fakefs"
gem "activesupport"
gem "i18n"
end
GEM
remote: http://rubygems.org/
specs:
activesupport (3.0.4)
diff-lcs (1.1.2)
fakefs (0.3.1)
git (1.2.5)
i18n (0.5.0)
jeweler (1.5.2)
bundler (~> 1.0.0)
git (>= 1.2.5)
rake
rake (0.8.7)
rcov (0.9.9)
rspec (2.5.0)
rspec-core (~> 2.5.0)
rspec-expectations (~> 2.5.0)
rspec-mocks (~> 2.5.0)
rspec-core (2.5.1)
rspec-expectations (2.5.0)
diff-lcs (~> 1.1.2)
rspec-mocks (2.5.0)
PLATFORMS
ruby
DEPENDENCIES
activesupport
bundler
fakefs
i18n
jeweler
rcov
rspec
Copyright (c) 2011 Dmitry Lihachev
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
# require 'rubygems'
require 'rake'
require File.dirname(__FILE__) + '/lib/annotate'
# want other tests/tasks run by default? Add them to the list
task :default => [:spec]
require 'rubygems'
require 'bundler'
begin
require 'jeweler'
Jeweler::Tasks.new do |gem|
gem.name = "netsign-annotate"
gem.executables = "annotate"
gem.summary = "Annotates Rails Models, routes, fixtures, and others based on the database schema."
gem.description = "Packaged for netSIGN, gem experimentation"
gem.email = ["alex@stinky.com", 'ctran@pragmaquest.com', "x@nofxx.com"]
gem.homepage = "https://github.com/miyucy/annotate_models"
gem.authors = ['Cuong Tran', "Alex Chaffee", "Marcos Piccinini"]
gem.files = FileList["[A-Z]*.*", "{bin,lib,tasks,spec}/**/*"]
gem.rubyforge_project = "netsign-annotate"
Bundler.setup(:default, :development)
rescue Bundler::BundlerError => e
$stderr.puts e.message
$stderr.puts "Run `bundle install` to install missing gems"
exit e.status_code
end
require 'rake'
# note that Jeweler automatically reads the version from VERSION.yml
# gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
end
require 'jeweler'
Jeweler::Tasks.new do |gem|
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
gem.name = "annotated_models"
gem.homepage = "http://github.com/lda/annotated_models"
gem.license = "MIT"
gem.summary = %Q{TODO: one-line summary of your gem}
gem.description = %Q{TODO: longer description of your gem}
gem.email = "lda@openteam.ru"
gem.authors = ["Dmitry Lihachev"]
# Include your dependencies below. Runtime dependencies are required when using your gem,
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
# gem.add_development_dependency 'rspec', '> 1.2.3'
end
Jeweler::RubygemsDotOrgTasks.new
# Jeweler::RubyforgeTasks.new do |rubyforge|
# rubyforge.doc_task = "rdoc"
# end
Jeweler::GemcutterTasks.new
rescue LoadError
puts "Jeweler (or a dependency) not available. Install it with: sudo gem install jeweler"
require 'rspec/core'
require 'rspec/core/rake_task'
RSpec::Core::RakeTask.new(:spec) do |spec|
spec.pattern = FileList['spec/**/*_spec.rb']
end
# Dir["#{File.dirname(__FILE)}/tasks/*.rake"].sort.each { |ext| load ext }
RSpec::Core::RakeTask.new(:rcov) do |spec|
spec.pattern = 'spec/**/*_spec.rb'
spec.rcov = true
end
# require 'spec/rake/spectask'
# Spec::Rake::SpecTask.new(:spec) do |spec|
# spec.libs << 'lib' << 'spec'
# spec.spec_files = FileList['spec/**/*_spec.rb']
# end
#
# Spec::Rake::SpecTask.new(:rcov) do |spec|
# spec.libs << 'lib' << 'spec'
# spec.pattern = 'spec/**/*_spec.rb'
# spec.rcov = true
# end
task :default => :spec
require 'rake/rdoctask'
Rake::RDocTask.new do |rdoc|
version = File.exist?('VERSION') ? File.read('VERSION') : ""
rdoc.rdoc_dir = 'rdoc'
rdoc.title = "annotate #{Annotate.version}"
rdoc.title = "annotated_models #{version}"
rdoc.rdoc_files.include('README*')
rdoc.rdoc_files.include('lib/**/*.rb')
end
---
---
:major: 2
:minor: 4
:patch: 3
:patch: 4
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = %q{annotate}
s.version = "2.4.2"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Cuong Tran", "Alex Chaffee", "Marcos Piccinini"]
s.date = %q{2011-01-29}
s.default_executable = %q{annotate}
s.description = %q{Annotates Rails Models, routes, fixtures, and others based on the database schema.}
s.email = ["alex@stinky.com", "ctran@pragmaquest.com", "x@nofxx.com"]
s.executables = ["annotate"]
s.extra_rdoc_files = [
"README.rdoc"
]
s.files = [
"History.txt",
"README.rdoc",
"VERSION.yml",
"bin/annotate",
"lib/annotate.rb",
"lib/annotate/annotate_models.rb",
"lib/annotate/annotate_routes.rb",
"lib/tasks/annotate_models.rake",
"lib/tasks/annotate_routes.rake",
"lib/tasks/migrate.rake",
"spec/annotate/annotate_models_spec.rb",
"spec/annotate/annotate_routes_spec.rb",
"spec/annotate_spec.rb",
"spec/spec.opts",
"spec/spec_helper.rb"
]
s.homepage = %q{http://github.com/ctran/annotate}
s.rdoc_options = ["--charset=UTF-8"]
s.require_paths = ["lib"]
s.rubyforge_project = %q{annotate}
s.rubygems_version = %q{1.3.7}
s.summary = %q{Annotates Rails Models, routes, fixtures, and others based on the database schema.}
s.test_files = [
"spec/annotate/annotate_models_spec.rb",
"spec/annotate/annotate_routes_spec.rb",
"spec/annotate_spec.rb",
"spec/spec_helper.rb"
]
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
else
end
else
end
end
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = %q{annotated_models}
s.version = "2.4.4"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Dmitry Lihachev"]
s.date = %q{2011-02-18}
s.description = %q{TODO: longer description of your gem}
s.email = %q{lda@openteam.ru}
s.extra_rdoc_files = [
"LICENSE.txt",
"README.rdoc"
]
s.files = [
".document",
"Gemfile",
"LICENSE.txt",
"README.rdoc",
"Rakefile",
"lib/annotated_models.rb",
"test/helper.rb",
"test/test_annotated_models.rb"
]
s.homepage = %q{http://github.com/lda/annotated_models}
s.licenses = ["MIT"]
s.require_paths = ["lib"]
s.rubygems_version = %q{1.3.7}
s.summary = %q{TODO: one-line summary of your gem}
s.test_files = [
"test/helper.rb",
"test/test_annotated_models.rb"
]
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
s.add_development_dependency(%q<shoulda>, [">= 0"])
s.add_development_dependency(%q<bundler>, [">= 0"])
s.add_development_dependency(%q<jeweler>, [">= 0"])
s.add_development_dependency(%q<rcov>, [">= 0"])
else
s.add_dependency(%q<shoulda>, [">= 0"])
s.add_dependency(%q<bundler>, [">= 0"])
s.add_dependency(%q<jeweler>, [">= 0"])
s.add_dependency(%q<rcov>, [">= 0"])
end
else
s.add_dependency(%q<shoulda>, [">= 0"])
s.add_dependency(%q<bundler>, [">= 0"])
s.add_dependency(%q<jeweler>, [">= 0"])
s.add_dependency(%q<rcov>, [">= 0"])
end
end
require 'yaml'
module Annotate
def self.version
version_file = File.dirname(__FILE__) + "/../VERSION.yml"
if File.exist?(version_file)
config = YAML.load(File.read(version_file))
version = "#{config[:major]}.#{config[:minor]}.#{config[:patch]}"
else
version = "0.0.0"
end
end
def self.load_tasks
if File.exists?('Rakefile')
load 'Rakefile'
Dir[File.join(File.dirname(__FILE__), 'tasks', '**/*.rake')].each { |rake| load rake }
return true
else
return false
end
end
end
# == Annotate Routes
#
# Based on:
#
#
#
# Prepends the output of "rake routes" to the top of your routes.rb file.
# Yes, it's simple but I'm thick and often need a reminder of what my routes mean.
#
# Running this task will replace any exising route comment generated by the task.
# Best to back up your routes file before running:
#
# Author:
# Gavin Montague
# gavin@leftbrained.co.uk
#
# Released under the same license as Ruby. No Support. No Warranty.module AnnotateRoutes
#
module AnnotateRoutes
PREFIX = "#== Route Map"
def self.do_annotate
routes_rb = File.join("config", "routes.rb")
header = PREFIX + "\n# Generated on #{Time.now.strftime("%d %b %Y %H:%M")}\n#"
if File.exists? routes_rb
routes_map = `rake routes`
routes_map = routes_map.split("\n")
routes_map.shift # remove the first line of rake routes which is just a file path
routes_map = routes_map.inject(header){|sum, line| sum<<"\n# "<<line}
content = File.read(routes_rb)
content, old = content.split(/^#== Route .*?\n/)
File.open(routes_rb, "wb") do |f|
f.puts content.sub!(/\n?\z/, "\n") + routes_map
end
puts "Route file annotated."
else
puts "Can`t find routes.rb"
end
end
end
module AnnotateModels
module AnnotatedModels
# Annotate Models plugin use this header
COMPAT_PREFIX = "== Schema Info"
PREFIX = "== Schema Information"
......
desc "Prepends the route map to the top of routes.rb"
task :annotate_routes => :environment do
require 'annotate/annotate_routes'
AnnotateRoutes.do_annotate
end
# Generated by jeweler
# DO NOT EDIT THIS FILE DIRECTLY
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
# -*- encoding: utf-8 -*-
Gem::Specification.new do |s|
s.name = %q{netsign-annotate}
s.version = "2.4.3"
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
s.authors = ["Cuong Tran", "Alex Chaffee", "Marcos Piccinini"]
s.date = %q{2011-01-30}
s.default_executable = %q{annotate}
s.description = %q{Packaged for netSIGN, gem experimentation}
s.email = ["alex@stinky.com", "ctran@pragmaquest.com", "x@nofxx.com"]
s.executables = ["annotate"]
s.extra_rdoc_files = [
"README.rdoc"
]
s.files = [
"History.txt",
"README.rdoc",
"VERSION.yml",
"bin/annotate",
"lib/annotate.rb",
"lib/annotate/annotate_models.rb",
"lib/annotate/annotate_routes.rb",
"lib/tasks/annotate_models.rake",
"lib/tasks/annotate_routes.rake",
"lib/tasks/migrate.rake",
"spec/annotate/annotate_models_spec.rb",
"spec/annotate/annotate_routes_spec.rb",
"spec/annotate_spec.rb",
"spec/spec.opts",
"spec/spec_helper.rb"
]
s.homepage = %q{https://github.com/miyucy/annotate_models}
s.require_paths = ["lib"]
s.rubyforge_project = %q{netsign-annotate}
s.rubygems_version = %q{1.3.7}
s.summary = %q{Annotates Rails Models, routes, fixtures, and others based on the database schema.}
s.test_files = [
"spec/annotate/annotate_models_spec.rb",
"spec/annotate/annotate_routes_spec.rb",
"spec/annotate_spec.rb",
"spec/spec_helper.rb"
]
if s.respond_to? :specification_version then
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
s.specification_version = 3
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
else
end
else
end
end
require File.dirname(__FILE__) + '/../spec_helper.rb'
require 'annotate/annotate_routes'
describe AnnotateRoutes do
def mock_file(stubs={})
@mock_file ||= mock(File, stubs)
end
describe "Annotate Job" do
before(:each) do
File.should_receive(:join).with("config", "routes.rb").and_return("config/routes.rb")
end
it "should check if routes.rb exists" do
File.should_receive(:exists?).with("config/routes.rb").and_return(false)
AnnotateRoutes.should_receive(:puts).with("Can`t find routes.rb")
AnnotateRoutes.do_annotate
end
describe "When Annotating" do
before(:each) do
File.should_receive(:exists?).with("config/routes.rb").and_return(true)
AnnotateRoutes.should_receive(:`).with("rake routes").and_return("bad line\ngood line")
File.should_receive(:open).with("config/routes.rb", "wb").and_yield(mock_file)
AnnotateRoutes.should_receive(:puts).with("Route file annotated.")
end
it "should annotate and add a newline!" do
File.should_receive(:read).with("config/routes.rb").and_return("ActionController::Routing...\nfoo")
@mock_file.should_receive(:puts).with(/ActionController::Routing...\nfoo\n#== Route Map\n# Generated on .*\n#\n# good line/)
AnnotateRoutes.do_annotate
end
it "should not add a newline if there are empty lines" do
File.should_receive(:read).with("config/routes.rb").and_return("ActionController::Routing...\nfoo\n")
@mock_file.should_receive(:puts).with(/ActionController::Routing...\nfoo\n#== Route Map\n# Generated on .*\n#\n# good line/)
AnnotateRoutes.do_annotate
end
end
end
end
#encoding: utf-8
require File.dirname(__FILE__) + '/../spec_helper.rb'
require 'annotate/annotate_models'
require 'active_support'
require File.expand_path(File.dirname(__FILE__) + '/spec_helper')
require 'annotated_models'
require 'active_support/core_ext'
require 'active_support/inflector'
require 'fakefs/spec_helpers'
require 'tmpdir'
describe AnnotateModels do
describe AnnotatedModels do
include FakeFS::SpecHelpers
def mock_class(table_name, primary_key, columns)
options = {
:connection => mock("Conn", :indexes => []),
:table_name => table_name,
:model_name => mock("ModelName", :human => ""),
:primary_key => primary_key.to_s,
:column_names => columns.map { |col| col.name.to_s },
:columns => columns
}
mock("An ActiveRecord class", options)
klass = mock("An ActiveRecord class", options)
columns.reverse.each do | column |
klass.stub!(:human_attribute_name).with(column.name, {:default=>""}).and_return("")
end
klass
end
def mock_column(name, type, options={})
......@@ -29,17 +35,17 @@ describe AnnotateModels do
stubs = default_options.dup
stubs.merge!(options)
stubs.merge!(:name => name, :type => type)
stubs.merge!(:name => name, :type => type, :humanize => name.to_s.humanize)
mock("Column", stubs)
end
it { AnnotateModels.quote(nil).should eql("NULL") }
it { AnnotateModels.quote(true).should eql("TRUE") }
it { AnnotateModels.quote(false).should eql("FALSE") }
it { AnnotateModels.quote(25).should eql("25") }
it { AnnotateModels.quote(25.6).should eql("25.6") }
it { AnnotateModels.quote(1e-20).should eql("1.0e-20") }
it { AnnotatedModels.quote(nil).should eql("NULL") }
it { AnnotatedModels.quote(true).should eql("TRUE") }
it { AnnotatedModels.quote(false).should eql("FALSE") }
it { AnnotatedModels.quote(25).should eql("25") }
it { AnnotatedModels.quote(25.6).should eql("25.6") }
it { AnnotatedModels.quote(1e-20).should eql("1.0e-20") }
it "should get schema info" do
klass = mock_class(:users, :id, [
......@@ -47,7 +53,7 @@ describe AnnotateModels do
mock_column(:name, :string, :limit => 50)
])
AnnotateModels.get_schema_info(klass, "Schema Info").should eql(<<-EOS)
AnnotatedModels.get_schema_info(klass, "Schema Info").should eql(<<-EOS)
# Schema Info
#
# Table name: users
......@@ -65,15 +71,15 @@ EOS
mock_column(:name, :string, :limit => 50)
])
ENV.stub!(:[]).with('format_rdoc').and_return(true)
AnnotateModels.get_schema_info(klass, AnnotateModels::PREFIX).should eql(<<-EOS)
# #{AnnotateModels::PREFIX}
AnnotatedModels.get_schema_info(klass, AnnotatedModels::PREFIX).should eql(<<-EOS)
# #{AnnotatedModels::PREFIX}
#
# Table name: users
#
# *id*:: <tt>integer, not null, primary key</tt>
# *name*:: <tt>string(50), not null</tt>
#--
# #{AnnotateModels::END_MARK}
# #{AnnotatedModels::END_MARK}
#++
EOS
......@@ -92,7 +98,7 @@ EOS
before :all do
@dir = File.join Dir.tmpdir, "annotate_models"
FileUtils.mkdir_p(@dir)
AnnotateModels.model_dir = @dir
AnnotatedModels.model_dir = @dir
create('foo.rb', <<-EOS)
class Foo < ActiveRecord::Base
......@@ -112,17 +118,17 @@ EOS
end
it "should work" do
klass = AnnotateModels.get_model_class("foo.rb")
klass = AnnotatedModels.get_model_class("foo.rb")
klass.name.should == "Foo"
end
it "should not care about unknown macros" do
klass = AnnotateModels.get_model_class("foo_with_macro.rb")
klass = AnnotatedModels.get_model_class("foo_with_macro.rb")
klass.name.should == "FooWithMacro"
end
it "should not complain of invalid multibyte char (USASCII)" do
klass = AnnotateModels.get_model_class("foo_with_utf8.rb")
klass = AnnotatedModels.get_model_class("foo_with_utf8.rb")
klass.name.should == "FooWithUtf8"
end
end
......@@ -153,7 +159,7 @@ class Foo < ActiveRecord::Base
end
EOS
AnnotateModels.remove_annotation_of_file("before.rb")
AnnotatedModels.remove_annotation_of_file("before.rb")
content("before.rb").should == <<-EOS
class Foo < ActiveRecord::Base
......@@ -177,7 +183,7 @@ end
EOS
AnnotateModels.remove_annotation_of_file("after.rb")
AnnotatedModels.remove_annotation_of_file("after.rb")
content("after.rb").should == <<-EOS
class Foo < ActiveRecord::Base
......@@ -198,31 +204,31 @@ end
mock_column(:id, :integer),
mock_column(:name, :string, :limit => 50)
])
@schema_info = AnnotateModels.get_schema_info(@klass, "== Schema Info")
@schema_info = AnnotatedModels.get_schema_info(@klass, "== Schema Info")
end
it "should annotate the file before the model if position == 'before'" do
AnnotateModels.annotate_one_file(@file_name, @schema_info, :position => "before")
AnnotatedModels.annotate_one_file(@file_name, @schema_info, :position => "before")
File.read(@file_name).should == "#{@schema_info}#{@file_content}"
end
it "should annotate before if given :position => :before" do
AnnotateModels.annotate_one_file(@file_name, @schema_info, :position => :before)
AnnotatedModels.annotate_one_file(@file_name, @schema_info, :position => :before)
File.read(@file_name).should == "#{@schema_info}#{@file_content}"
end
it "should annotate before if given :position => :after" do
AnnotateModels.annotate_one_file(@file_name, @schema_info, :position => :after)
AnnotatedModels.annotate_one_file(@file_name, @schema_info, :position => :after)
File.read(@file_name).should == "#{@file_content}\n#{@schema_info}"
end
it "should update annotate position" do
AnnotateModels.annotate_one_file(@file_name, @schema_info, :position => :before)
AnnotatedModels.annotate_one_file(@file_name, @schema_info, :position => :before)
another_schema_info = AnnotateModels.get_schema_info(mock_class(:users, :id, [mock_column(:id, :integer),]),
another_schema_info = AnnotatedModels.get_schema_info(mock_class(:users, :id, [mock_column(:id, :integer),]),
"== Schema Info")
AnnotateModels.annotate_one_file(@file_name, another_schema_info, :position => :after)
AnnotatedModels.annotate_one_file(@file_name, another_schema_info, :position => :after)
File.read(@file_name).should == "#{@file_content}\n#{another_schema_info}"
end
......
require File.dirname(__FILE__) + '/spec_helper.rb'
describe Annotate do
it "should have a version" do
Annotate.version.should be_instance_of(String)
end
end
--format=specdoc
--colour
\ No newline at end of file
require 'rubygems'
require 'spec'
$:.unshift(File.dirname(__FILE__) + '/../lib')
require 'annotate'
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
$LOAD_PATH.unshift(File.dirname(__FILE__))
require 'rspec'
require 'annotated_models'
# Requires supporting files with custom matchers and macros, etc,
# in ./support/ and its subdirectories.
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
RSpec.configure do |config|
end
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment