Class: Spork::AppFramework::Rails

Inherits:
Spork::AppFramework show all
Defined in:
lib/spork/app_framework/rails.rb

Defined Under Namespace

Modules: NinjaPatcher

Constant Summary

Constants inherited from Spork::AppFramework

SUPPORTED_FRAMEWORKS

Instance Method Summary collapse

Methods inherited from Spork::AppFramework

[], #bootstrap_required?, detect_framework, detect_framework_name, setup_autoload, short_name, #short_name

Instance Method Details

#boot_fileObject



130
131
132
# File 'lib/spork/app_framework/rails.rb', line 130

def boot_file
  @boot_file ||= File.join(File.dirname(environment_file), 'boot')
end

#entry_pointObject Also known as: environment_file



124
125
126
# File 'lib/spork/app_framework/rails.rb', line 124

def entry_point
  @entry_point ||= File.expand_path("config/environment.rb", Dir.pwd)
end

#environment_contentsObject



134
135
136
# File 'lib/spork/app_framework/rails.rb', line 134

def environment_contents
  @environment_contents ||= File.read(environment_file)
end

#preload(&block) ⇒ Object



116
117
118
119
120
121
122
# File 'lib/spork/app_framework/rails.rb', line 116

def preload(&block)
  STDERR.puts "Preloading Rails environment"
  STDERR.flush
  ENV["RAILS_ENV"] ||= 'test'
  preload_rails
  yield
end

#preload_railsObject



152
153
154
155
156
# File 'lib/spork/app_framework/rails.rb', line 152

def preload_rails
  Object.const_set(:RAILS_GEM_VERSION, version) if version
  require boot_file
  ::Rails::Initializer.send(:include, Spork::AppFramework::Rails::NinjaPatcher)
end

#vendorObject



138
139
140
# File 'lib/spork/app_framework/rails.rb', line 138

def vendor
  @vendor ||= File.expand_path("vendor/rails", Dir.pwd)
end

#versionObject



142
143
144
145
146
147
148
149
150
# File 'lib/spork/app_framework/rails.rb', line 142

def version
  @version ||= (
    if /^[^#]*RAILS_GEM_VERSION\s*=\s*["']([!~<>=]*\s*[\d.]+)["']/.match(environment_contents)
      $1
    else
      nil
    end
  )
end