warp_drive 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2009 markbates
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README ADDED
@@ -0,0 +1,3 @@
1
+ README
2
+ ========================================================================
3
+ warp_drive was developed by: markbates
@@ -0,0 +1,40 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ # adds a warp drive to a rails project
4
+
5
+ warp_drive_name = ARGV[0]
6
+
7
+ if warp_drive_name.nil?
8
+ puts "You must specify the name of a warp drive you want to install!"
9
+ exit(1)
10
+ end
11
+
12
+ rake_file_path = File.join(FileUtils.pwd, 'Rakefile')
13
+ rake_file = File.read(rake_file_path)
14
+ env_file_path = File.join(FileUtils.pwd, 'config', 'environment.rb')
15
+ env_file = File.read(env_file_path)
16
+
17
+ if rake_file.match(/require 'warp_drive\/tasks'/) && env_file.match(/require '#{warp_drive_name}\/boot'/)
18
+ puts 'We have already installed this Warp Drive, so there is nothing to do.'
19
+ else
20
+ print 'Please hold while we install your Warp Drive...'
21
+
22
+ File.open(rake_file_path, 'a') do |f|
23
+ f.puts %{
24
+ begin
25
+ require '#{warp_drive_name}/tasks'
26
+ rescue Exception => e
27
+ puts e.message
28
+ end
29
+ }
30
+ end
31
+
32
+ File.open(env_file_path, 'w') do |f|
33
+ f.puts env_file.gsub(%{require File.join(File.dirname(__FILE__), 'boot')}, %{
34
+ require File.join(File.dirname(__FILE__), 'boot')
35
+ require '#{warp_drive_name}/boot'
36
+ })
37
+ end
38
+
39
+ puts 'completed!'
40
+ end
data/bin/warpify ADDED
@@ -0,0 +1,27 @@
1
+ #!/usr/local/bin/ruby
2
+
3
+ # turns a rails project into a warp drive
4
+ require 'fileutils'
5
+
6
+ rake_file_path = File.join(FileUtils.pwd, 'Rakefile')
7
+ rake_file = File.read(rake_file_path)
8
+
9
+ unless rake_file.match(/require 'warp_drive\/tasks'/)
10
+ print 'Please hold we are converting your application to a Warp Drive...'
11
+ File.open(rake_file_path, 'a') do |f|
12
+ f.puts %{
13
+ require 'warp_drive/tasks'
14
+
15
+ WarpDrive.configure do |config|
16
+ # Define your gem spec settings here:
17
+ config.gem.version = "0.0.1"
18
+
19
+ # Add your gem dependencies here:
20
+ config.dependencies = {'warp_drive' => '>=0.1.0'}
21
+ end
22
+ }
23
+ end
24
+ puts 'completed!'
25
+ else
26
+ puts 'Your application is already a Warp Drive, so there is nothing to do.'
27
+ end
@@ -0,0 +1,22 @@
1
+ namespace :warp_drive do
2
+
3
+ task :compile do
4
+ path = File.expand_path(File.join(File.dirname(__FILE__), '..', 'warp_drive', 'warp_drive_gem_generator'))
5
+ require path
6
+ $genosaurus_output_directory = File.join(pwd, 'tmp', File.basename(pwd))
7
+ FileUtils.rm_rf($genosaurus_output_directory, :verbose => false)
8
+ WarpDriveGemGenerator.run('APP' => File.basename(pwd), 'OUT_DIR' => File.join(pwd, 'tmp', File.basename(pwd)))
9
+
10
+ sh "cd #{$genosaurus_output_directory}; rake package"
11
+ FileUtils.rm_rf($genosaurus_output_directory, :verbose => false)
12
+ # FileUtils.rm_rf(File.join(pwd, 'pkg'), :verbose => true)
13
+ # mv File.join($genosaurus_output_directory, 'pkg'), File.join(pwd, 'pkg')
14
+ end
15
+
16
+ task :install => :compile do
17
+ Dir[File.join($genosaurus_output_directory, 'pkg', '*.gem')].each do |g|
18
+ sh "gem install #{g}"
19
+ end
20
+ end
21
+
22
+ end
@@ -0,0 +1,42 @@
1
+ module WarpDrive
2
+
3
+ RAILS_INIT_METHODS = %w{
4
+ install_gem_spec_stubs
5
+ set_load_path
6
+ require_frameworks
7
+ set_autoload_paths
8
+ add_plugin_load_paths
9
+ load_environment
10
+ preload_frameworks
11
+ initialize_encoding
12
+ initialize_database
13
+ initialize_cache
14
+ initialize_framework_caches
15
+ initialize_logger
16
+ initialize_framework_logging
17
+ initialize_dependency_mechanism
18
+ initialize_whiny_nils
19
+ initialize_time_zone
20
+ initialize_i18n
21
+ initialize_framework_settings
22
+ initialize_framework_views
23
+ initialize_metal
24
+ add_support_load_paths
25
+ check_for_unbuilt_gems
26
+ load_plugins
27
+ add_gem_load_paths
28
+ load_gems
29
+ check_gem_dependencies
30
+ gems_dependencies_loaded
31
+ load_application_initializers
32
+ after_initialize
33
+ initialize_database_middleware
34
+ prepare_dispatcher
35
+ initialize_routing
36
+ load_observers
37
+ load_view_paths
38
+ load_application_classes
39
+ disable_dependency_loading
40
+ }
41
+
42
+ end
@@ -0,0 +1,14 @@
1
+ module ActiveRecord
2
+ class Migrator
3
+
4
+ migs = []
5
+ migs << ActiveRecord::Migrator.new(:up, WarpDrive::Path.db.migrate).migrations
6
+ migs << ActiveRecord::Migrator.new(:up, File.join(RAILS_ROOT, 'db', 'migrate')).migrations
7
+ migs.flatten!
8
+
9
+ define_method('migrations') do
10
+ return migs
11
+ end
12
+
13
+ end
14
+ end
@@ -0,0 +1,32 @@
1
+ module WarpDrive
2
+ module Procs
3
+
4
+ class << self
5
+
6
+ def load_plugins
7
+ Proc.new do
8
+ @plugin_loader = nil
9
+ WarpDrive.load_plugins
10
+ plugin_loader.add_plugin_load_paths
11
+ load_plugins_without_warp_drive
12
+ end
13
+ end
14
+
15
+ def initialize_dependency_mechanism
16
+ Proc.new do
17
+ initialize_dependency_mechanism_without_warp_drive
18
+ WarpDrive.initialize_dependency_mechanism
19
+ end
20
+ end
21
+
22
+ def method_missing(meth, *args)
23
+ Proc.new do
24
+ WarpDrive.send(meth)
25
+ send("#{meth}_without_warp_drive")
26
+ end
27
+ end
28
+
29
+ end
30
+
31
+ end # Procs
32
+ end # WarpDrive
@@ -0,0 +1,11 @@
1
+ module Rails
2
+ class Initializer
3
+
4
+ WarpDrive::RAILS_INIT_METHODS.each do |meth|
5
+ alias_method "#{meth}_without_warp_drive", meth
6
+ define_method("#{meth}_with_warp_drive", WarpDrive::Procs.send(meth))
7
+ alias_method meth, "#{meth}_with_warp_drive"
8
+ end
9
+
10
+ end # Initializer
11
+ end # Rails
@@ -0,0 +1,119 @@
1
+ module WarpDrive
2
+ extend self
3
+ # --- RAILS --- #
4
+ def load_plugins
5
+ Rails.configuration.plugin_paths << WarpDrive::Path.vendor.plugins.to_s
6
+ end
7
+
8
+ def set_load_path
9
+ Rails.configuration.load_paths = [Rails.configuration.load_paths,
10
+ WarpDrive::Path.lib.to_s,
11
+ WarpDrive::Path.app.to_s,
12
+ WarpDrive::Path.app.models.to_s,
13
+ WarpDrive::Path.app.controllers.to_s,
14
+ WarpDrive::Path.app.helpers.to_s].flatten
15
+ end
16
+
17
+ def load_gems
18
+ begin
19
+ require('gemtronics')
20
+
21
+ sr_gem_path = WarpDrive::Path.config.gemtronics.rb
22
+ Gemtronics.load(sr_gem_path) if File.exists?(sr_gem_path)
23
+
24
+ local_path = File.join(RAILS_ROOT, 'config', 'gemtronics.rb')
25
+ Gemtronics.load(local_path) if File.exists?(local_path)
26
+ Gemtronics.require_gems(RAILS_ENV, :verbose => false)
27
+ rescue Exception => e
28
+ puts "Problems loading Gemtronics: #{e.message}"
29
+ puts "This probably means you aren't using Gemtronics."
30
+ end
31
+
32
+ end
33
+
34
+ def initialize_routing
35
+ ActionController::Routing::Routes.add_configuration_file(WarpDrive::Path.config.routes.rb.to_s)
36
+ end
37
+
38
+ def load_view_paths
39
+ ActionController::Base.view_paths = [ActionController::Base.view_paths,
40
+ WarpDrive::Path.app.views.to_s].flatten
41
+ ActionMailer::Base.view_paths = ActionController::Base.view_paths
42
+ end
43
+
44
+ def initialize_dependency_mechanism
45
+ ActiveSupport::Dependencies.class_eval do
46
+ class << self
47
+ alias_method :require_or_load_without_warp_drive, :require_or_load
48
+
49
+ def require_or_load_with_warp_drive(file_name, const_path = nil)
50
+ sr_file_name = file_name.gsub(RAILS_ROOT, WarpDrive::ROOT)
51
+ require_or_load_without_warp_drive(sr_file_name, const_path) if File.exists?(sr_file_name)
52
+ require_or_load_without_warp_drive(file_name, const_path)
53
+ end
54
+
55
+ alias_method :require_or_load, :require_or_load_with_warp_drive
56
+ end
57
+ end
58
+ end
59
+
60
+ def initialize_database
61
+ Rails.configuration.instance_eval do
62
+ def database_configuration
63
+ require 'erb'
64
+ db_opts = {}
65
+
66
+ [WarpDrive::Path.config.database.yml.to_s,
67
+ File.join(RAILS_ROOT, 'config', 'database.yml')].each do |yml_path|
68
+ db_opts.recursive_merge!(YAML::load(ERB.new(File.read(yml_path)).result)) if File.exists?(yml_path)
69
+ end
70
+
71
+ db_opts
72
+ end # database_configuration
73
+ end # Rails.configuration.instance_eval
74
+ end
75
+
76
+ def load_application_initializers
77
+ Dir[File.join(WarpDrive::Path.config.initializers.to_s, '**', '*.rb')].sort.each do |initializer|
78
+ initializer = File.expand_path(initializer)
79
+ load(initializer)
80
+ end
81
+ end
82
+
83
+ def initialize_database_middleware
84
+ require File.join(File.dirname(__FILE__), 'migration_override')
85
+ end
86
+
87
+ # --- Non-RAILS --- #
88
+
89
+ def load_rake_tasks
90
+ require 'rake'
91
+ Dir.glob(File.join(WarpDrive::Path.lib.tasks.to_s, '**', '*.*')).sort.each do |task|
92
+ load File.expand_path(task) unless task.match(/\/private\//)
93
+ end
94
+ Dir.glob(File.join(WarpDrive::Path.vendor.plugins.to_s, '*')).sort.each do |plugin|
95
+ Dir.glob(File.join(plugin, 'tasks', '**', '*.*')).sort.each do |task|
96
+ load File.expand_path(task) unless task.match(/\/private\//)
97
+ end
98
+ end
99
+ end
100
+
101
+ def load_assets
102
+ Dir.glob(File.join(WarpDrive::ROOT, 'public', '**', 'warp_drive', '**', '*.*')).sort.each do |f|
103
+ f.match(/public\/(.*warp_drive)/)
104
+ base_path = $1
105
+ rails_path = File.join(RAILS_ROOT, 'public', base_path)
106
+ FileUtils.rm_rf(rails_path, :verbose => false) if File.exists?(rails_path)
107
+ f.match(/(^.+public\/.*warp_drive)/)
108
+ begin
109
+ FileUtils.ln_sf($1, rails_path)
110
+ rescue Exception => e
111
+ end
112
+ end
113
+ end
114
+
115
+ def method_missing(sym, *args)
116
+ # puts "Tried to call WarpDrive.#{sym} but it doesn't exist!"
117
+ end
118
+
119
+ end
@@ -0,0 +1,13 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'warp_drive')
2
+
3
+ unless defined?(WARP_DRIVE_INITIALIZED)
4
+
5
+ wd_path = File.join(File.dirname(__FILE__), 'boot')
6
+
7
+ [:workers, :method_list, :procs, :rails_init].each do |file|
8
+ require File.join(wd_path, file.to_s)
9
+ end
10
+
11
+ WarpDrive.load_assets
12
+
13
+ end
@@ -0,0 +1,11 @@
1
+ module WarpDrive
2
+
3
+ class << self
4
+
5
+ def configure
6
+ yield configatron.warp_drive
7
+ end
8
+
9
+ end
10
+
11
+ end
@@ -0,0 +1,45 @@
1
+ module WarpDrive
2
+ class Path
3
+
4
+ attr_accessor :parent
5
+ attr_accessor :path
6
+
7
+ def initialize(parent, path)
8
+ self.parent = parent
9
+ self.path = path.to_s
10
+ end
11
+
12
+ def method_missing(sym, *args)
13
+ if sym == :rb || sym == :yml
14
+ return self.to_s + ".#{sym}"
15
+ else
16
+ WarpDrive::Path.new(self, sym)
17
+ end
18
+ end
19
+
20
+ def to_s
21
+ paths = [self.path]
22
+ par = self.parent
23
+ until par.nil?
24
+ paths << par.path
25
+ par = par.parent
26
+ end
27
+ paths << File.join(WarpDrive::ROOT)
28
+ path = File.expand_path(File.join(paths.reverse))
29
+ return path
30
+ end
31
+
32
+ def /(other)
33
+ File.expand_path(File.join(self.to_s, other.to_s))
34
+ end
35
+
36
+ class << self
37
+
38
+ def method_missing(sym, *args)
39
+ WarpDrive::Path.new(nil, sym)
40
+ end
41
+
42
+ end
43
+
44
+ end # Path
45
+ end # WarpDrive
@@ -0,0 +1,4 @@
1
+ require File.join(File.dirname(__FILE__), '..', 'warp_drive')
2
+ Dir.glob(File.join(File.dirname(__FILE__), '..', 'tasks', '**/*.rake')).each do |f|
3
+ load File.expand_path(f)
4
+ end
@@ -0,0 +1,12 @@
1
+ require 'rubygems'
2
+ require 'gemstub'
3
+
4
+ Gemstub.gem_spec do |s|
5
+ <% configatron.warp_drive.gem.configatron_keys.each do |key| -%>
6
+ s.<%= key %> = "<%= configatron.warp_drive.gem.retrieve(key) %>"
7
+ <% end %>
8
+ <% configatron.warp_drive.dependencies.each do |name, version| -%>
9
+ s.add_dependency('<%= name %>', '<%= version %>')
10
+ <% end %>
11
+ s.files = FileList['lib/**/*.*', 'bin/**/*.*']
12
+ end
@@ -0,0 +1,2 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '<%= app %>'))
2
+ require 'warp_drive/boot'
@@ -0,0 +1,12 @@
1
+ require File.expand_path(File.join(File.dirname(__FILE__), '..', '<%= app %>'))
2
+ require 'rake'
3
+
4
+ Dir.glob(File.join(WarpDrive::Path.lib.tasks.to_s, '**', '*.*')).sort.each do |task|
5
+ load File.expand_path(task) unless task.match(/\/private\//)
6
+ end
7
+
8
+ Dir.glob(File.join(WarpDrive::Path.vendor.plugins.to_s, '*')).sort.each do |plugin|
9
+ Dir.glob(File.join(plugin, 'tasks', '**', '*.*')).sort.each do |task|
10
+ load File.expand_path(task) unless task.match(/\/private\//)
11
+ end
12
+ end
@@ -0,0 +1,5 @@
1
+ module WarpDrive
2
+ ROOT = File.dirname(__FILE__)
3
+ end
4
+
5
+ require 'warp_drive'
@@ -0,0 +1,53 @@
1
+ class WarpDriveGemGenerator < Genosaurus
2
+ require_param :app
3
+ require_param :out_dir
4
+
5
+ def before_generate
6
+ copy_major_directories
7
+ remove_private_rake_tasks
8
+ remove_private_assets
9
+ remove_private_configs
10
+ end
11
+
12
+ private
13
+ def copy_major_directories
14
+ %w{app config lib public vendor}.each do |dir|
15
+ Dir[File.join(pwd, dir, '**', '*.*')].each do |f|
16
+ self.copy(f, f.gsub(pwd, 'lib'))
17
+ end
18
+ end
19
+
20
+ %w{db}.each do |dir|
21
+ Dir[File.join(pwd, dir, '**', '*.rb')].each do |f|
22
+ self.copy(f, f.gsub(pwd, 'lib'))
23
+ end
24
+ end
25
+ end
26
+
27
+ def remove_private_rake_tasks
28
+ Dir[File.join(out_lib_dir, 'lib', 'tasks', '**', 'private')].each do |f|
29
+ rm_rf(f, :verbose => false)
30
+ end
31
+ end
32
+
33
+ def remove_private_assets
34
+ pub_path = File.join(out_lib_dir, 'public')
35
+ Dir[File.join(pub_path, '**', '*.*')].each do |f|
36
+ tpath = f.gsub(pub_path, '')
37
+ unless tpath.match(/\/warp_drive\//)
38
+ rm(f, :verbose => false)
39
+ end
40
+ end
41
+ end
42
+
43
+ def remove_private_configs
44
+ %w{boot.rb environment.rb}.each do |f|
45
+ rm(File.join(out_lib_dir, 'config', f), :verbose => false)
46
+ end
47
+ end
48
+
49
+ def out_lib_dir
50
+ File.join(self.out_dir, 'lib')
51
+ end
52
+
53
+ end
data/lib/warp_drive.rb ADDED
@@ -0,0 +1,23 @@
1
+ class Hash # :nodoc:
2
+
3
+ def recursive_merge!(other) # :nodoc:
4
+ other.each do |key, value|
5
+ myval = self[key]
6
+ if value.is_a?(Hash) && myval.is_a?(Hash)
7
+ myval.recursive_merge!(value)
8
+ else
9
+ self[key] = value
10
+ end
11
+ end
12
+ self
13
+ end # recursive_merge!
14
+
15
+ end # Hash
16
+
17
+
18
+ require 'configatron'
19
+ require 'genosaurus'
20
+
21
+ path = File.join(File.dirname(__FILE__), 'warp_drive')
22
+ require File.join(path, 'configure.rb')
23
+ require File.join(path, 'path.rb')
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: warp_drive
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - markbates
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-31 00:00:00 -04:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: configatron
17
+ type: :runtime
18
+ version_requirement:
19
+ version_requirements: !ruby/object:Gem::Requirement
20
+ requirements:
21
+ - - ">="
22
+ - !ruby/object:Gem::Version
23
+ version: "0"
24
+ version:
25
+ - !ruby/object:Gem::Dependency
26
+ name: genosaurus
27
+ type: :runtime
28
+ version_requirement:
29
+ version_requirements: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: "0"
34
+ version:
35
+ description: Screw Rails Engines! Why not install a Warp Drive! Completely bundle up an ENTIRE Rails application into a gem, then load it into another application! It's that easy!
36
+ email: ""
37
+ executables:
38
+ - warpify
39
+ - install_warp_drive
40
+ extensions: []
41
+
42
+ extra_rdoc_files:
43
+ - README
44
+ - LICENSE
45
+ files:
46
+ - lib/tasks/compile.rake
47
+ - lib/warp_drive/boot/method_list.rb
48
+ - lib/warp_drive/boot/migration_override.rb
49
+ - lib/warp_drive/boot/procs.rb
50
+ - lib/warp_drive/boot/rails_init.rb
51
+ - lib/warp_drive/boot/workers.rb
52
+ - lib/warp_drive/boot.rb
53
+ - lib/warp_drive/configure.rb
54
+ - lib/warp_drive/path.rb
55
+ - lib/warp_drive/tasks.rb
56
+ - lib/warp_drive/templates/lib/%=app%/boot.rb.template
57
+ - lib/warp_drive/templates/lib/%=app%/tasks.rb.template
58
+ - lib/warp_drive/templates/lib/%=app%.rb.template
59
+ - lib/warp_drive/templates/Rakefile.template
60
+ - lib/warp_drive/warp_drive_gem_generator.rb
61
+ - lib/warp_drive.rb
62
+ - README
63
+ - LICENSE
64
+ has_rdoc: true
65
+ homepage: ""
66
+ licenses: []
67
+
68
+ post_install_message:
69
+ rdoc_options: []
70
+
71
+ require_paths:
72
+ - lib
73
+ required_ruby_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: "0"
78
+ version:
79
+ required_rubygems_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: "0"
84
+ version:
85
+ requirements: []
86
+
87
+ rubyforge_project: magrathea
88
+ rubygems_version: 1.3.4
89
+ signing_key:
90
+ specification_version: 3
91
+ summary: warp_drive
92
+ test_files: []
93
+