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, instances, short_name, #short_name

Instance Method Details

#boot_fileObject



111
112
113
# File 'lib/spork/app_framework/rails.rb', line 111

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

#entry_pointObject Also known as: environment_file



105
106
107
# File 'lib/spork/app_framework/rails.rb', line 105

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

#environment_contentsObject



115
116
117
# File 'lib/spork/app_framework/rails.rb', line 115

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

#preload(&block) ⇒ Object



97
98
99
100
101
102
103
# File 'lib/spork/app_framework/rails.rb', line 97

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

#preload_railsObject



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

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



119
120
121
# File 'lib/spork/app_framework/rails.rb', line 119

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

#versionObject



123
124
125
126
127
128
129
130
131
# File 'lib/spork/app_framework/rails.rb', line 123

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