warp_drive 0.1.4 → 0.1.5

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License
2
2
 
3
- Copyright (c) 2009 markbates
3
+ Copyright (c) 2009 Mark Bates
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
data/README CHANGED
@@ -1,3 +1,89 @@
1
- README
2
- ========================================================================
3
- warp_drive was developed by: markbates
1
+ =Warp Drive
2
+
3
+ ==What is Warp Drive?
4
+
5
+ Warp Drive is what Rails Engines wish they could be, and more! They kick Rails templates in the ass, and they beat keeping an ever evolving base Rails app up to date.
6
+
7
+ ===What are Rails Engines?
8
+
9
+ Rails Engines allow you to package up some of a Rails app (controllers, models, views, routes, libs) and put them in a plugin that can be included into a new Rails app, thereby giving it the functionality you had in the engine. That sounds good, but what about the downsides of using an engine? Well, you can't override or extend any of the functionality from the engine in your main application. You can hack at the plugin, but now you've made it difficult to update. So what do you do if you want to add or alter a method to a controller or model? What do you do if you want to change the look and feel of a view? You have to copy everything into your main application. Boo!
10
+
11
+ Rails Engines also don't allow you to package up migrations, assets, plugins, initializers, etc... All the fun stuff that you've come to know and love about a Rails application.
12
+
13
+ ===Enter the Warp Drive!
14
+
15
+ So what is a Warp Drive? Great question. To put it simply a Warp Drive is a standard, full featured, Rails application that you can easily bundle up into a Ruby Gem, and include into another Rails app. That second Rails app now has all the power of the first Rails. That is all there is to it.
16
+
17
+ ==Creating a Warp Drive.
18
+
19
+ Let's assume we have an application that implements AuthLogic for handling user registration/authentication. We have controllers, views, models, plugins, initializers, configurations, migrations, tasks, etc... it's a full featured fully functional Rails application, we call it authenticator.
20
+
21
+ We want to turn our authenticator application into a Warp Drive. We can do it in three simple steps, the first two steps you only need to do the first time, to set everything up.
22
+
23
+ # <code>$ gem install warp_drive</code>
24
+ # <code>$ warpify</code>
25
+ That will add a little bit of code to your <code>Rakefile</code>. That code simply requires the Warp Drive gem, and gives you hooks to configure the gem of your Warp Drive application.
26
+ # $ <code>rake warp_drive:compile</code> (<code>rake warp_drive:install</code>)
27
+ This will either compile your gem for your (<code>warp_drive:compile</code>) or compile and install your gem (<code>warp_drive:install</code>)
28
+
29
+ That's it! You should now have your Rails application bundled up and/or installed as a RubyGem!
30
+
31
+ ==Using a Warp Drive.
32
+
33
+ With your fancy new Warp Drive, authenticator, built and installed how do you use it in that new application your building? Again, it's stupid easy, and it only takes one step, that only needs to be run once:
34
+
35
+ # $ install_warp_drive authenticator
36
+
37
+ That will put a few lines of code in your <code>Rakefile</code>, so you have access to all the <code>Rakefile</code> tasks in your Warp Drive, and a line in your <code>config/environment.rb</code> so that it will load your Warp Drive when you launch your application.
38
+
39
+ That's it! You're done. Now you can run <code>rake db:migrate</code> to run the migrations from both your Warp Drive and your new application. Enjoy!
40
+
41
+ ==Overriding, Extending, and Other Such Fun Things
42
+
43
+ ===Overriding and Extending
44
+
45
+ You've been enjoying your new Warp Drive back application for a little while now, but you decide you really need to change an action in your controller, how do you go about that? Simple, just like you would any normal alteration to a Ruby class.
46
+
47
+ Example:
48
+ Here is what the action looks like in our Warp Drive UsersController:
49
+
50
+ def new
51
+ @user = User.new
52
+ end
53
+
54
+ In our new application we can just open up the UsersController like this:
55
+
56
+ class UsersController < ApplicationController
57
+
58
+ def new_with_default_name
59
+ new_without_default_name
60
+ @user.login = 'default_name'
61
+ end
62
+
63
+ alias_method_chain :new, :default_name
64
+
65
+ end
66
+
67
+ Viola! The same works for any thing else in the system, models, libs, etc... In our example we used <code>alias_method_chain</code> to retain the original method, but we could have completely rewritten the method as well.
68
+
69
+ You can also plop in a new view and it will override the view that was in your Warp Drive. The sky is really the limit.
70
+
71
+ ===Assets
72
+
73
+ You can easily bundle assets from your public directory in your Warp Drive. Just make sure they are in folders called <code>warp_drive</code>. Those folders will then be symlinked to your new project's public directory when the application starts up.
74
+
75
+ ===Keep Those Rake Tasks Private!
76
+
77
+ We all them, Rake tasks we have created to help us do all sorts of things, and we usually don't want them to ship. Well, Warp Drive has you covered there. Just place your tasks in folders called <code>private</code> and Bob's your uncle they won't be available in the compiled gem.
78
+
79
+ ====Example:
80
+
81
+ lib/
82
+ tasks/
83
+ foo.rake
84
+ private/
85
+ bar.rake
86
+
87
+ In this example <code>foo.rake</code> will be available to clients of your Warp Drive, but <code>bar.rake</code> will not be.
88
+
89
+ Copyright (c) 2009 Mark Bates
@@ -37,6 +37,6 @@ module WarpDrive
37
37
  load_view_paths
38
38
  load_application_classes
39
39
  disable_dependency_loading
40
- }
40
+ } # :nodoc:
41
41
 
42
42
  end
@@ -1,5 +1,5 @@
1
- module ActiveRecord
2
- class Migrator
1
+ module ActiveRecord # :nodoc:
2
+ class Migrator # :nodoc:
3
3
 
4
4
  migs = []
5
5
  migs << ActiveRecord::Migrator.new(:up, WarpDrive::Path.db.migrate).migrations
@@ -1,5 +1,5 @@
1
1
  module WarpDrive
2
- module Procs
2
+ module Procs # :nodoc:
3
3
 
4
4
  class << self
5
5
 
@@ -1,5 +1,5 @@
1
- module Rails
2
- class Initializer
1
+ module Rails # :nodoc:
2
+ class Initializer # :nodoc:
3
3
 
4
4
  WarpDrive::RAILS_INIT_METHODS.each do |meth|
5
5
  alias_method "#{meth}_without_warp_drive", meth
@@ -1,11 +1,11 @@
1
1
  module WarpDrive
2
2
  extend self
3
3
  # --- RAILS --- #
4
- def load_plugins
4
+ def load_plugins # :nodoc:
5
5
  Rails.configuration.plugin_paths << WarpDrive::Path.vendor.plugins.to_s
6
6
  end
7
7
 
8
- def set_load_path
8
+ def set_load_path # :nodoc:
9
9
  Rails.configuration.load_paths = [Rails.configuration.load_paths,
10
10
  WarpDrive::Path.lib.to_s,
11
11
  WarpDrive::Path.app.to_s,
@@ -14,7 +14,7 @@ module WarpDrive
14
14
  WarpDrive::Path.app.helpers.to_s].flatten
15
15
  end
16
16
 
17
- def load_gems
17
+ def load_gems # :nodoc:
18
18
  begin
19
19
  require('gemtronics')
20
20
 
@@ -31,22 +31,22 @@ module WarpDrive
31
31
 
32
32
  end
33
33
 
34
- def initialize_routing
34
+ def initialize_routing # :nodoc:
35
35
  ActionController::Routing::Routes.add_configuration_file(WarpDrive::Path.config.routes.rb.to_s)
36
36
  end
37
37
 
38
- def load_view_paths
38
+ def load_view_paths # :nodoc:
39
39
  ActionController::Base.view_paths = [ActionController::Base.view_paths,
40
40
  WarpDrive::Path.app.views.to_s].flatten
41
41
  ActionMailer::Base.view_paths = ActionController::Base.view_paths
42
42
  end
43
43
 
44
- def initialize_dependency_mechanism
44
+ def initialize_dependency_mechanism # :nodoc:
45
45
  ActiveSupport::Dependencies.class_eval do
46
46
  class << self
47
47
  alias_method :require_or_load_without_warp_drive, :require_or_load
48
48
 
49
- def require_or_load_with_warp_drive(file_name, const_path = nil)
49
+ def require_or_load_with_warp_drive(file_name, const_path = nil) # :nodoc:
50
50
  sr_file_name = file_name.gsub(RAILS_ROOT, WarpDrive::ROOT)
51
51
  require_or_load_without_warp_drive(sr_file_name, const_path) if File.exists?(sr_file_name)
52
52
  require_or_load_without_warp_drive(file_name, const_path)
@@ -57,9 +57,9 @@ module WarpDrive
57
57
  end
58
58
  end
59
59
 
60
- def initialize_database
60
+ def initialize_database # :nodoc:
61
61
  Rails.configuration.instance_eval do
62
- def database_configuration
62
+ def database_configuration # :nodoc:
63
63
  require 'erb'
64
64
  db_opts = {}
65
65
 
@@ -76,20 +76,20 @@ module WarpDrive
76
76
  end # Rails.configuration.instance_eval
77
77
  end
78
78
 
79
- def load_application_initializers
79
+ def load_application_initializers # :nodoc:
80
80
  Dir[File.join(WarpDrive::Path.config.initializers.to_s, '**', '*.rb')].sort.each do |initializer|
81
81
  initializer = File.expand_path(initializer)
82
82
  load(initializer)
83
83
  end
84
84
  end
85
85
 
86
- def initialize_database_middleware
86
+ def initialize_database_middleware # :nodoc:
87
87
  require File.join(File.dirname(__FILE__), 'migration_override')
88
88
  end
89
89
 
90
90
  # --- Non-RAILS --- #
91
91
 
92
- def load_rake_tasks
92
+ def load_rake_tasks # :nodoc:
93
93
  require 'rake'
94
94
  Dir.glob(File.join(WarpDrive::Path.lib.tasks.to_s, '**', '*.*')).sort.each do |task|
95
95
  load File.expand_path(task) unless task.match(/\/private\//)
@@ -101,7 +101,7 @@ module WarpDrive
101
101
  end
102
102
  end
103
103
 
104
- def load_assets
104
+ def load_assets # :nodoc:
105
105
  Dir.glob(File.join(WarpDrive::ROOT, 'public', '**', 'warp_drive', '**', '*.*')).sort.each do |f|
106
106
  f.match(/public\/(.*warp_drive)/)
107
107
  base_path = $1
@@ -115,7 +115,7 @@ module WarpDrive
115
115
  end
116
116
  end
117
117
 
118
- def method_missing(sym, *args)
118
+ def method_missing(sym, *args) # :nodoc:
119
119
  # puts "Tried to call WarpDrive.#{sym} but it doesn't exist!"
120
120
  end
121
121
 
@@ -2,6 +2,19 @@ module WarpDrive
2
2
 
3
3
  class << self
4
4
 
5
+ # Use this method in your Rakefile to configure the resulting
6
+ # Warp Drive gem.
7
+ #
8
+ # Example:
9
+ # WarpDrive.configure do |config|
10
+ # # Define your gem spec settings here:
11
+ # config.gem.version = "1.2.3"
12
+ # config.gem.email = 'me@example.com'
13
+ # config.gem.homepage = 'http://www.example.com'
14
+ #
15
+ # # Add your gem dependencies here:
16
+ # config.dependencies = {'warp_drive' => '>=0.1.0'}
17
+ # end
5
18
  def configure
6
19
  yield configatron.warp_drive
7
20
  end
@@ -1,4 +1,9 @@
1
1
  module WarpDrive
2
+ # This class allows you to easily get the location of any file or path in a Warp Drive gem.
3
+ #
4
+ # Example:
5
+ # WarpDrive::Path.app.controllers.application_controller.rb
6
+ # # => "/usr/local/lib/ruby/gems/1.8/gems/my_warp_drive_gem-1.2.3/lib/app/controllers/application_controller.rb"
2
7
  class Path
3
8
 
4
9
  attr_accessor :parent
@@ -1,4 +1,4 @@
1
- class WarpDriveGemGenerator < Genosaurus
1
+ class WarpDriveGemGenerator < Genosaurus # :nodoc:
2
2
  require_param :app
3
3
  require_param :out_dir
4
4
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: warp_drive
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - markbates
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-08-31 00:00:00 -04:00
12
+ date: 2009-09-03 00:00:00 -04:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  requirements: []
88
88
 
89
89
  rubyforge_project: magrathea
90
- rubygems_version: 1.3.4
90
+ rubygems_version: 1.3.5
91
91
  signing_key:
92
92
  specification_version: 3
93
93
  summary: warp_drive