wagons 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (87) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/README.rdoc +21 -0
  3. data/Rakefile +36 -0
  4. data/lib/generators/wagon/USAGE +7 -0
  5. data/lib/generators/wagon/templates/%singular_name%.gemspec.tt +21 -0
  6. data/lib/generators/wagon/templates/Gemfile.tt +20 -0
  7. data/lib/generators/wagon/templates/Rakefile.tt +12 -0
  8. data/lib/generators/wagon/templates/config/routes.rb +3 -0
  9. data/lib/generators/wagon/templates/lib/%singular_name%/version.rb.tt +3 -0
  10. data/lib/generators/wagon/templates/lib/%singular_name%/wagon.rb.tt +13 -0
  11. data/lib/generators/wagon/templates/lib/%singular_name%.rb.tt +7 -0
  12. data/lib/generators/wagon/templates/script/rails.tt +11 -0
  13. data/lib/generators/wagon/templates/test/%singular_name%_test.rb.tt +7 -0
  14. data/lib/generators/wagon/templates/test/test_helper.rb.tt +10 -0
  15. data/lib/generators/wagon/wagon_generator.rb +21 -0
  16. data/lib/tasks/wagons.rake +112 -0
  17. data/lib/wagons/railtie.rb +8 -0
  18. data/lib/wagons/test_case.rb +10 -0
  19. data/lib/wagons/version.rb +3 -0
  20. data/lib/wagons/wagon.rb +112 -0
  21. data/lib/wagons/wagon_tasks.rake +145 -0
  22. data/lib/wagons.rb +15 -0
  23. data/test/dummy/Gemfile +13 -0
  24. data/test/dummy/Gemfile.lock +113 -0
  25. data/test/dummy/README.rdoc +261 -0
  26. data/test/dummy/Rakefile +7 -0
  27. data/test/dummy/Wagonfile +6 -0
  28. data/test/dummy/app/assets/javascripts/application.js +15 -0
  29. data/test/dummy/app/assets/stylesheets/application.css +13 -0
  30. data/test/dummy/app/controllers/application_controller.rb +3 -0
  31. data/test/dummy/app/helpers/application_helper.rb +2 -0
  32. data/test/dummy/app/models/person.rb +5 -0
  33. data/test/dummy/app/views/layouts/application.html.erb +14 -0
  34. data/test/dummy/config/application.rb +60 -0
  35. data/test/dummy/config/boot.rb +6 -0
  36. data/test/dummy/config/database.yml +25 -0
  37. data/test/dummy/config/environment.rb +5 -0
  38. data/test/dummy/config/environments/development.rb +37 -0
  39. data/test/dummy/config/environments/production.rb +67 -0
  40. data/test/dummy/config/environments/test.rb +37 -0
  41. data/test/dummy/config/initializers/backtrace_silencers.rb +7 -0
  42. data/test/dummy/config/initializers/inflections.rb +15 -0
  43. data/test/dummy/config/initializers/mime_types.rb +5 -0
  44. data/test/dummy/config/initializers/secret_token.rb +7 -0
  45. data/test/dummy/config/initializers/session_store.rb +8 -0
  46. data/test/dummy/config/initializers/wrap_parameters.rb +14 -0
  47. data/test/dummy/config/locales/en.yml +5 -0
  48. data/test/dummy/config/routes.rb +58 -0
  49. data/test/dummy/config.ru +4 -0
  50. data/test/dummy/db/development.sqlite3 +0 -0
  51. data/test/dummy/db/fixtures/development/people.rb +4 -0
  52. data/test/dummy/db/fixtures/test/people.rb +4 -0
  53. data/test/dummy/db/migrate/20120606125104_create_people.rb +10 -0
  54. data/test/dummy/db/schema.rb +23 -0
  55. data/test/dummy/db/test.sqlite3 +0 -0
  56. data/test/dummy/dummy.gemspec +17 -0
  57. data/test/dummy/log/development.log +2017 -0
  58. data/test/dummy/log/test.log +2311 -0
  59. data/test/dummy/public/404.html +26 -0
  60. data/test/dummy/public/422.html +26 -0
  61. data/test/dummy/public/500.html +25 -0
  62. data/test/dummy/public/favicon.ico +0 -0
  63. data/test/dummy/script/rails +6 -0
  64. data/test/dummy/test/fixtures/people.yml +9 -0
  65. data/test/dummy/test/test_helper.rb +13 -0
  66. data/test/dummy/test/unit/person_test.rb +15 -0
  67. data/test/dummy/vendor/wagons/superliner/Gemfile +14 -0
  68. data/test/dummy/vendor/wagons/superliner/Gemfile.lock +113 -0
  69. data/test/dummy/vendor/wagons/superliner/Rakefile +13 -0
  70. data/test/dummy/vendor/wagons/superliner/app/models/city.rb +7 -0
  71. data/test/dummy/vendor/wagons/superliner/config/routes.rb +3 -0
  72. data/test/dummy/vendor/wagons/superliner/db/development.sqlite3 +0 -0
  73. data/test/dummy/vendor/wagons/superliner/db/fixtures/cities.rb +1 -0
  74. data/test/dummy/vendor/wagons/superliner/db/migrate/20120606125258_create_cities.rb +11 -0
  75. data/test/dummy/vendor/wagons/superliner/dummy_superliner.gemspec +21 -0
  76. data/test/dummy/vendor/wagons/superliner/lib/dummy_superliner/version.rb +3 -0
  77. data/test/dummy/vendor/wagons/superliner/lib/dummy_superliner/wagon.rb +14 -0
  78. data/test/dummy/vendor/wagons/superliner/lib/dummy_superliner.rb +6 -0
  79. data/test/dummy/vendor/wagons/superliner/script/rails +11 -0
  80. data/test/dummy/vendor/wagons/superliner/test/fixtures/cities.yml +11 -0
  81. data/test/dummy/vendor/wagons/superliner/test/test_helper.rb +10 -0
  82. data/test/dummy/vendor/wagons/superliner/test/unit/city_test.rb +9 -0
  83. data/test/dummy/vendor/wagons/superliner/test/unit/person_test.rb +16 -0
  84. data/test/dummy/vendor/wagons/superliner/test/wagon_test.rb +51 -0
  85. data/test/test_helper.rb +15 -0
  86. data/test/wagons_test.rb +7 -0
  87. metadata +256 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2012 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,21 @@
1
+ = Here be Wagons!
2
+
3
+ Wagons are extensions to your application train running on Rails. You can see them as plugins that extend the behavior of your specific Rails application. This framework makes it easy to create and manage them.
4
+
5
+ == Setup
6
+
7
+ As always, add this declaration to your application's Gemfile
8
+
9
+ gem 'wagons'
10
+
11
+ If you do not have one yet, create a .gemspec file for your application. This allows Rubygems to see your application as a (virtual) gem, so your wagons can define a dependency on it. As with all gems, move your (production) dependencies to this gemspec (+add_dependency+) and simply call +gemspec+ inside your Gemfile.
12
+
13
+ Now you are ready for your first wagon. Generate it with
14
+
15
+ rails generate wagon [name]
16
+
17
+ == Under the hood
18
+
19
+ TODO:
20
+ * Wagonfile
21
+ * Rake Tasks
data/Rakefile ADDED
@@ -0,0 +1,36 @@
1
+ #!/usr/bin/env rake
2
+ begin
3
+ require 'bundler/setup'
4
+ rescue LoadError
5
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
6
+ end
7
+ begin
8
+ require 'rdoc/task'
9
+ rescue LoadError
10
+ require 'rdoc/rdoc'
11
+ require 'rake/rdoctask'
12
+ RDoc::Task = Rake::RDocTask
13
+ end
14
+
15
+ RDoc::Task.new(:rdoc) do |rdoc|
16
+ rdoc.rdoc_dir = 'rdoc'
17
+ rdoc.title = 'Here be Wagons'
18
+ rdoc.options << '--line-numbers'
19
+ rdoc.rdoc_files.include('README.rdoc')
20
+ rdoc.rdoc_files.include('lib/**/*.rb')
21
+ end
22
+
23
+
24
+
25
+
26
+ Bundler::GemHelper.install_tasks
27
+
28
+ require 'rake/testtask'
29
+
30
+ task :test do
31
+ puts "Testing wagons is a bit weird. So far, please run the following command directly in your shell:"
32
+ puts "(cd test/dummy/vendor/wagons/superliner && rake)"
33
+ end
34
+
35
+
36
+ task :default => :test
@@ -0,0 +1,7 @@
1
+ Description:
2
+ Generates a new wagon
3
+
4
+ Example:
5
+ rails generate wagon superliner
6
+
7
+ This will create a brand new wagon in vendor/wagons/superliner.
@@ -0,0 +1,21 @@
1
+ $:.push File.expand_path("../lib", __FILE__)
2
+
3
+ # Maintain your wagon's version:
4
+ require "<%= singular_name %>/version"
5
+
6
+ # Describe your gem and declare its dependencies:
7
+ Gem::Specification.new do |s|
8
+ s.name = "<%= singular_name %>"
9
+ s.version = <%= class_name %>::VERSION
10
+ s.authors = ["TODO: Your name"]
11
+ s.email = ["TODO: Your email"]
12
+ #s.homepage = "TODO"
13
+ s.summary = "<%= wagon_name.humanize.titleize %>"
14
+ s.description = "TODO: description"
15
+
16
+ s.files = Dir["{app,config,db,lib}/**/*"] + ["Rakefile"]
17
+ s.test_files = Dir["test/**/*"]
18
+
19
+ s.add_dependency "<%= application_name %>"
20
+
21
+ end
@@ -0,0 +1,20 @@
1
+ <%= app_root_initializer %>
2
+
3
+ source "http://rubygems.org"
4
+
5
+ # Declare your gem's dependencies in <%= singular_name %>.gemspec.
6
+ # Bundler will treat runtime dependencies like base dependencies, and
7
+ # development dependencies will be added by default to the :development group.
8
+ gemspec
9
+
10
+ group :development, :test do
11
+ gem '<%= application_name %>', :path => ENV['APP_ROOT']
12
+ end
13
+
14
+ # Declare any dependencies that are still in development here instead of in
15
+ # your gemspec. These might include edge Rails or gems from your path or
16
+ # Git. Remember to move these dependencies to your gemspec before releasing
17
+ # your gem to rubygems.org.
18
+
19
+ # To use debugger
20
+ # gem 'ruby-debug'
@@ -0,0 +1,12 @@
1
+ #!/usr/bin/env rake
2
+
3
+ begin
4
+ require 'bundler/setup'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ ENGINE_PATH = File.expand_path('..', __FILE__)
10
+ <%= app_root_initializer %>
11
+
12
+ load 'wagons/wagon_tasks.rake'
@@ -0,0 +1,3 @@
1
+ Rails.application.routes.draw do
2
+
3
+ end
@@ -0,0 +1,3 @@
1
+ module <%= class_name %>
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,13 @@
1
+ module <%= class_name %>
2
+ class Wagon < Rails::Engine
3
+ include ::Wagon
4
+
5
+ # Add a load path for this specific Wagon
6
+ #config.autoload_paths += %W( #{config.root}/lib )
7
+
8
+ config.to_prepare do
9
+ # extend application classes here
10
+ end
11
+
12
+ end
13
+ end
@@ -0,0 +1,7 @@
1
+ require 'wagons'
2
+ # require 'your_wagon_dependencies'
3
+ require '<%= singular_name %>/wagon'
4
+
5
+ module <%= class_name %>
6
+ end
7
+
@@ -0,0 +1,11 @@
1
+ #!/usr/bin/env ruby
2
+ # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application.
3
+
4
+ ENGINE_ROOT = File.expand_path('../..', __FILE__)
5
+
6
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('Gemfile', ENGINE_ROOT)
7
+ ENGINE_PATH = File.expand_path('lib/<%= singular_name %>/engine', ENGINE_ROOT)
8
+
9
+ <%= app_root_initializer %>
10
+
11
+ load File.expand_path('script/rails', ENV["APP_ROOT"])
@@ -0,0 +1,7 @@
1
+ require 'test_helper'
2
+
3
+ class <%= class_name %>Test < ActiveSupport::TestCase
4
+ test "truth" do
5
+ assert_kind_of Module, <%= class_name %>
6
+ end
7
+ end
@@ -0,0 +1,10 @@
1
+ # Configure Rails Environment
2
+ <%= app_root_initializer %>
3
+ ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
4
+
5
+ require File.join(ENV["APP_ROOT"], 'test', 'test_helper.rb')
6
+
7
+
8
+ class ActiveSupport::TestCase
9
+ self.reset_fixture_path File.expand_path("../fixtures", __FILE__)
10
+ end
@@ -0,0 +1,21 @@
1
+ class WagonGenerator < Rails::Generators::NamedBase
2
+
3
+ attr_reader :wagon_name, :app_root_initializer
4
+
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ def initialize(*args)
8
+ super
9
+ @wagon_name = name
10
+ @app_root_initializer = "ENV['APP_ROOT'] ||= File.expand_path(__FILE__).split(\"vendor\#{File::SEPARATOR}wagons\").first"
11
+
12
+ assign_names!("#{application_name}_#{name}")
13
+ end
14
+
15
+
16
+ def copy_templates
17
+ self.destination_root = "vendor/wagons/#{wagon_name}"
18
+ directory('.')
19
+ end
20
+
21
+ end
@@ -0,0 +1,112 @@
1
+
2
+ namespace :wagon do
3
+ desc "Run wagon migrations (options: VERSION=x, WAGON=abc, VERBOSE=false)"
4
+ task :migrate => [:environment, :'db:load_config'] do
5
+ ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
6
+ wagons.each do |wagon|
7
+ wagon.migrate(ENV["VERSION"] ? ENV["VERSION"].to_i : nil)
8
+ end
9
+ end
10
+
11
+ desc "Revert wagon migrations (options: WAGON=abc, VERBOSE=false)"
12
+ task :revert => [:environment, :'db:load_config'] do
13
+ ActiveRecord::Migration.verbose = ENV["VERBOSE"] ? ENV["VERBOSE"] == "true" : true
14
+ wagons.reverse.each do |wagon|
15
+ wagon.revert
16
+ end
17
+ end
18
+
19
+ desc "Seed wagon data (options: WAGON=abc)"
20
+ task :seed => :abort_if_pending_migrations do
21
+ wagons.each { |wagon| wagon.load_seed }
22
+ end
23
+
24
+ desc "Unseed wagon data (options: WAGON=abc)"
25
+ task :unseed => :abort_if_pending_migrations do
26
+ wagons.reverse.each { |wagon| wagon.unload_seed }
27
+ end
28
+
29
+ desc "Migrate and seed wagons"
30
+ task :setup => [:migrate, :seed]
31
+
32
+ desc "Remove the specified wagon"
33
+ task :remove do
34
+ if wagons.size != 1
35
+ puts "Please specify a WAGON to remove"
36
+ elsif message = wagons.first.protect?
37
+ puts message
38
+ else
39
+ Rake::Task['wagon:unseed'].invoke
40
+ Rake::Task['wagon:revert'].invoke
41
+ end
42
+ end
43
+
44
+ desc "Creates a Wagonfile for development"
45
+ task :file do
46
+ file = Rails.root.join('Wagonfile')
47
+ unless File.exist?(file)
48
+ File.open(file, 'w') do |f|
49
+ f.puts <<FIN
50
+ group :development do
51
+ # Load all wagons found in vendor/wagons/*
52
+ Dir[File.expand_path('../vendor/wagons/**/*.gemspec', __FILE__)].each do |spec|
53
+ gem File.basename(spec, '.gemspec'), :path => File.expand_path('..', spec)
54
+ end
55
+ end
56
+ FIN
57
+ end
58
+ end
59
+ gemfile = Rails.root.join('Gemfile')
60
+ content = File.read(gemfile)
61
+ unless content =~ /wagonfile/
62
+ File.open(gemfile, 'w') do |f|
63
+ f.puts content
64
+ f.puts "\n\n"
65
+ f.puts "# Include the wagon gems you want attached in Wagonfile.
66
+ # Do not check Wagonfile into source control.
67
+ #
68
+ # To create a Wagonfile suitable for development, run 'rake wagon:file'
69
+ wagonfile = File.expand_path('../Wagonfile', __FILE__)
70
+ eval(File.read(wagonfile)) if File.exist?(wagonfile)"
71
+ end
72
+ end
73
+ end
74
+
75
+ desc "list the loaded wagons"
76
+ task :list => :environment do # depend on environment to get correct order
77
+ wagons.each {|p| puts p.wagon_name }
78
+ end
79
+
80
+ namespace :test do
81
+ desc "Create script to test all wagons at once"
82
+ task :script => :environment do
83
+ script = 'vendor/wagons/test_wagons.sh'
84
+ File.open(script, 'w') do |f|
85
+ wagons.each do |w|
86
+ f.puts "(echo && echo '*** TESTING #{w.wagon_name.upcase} ***' && cd #{w.root.to_s[(Rails.root.to_s.size+1)..-1]} && bundle exec rake)"
87
+ end
88
+ end
89
+ end
90
+ end
91
+
92
+ # desc "Raises an error if there are pending wagon migrations"
93
+ task :abort_if_pending_migrations => :environment do
94
+ pending_migrations = ActiveRecord::Migrator.new(:up, wagons.collect(&:migrations_paths).flatten).pending_migrations
95
+
96
+ if pending_migrations.any?
97
+ puts "You have #{pending_migrations.size} pending migrations:"
98
+ pending_migrations.each do |pending_migration|
99
+ puts ' %4d %s' % [pending_migration.version, pending_migration.name]
100
+ end
101
+ abort %{Run `rake wagon:migrate` to update your database then try again.}
102
+ end
103
+ end
104
+ end
105
+
106
+ # Load the wagons specified by WAGON or all available.
107
+ def wagons
108
+ to_load = ENV['WAGON'].blank? ? :all : ENV['WAGON'].split(",").map(&:strip)
109
+ wagons = Wagon.all.select { |wagon| to_load == :all || to_load.include?(wagon.wagon_name) }
110
+ puts "Please specify at least one valid WAGON" if wagons.blank?
111
+ wagons
112
+ end
@@ -0,0 +1,8 @@
1
+ module Wagons
2
+ # Integrate tasks into Rails.
3
+ class Railtie < Rails::Railtie
4
+ rake_tasks do
5
+ load "tasks/wagons.rake"
6
+ end
7
+ end
8
+ end
@@ -0,0 +1,10 @@
1
+ class ActiveSupport::TestCase
2
+
3
+ # Resets the fixtures to the new path
4
+ def self.reset_fixture_path(path)
5
+ self.fixture_table_names = []
6
+ self.fixture_class_names = {}
7
+ self.fixture_path = path
8
+ self.fixtures :all
9
+ end
10
+ end
@@ -0,0 +1,3 @@
1
+ module Wagons
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,112 @@
1
+ # A wagon is an extension to your application train running on Rails.
2
+ #
3
+ # Wagons are built on Rails Engines. To change an engine to a wagon,
4
+ # simply include this module into your own Engine.
5
+ module Wagon
6
+
7
+ # All wagons installed in the current Rails application.
8
+ def self.all
9
+ Rails.application.railties.all.select {|r| r.is_a?(Wagon) }
10
+ end
11
+
12
+ # The name of the main Rails application.
13
+ def self.app_name
14
+ Rails.application.class.name.split('::').first.underscore
15
+ end
16
+
17
+ # Find a wagon by its name.
18
+ def self.find(name)
19
+ name = name.to_s
20
+ all.find {|wagon| wagon.wagon_name == name || wagon.gem_name == name }
21
+ end
22
+
23
+ # Version from the gemspec.
24
+ def version
25
+ gemspec.version
26
+ end
27
+
28
+ # Human readable name.
29
+ def label
30
+ gemspec.summary
31
+ end
32
+
33
+ # Simple system name, without application prefix.
34
+ def wagon_name
35
+ gem_name.sub(/^#{Wagon.app_name}_/, '')
36
+ end
37
+
38
+ # Name of the gem.
39
+ def gem_name
40
+ class_name = self.class.name.demodulize.underscore
41
+ engine_name.sub(/_#{class_name}$/, '')
42
+ end
43
+
44
+ # Description from the gemspec.
45
+ def description
46
+ gemspec.description
47
+ end
48
+
49
+ # Direct dependencies on other wagons.
50
+ def dependencies
51
+ gemspec.dependencies.collect(&:name).
52
+ select {|dep| dep =~ /\A#{Wagon.app_name}_/ }.
53
+ collect { |dep| Wagon.find(dep) || raise("No wagon #{dep} found") }
54
+ end
55
+
56
+ # Recursive depdencies on other wagons.
57
+ def all_dependencies
58
+ dependencies.collect {|dep| dep.all_dependencies + [dep] }.flatten.uniq
59
+ end
60
+
61
+ # Gem Specification.
62
+ def gemspec
63
+ Gem::Specification.find_by_name(gem_name)
64
+ end
65
+
66
+ # If true, this wagon may not be removed. Override as required.
67
+ def protect?
68
+ false
69
+ end
70
+
71
+ # Run the migrations.
72
+ def migrate(version = nil)
73
+ ActiveRecord::Migrator.migrate(migrations_paths, version)
74
+ end
75
+
76
+ # Revert the migrations.
77
+ def revert
78
+ ActiveRecord::Migrator.migrate(migrations_paths, 0)
79
+ end
80
+
81
+ # Load seed data in db/fixtures.
82
+ def load_seed
83
+ SeedFu.seed seed_fixtures
84
+ end
85
+
86
+ # Unload seed data in db/fixtures.
87
+ def unload_seed
88
+ SeedFuNdo.unseed seed_fixtures
89
+ end
90
+
91
+ # Paths for migration files.
92
+ def migrations_paths
93
+ paths['db/migrate'].existent
94
+ end
95
+
96
+ # Loads tasks into the main Rails application.
97
+ # Overwritten to only load own rake tasks, without install:migrations task from Rails::Engine
98
+ def load_tasks(app=self)
99
+ railties.all { |r| r.load_tasks(app) }
100
+ extend Rake::DSL if defined? Rake::DSL
101
+ self.class.rake_tasks.each { |block| self.instance_exec(app, &block) }
102
+ paths["lib/tasks"].existent.sort.each { |ext| load(ext) }
103
+ end
104
+
105
+ private
106
+
107
+ def seed_fixtures
108
+ fixtures = root.join('db', 'fixtures')
109
+ [fixtures, File.join(fixtures, Rails.env)]
110
+ end
111
+ end
112
+
@@ -0,0 +1,145 @@
1
+ # These are the tasks included by the specific wagons
2
+
3
+
4
+ begin
5
+ require 'bundler/setup'
6
+ rescue LoadError
7
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
8
+ end
9
+
10
+ require 'rake/testtask'
11
+
12
+ begin
13
+ require 'rdoc/task'
14
+ rescue LoadError
15
+ require 'rdoc/rdoc'
16
+ require 'rake/rdoctask'
17
+ RDoc::Task = Rake::RDocTask
18
+ end
19
+
20
+
21
+ Rake::TestTask.new(:test) do |t|
22
+ t.libs << 'lib'
23
+ t.libs << 'test'
24
+ t.pattern = 'test/**/*_test.rb'
25
+ t.verbose = false
26
+ end
27
+ task :test => [:'app:db:test:prepare']
28
+
29
+ RDoc::Task.new(:rdoc) do |rdoc|
30
+ rdoc.rdoc_dir = 'doc/rdoc'
31
+ rdoc.title = File.basename(ENGINE_PATH)
32
+ rdoc.options << '--line-numbers'
33
+ rdoc.rdoc_files.include('**/*.rdoc')
34
+ rdoc.rdoc_files.include('app/**/*.rb')
35
+ rdoc.rdoc_files.include('lib/**/*.rb')
36
+ end
37
+
38
+ Bundler::GemHelper.install_tasks
39
+
40
+
41
+ APP_RAKEFILE = File.join(ENV['APP_ROOT'], "Rakefile")
42
+
43
+ def app_task(name)
44
+ task name => [:load_app, "app:db:#{name}"]
45
+ end
46
+
47
+ def find_engine_path(path)
48
+ return if path == "/"
49
+
50
+ if Rails::Engine.find(path)
51
+ path
52
+ else
53
+ find_engine_path(File.expand_path('..', path))
54
+ end
55
+ end
56
+
57
+ def wagon
58
+ @wagon ||= Rails::Engine.find(ENGINE_PATH)
59
+ end
60
+
61
+ task "load_app" do
62
+ namespace :app do
63
+ load APP_RAKEFILE
64
+ end
65
+ task :environment => "app:environment"
66
+
67
+ if !defined?(ENGINE_PATH) || !ENGINE_PATH
68
+ ENGINE_PATH = find_engine_path(APP_RAKEFILE)
69
+ end
70
+ end
71
+
72
+
73
+ namespace :db do
74
+ desc "Migrate the database (options: VERSION=x, VERBOSE=false)."
75
+ task :migrate => [:load_app, 'app:environment', 'app:db:load_config'] do
76
+ wagon.migrate
77
+ end
78
+
79
+ desc "Revert the database (options: VERSION=x, VERBOSE=false)."
80
+ task :revert => [:load_app, 'app:environment', 'app:db:load_config'] do
81
+ wagon.revert
82
+ end
83
+
84
+ desc "Load the seed data"
85
+ task "seed" => [:load_app, 'app:db:abort_if_pending_migrations'] do
86
+ wagon.load_seed
87
+ end
88
+
89
+ desc "Unload the seed data"
90
+ task "unseed" => [:load_app, 'app:db:abort_if_pending_migrations'] do
91
+ wagon.unload_seed
92
+ end
93
+
94
+ desc "Run migrations and seed data (use db:reset to also revert the db first)"
95
+ task :setup => [:migrate, :seed]
96
+
97
+ desc "Revert the database and set it up again"
98
+ task :reset => [:unseed, :revert, :setup]
99
+
100
+ desc "Display status of migrations"
101
+ app_task "migrate:status"
102
+ end
103
+
104
+
105
+ Rake.application.invoke_task(:load_app)
106
+
107
+
108
+ namespace :app do
109
+ task :environment do
110
+ # set migrations paths only to core to have db:test:prepare work as desired
111
+ ActiveRecord::Migrator.migrations_paths = Rails.application.paths['db/migrate'].to_a
112
+ end
113
+
114
+ namespace :db do
115
+ namespace :test do
116
+ # for sqlite, make sure to delete the test.sqlite3 from the main application
117
+ task :purge do
118
+ abcs = ActiveRecord::Base.configurations
119
+ case abcs['test']['adapter']
120
+ when /sqlite/
121
+ dbfile = Rails.application.root.join(abcs['test']['database'])
122
+ File.delete(dbfile) if File.exist?(dbfile)
123
+ end
124
+ end
125
+
126
+ # run wagon migrations and load seed data
127
+ task :prepare do
128
+ Rails.env = 'test'
129
+ dependencies = (wagon.all_dependencies + [wagon])
130
+
131
+ # migrate
132
+ dependencies.each { |d| d.migrate }
133
+
134
+ # seed
135
+ SeedFu.quiet = true unless ENV['VERBOSE']
136
+ SeedFu.seed([ Rails.root.join('db/fixtures').to_s,
137
+ Rails.root.join('db/fixtures/test').to_s ])
138
+ dependencies.each { |d| d.load_seed }
139
+ end
140
+ end
141
+ end
142
+ end
143
+
144
+
145
+ task :default => :test
data/lib/wagons.rb ADDED
@@ -0,0 +1,15 @@
1
+ require 'seed-fu-ndo'
2
+
3
+ require 'wagons/wagon'
4
+ require 'wagons/railtie'
5
+ require 'wagons/test_case'
6
+
7
+ module Wagons
8
+ end
9
+
10
+ # Requires the specified argument but silently ignores an LoadErrors.
11
+ def optional_require(*args)
12
+ require *args
13
+ rescue LoadError
14
+ # that's fine, it's an optional require
15
+ end
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
4
+
5
+ gem 'wagons', :path => '../../'
6
+
7
+ # Include the wagons you want attached in Wagonfile.
8
+ # Do not check Wagonfile into source control.
9
+ #
10
+ # To create a Wagonfile suitable for development, run 'rake wagon:file'
11
+ #
12
+ wagonfile = File.expand_path('../Wagonfile', __FILE__)
13
+ eval(File.read(wagonfile)) if File.exist?(wagonfile)