Module: WarpDrive

Extended by:
WarpDrive
Included in:
WarpDrive
Defined in:
lib/warp_drive/path.rb,
lib/warp_drive/configure.rb,
lib/warp_drive/boot/procs.rb,
lib/warp_drive/boot/workers.rb,
lib/warp_drive/boot/method_list.rb

Defined Under Namespace

Modules: Procs Classes: Path

Constant Summary collapse

RAILS_INIT_METHODS =
%w{
  install_gem_spec_stubs
  set_load_path
  require_frameworks
  set_autoload_paths
  add_plugin_load_paths
  load_environment
  preload_frameworks
  initialize_encoding
  initialize_database
  initialize_cache
  initialize_framework_caches
  initialize_logger
  initialize_framework_logging
  initialize_dependency_mechanism
  initialize_whiny_nils
  initialize_time_zone
  initialize_i18n
  initialize_framework_settings
  initialize_framework_views
  initialize_metal
  add_support_load_paths
  check_for_unbuilt_gems
  load_plugins
  add_gem_load_paths
  load_gems
  check_gem_dependencies
  gems_dependencies_loaded
  load_application_initializers
  after_initialize
  initialize_database_middleware
  prepare_dispatcher
  initialize_routing
  load_observers
  load_view_paths
  load_application_classes
  disable_dependency_loading
}

Class Method Summary collapse

Instance Method Summary collapse

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(sym, *args) ⇒ Object

:nodoc:



129
130
131
# File 'lib/warp_drive/boot/workers.rb', line 129

def method_missing(sym, *args) # :nodoc:
  # puts "Tried to call WarpDrive.#{sym} but it doesn't exist!"
end

Class Method Details

.configure {|configatron.warp_drive| ... } ⇒ Object

Use this method in your Rakefile to configure the resulting Warp Drive gem.

Example:

WarpDrive.configure do |config|
  # Define your gem spec settings here:
  config.gem.version = "1.2.3"
  config.gem.email = '[email protected]'
  config.gem.homepage = 'http://www.example.com'

  # Add your gem dependencies here:
  config.dependencies = {'warp_drive' => '>=0.1.0'}
end

Yields:

  • (configatron.warp_drive)


18
19
20
# File 'lib/warp_drive/configure.rb', line 18

def configure
  yield configatron.warp_drive
end

Instance Method Details

#initialize_databaseObject

:nodoc:



71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/warp_drive/boot/workers.rb', line 71

def initialize_database # :nodoc:
  Rails.configuration.instance_eval do
    def database_configuration # :nodoc:
      require 'erb'
      db_opts = {}
      
      [WarpDrive::Path.config.database.yml.to_s, 
       File.join(RAILS_ROOT, 'config', 'database.yml')].each do |yml_path|
         if File.exists?(yml_path)
           opts = YAML::load(ERB.new(File.read(yml_path)).result)
           db_opts.recursive_merge!(opts) if opts
         end
      end
      
      db_opts
    end # database_configuration
  end # Rails.configuration.instance_eval
end

#initialize_database_middlewareObject

:nodoc:



97
98
99
# File 'lib/warp_drive/boot/workers.rb', line 97

def initialize_database_middleware # :nodoc:
  require File.join(File.dirname(__FILE__), 'migration_override')
end

#initialize_dependency_mechanismObject

:nodoc:



55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/warp_drive/boot/workers.rb', line 55

def initialize_dependency_mechanism # :nodoc:
  ActiveSupport::Dependencies.class_eval do
    class << self
      alias_method :require_or_load_without_warp_drive, :require_or_load

      def require_or_load_with_warp_drive(file_name, const_path = nil) # :nodoc:
        sr_file_name = file_name.gsub(RAILS_ROOT, WarpDrive::ROOT)
        require_or_load_without_warp_drive(sr_file_name, const_path) if File.exists?(sr_file_name)
        require_or_load_without_warp_drive(file_name, const_path)
      end
    
      alias_method :require_or_load, :require_or_load_with_warp_drive
    end
  end
end

#initialize_routingObject

:nodoc:



34
35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/warp_drive/boot/workers.rb', line 34

def initialize_routing # :nodoc:
  # this method is a copy/paste of the method of the same name in the rails 2.3.4 initializer.rb
  # we're doing this to be able to insert the warp drive routes at the correct place in the 
  # routes list to be able to override them with client applications
  return unless Rails.configuration.frameworks.include?(:action_controller)

  ActionController::Routing.controller_paths += Rails.configuration.controller_paths
  ActionController::Routing::Routes.add_configuration_file(Rails.configuration.routes_configuration_file)
  
  # this is the only bit we've changed from the rails 2.3.4 initializer.rb
  ActionController::Routing::Routes.add_configuration_file(WarpDrive::Path.config.routes.rb.to_s)
  
  ActionController::Routing::Routes.reload!
end

#load_application_initializersObject

:nodoc:



90
91
92
93
94
95
# File 'lib/warp_drive/boot/workers.rb', line 90

def load_application_initializers # :nodoc:
  Dir[File.join(WarpDrive::Path.config.initializers.to_s, '**', '*.rb')].sort.each do |initializer|
    initializer = File.expand_path(initializer)
    load(initializer)
  end
end

#load_assetsObject

:nodoc:



115
116
117
118
119
120
121
122
123
124
125
126
127
# File 'lib/warp_drive/boot/workers.rb', line 115

def load_assets # :nodoc:
  Dir.glob(File.join(WarpDrive::ROOT, 'public', '**', 'warp_drive', '**', '*.*')).sort.each do |f|
    f.match(/public\/(.*warp_drive)/)
    base_path = $1
    rails_path = File.join(RAILS_ROOT, 'public', base_path)
    FileUtils.rm_rf(rails_path, :verbose => false) if File.exists?(rails_path)
    f.match(/(^.+public\/.*warp_drive)/)
    begin
      FileUtils.ln_sf($1, rails_path)
    rescue Exception => e
    end
  end
end

#load_gemsObject

:nodoc:



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/warp_drive/boot/workers.rb', line 17

def load_gems # :nodoc:
  begin
    require('gemtronics')

    sr_gem_path = WarpDrive::Path.config.gemtronics.rb
    Gemtronics.load(sr_gem_path) if File.exists?(sr_gem_path)

    local_path = File.join(RAILS_ROOT, 'config', 'gemtronics.rb')
    Gemtronics.load(local_path) if File.exists?(local_path)
    Gemtronics.require_gems(RAILS_ENV, :verbose => false)
  rescue Exception => e
    puts "Problems loading Gemtronics: #{e.message}"
    puts "This probably means you aren't using Gemtronics."
  end

end

#load_pluginsObject

— RAILS — #



4
5
6
# File 'lib/warp_drive/boot/workers.rb', line 4

def load_plugins # :nodoc:
  Rails.configuration.plugin_paths << WarpDrive::Path.vendor.plugins.to_s
end

#load_rake_tasksObject

— Non-RAILS — #



103
104
105
106
107
108
109
110
111
112
113
# File 'lib/warp_drive/boot/workers.rb', line 103

def load_rake_tasks # :nodoc:
  require 'rake'
  Dir.glob(File.join(WarpDrive::Path.lib.tasks.to_s, '**', '*.*')).sort.each do |task|
    load File.expand_path(task) unless task.match(/\/private\//)
  end
  Dir.glob(File.join(WarpDrive::Path.vendor.plugins.to_s, '*')).sort.each do |plugin|
    Dir.glob(File.join(plugin, 'tasks', '**', '*.*')).sort.each do |task|
      load File.expand_path(task) unless task.match(/\/private\//) 
    end
  end
end

#load_view_pathsObject

:nodoc:



49
50
51
52
53
# File 'lib/warp_drive/boot/workers.rb', line 49

def load_view_paths # :nodoc:
  ActionController::Base.view_paths = [ActionController::Base.view_paths,
                                       WarpDrive::Path.app.views.to_s].flatten
  ActionMailer::Base.view_paths = ActionController::Base.view_paths
end

#set_load_pathObject

:nodoc:



8
9
10
11
12
13
14
15
# File 'lib/warp_drive/boot/workers.rb', line 8

def set_load_path # :nodoc:
  Rails.configuration.load_paths = [Rails.configuration.load_paths,
                                    WarpDrive::Path.lib.to_s,
                                    WarpDrive::Path.app.to_s,
                                    WarpDrive::Path.app.models.to_s,
                                    WarpDrive::Path.app.controllers.to_s,
                                    WarpDrive::Path.app.helpers.to_s].flatten
end