lib/spork/app_framework.rb in timcharper-spork-0.5.6 vs lib/spork/app_framework.rb in timcharper-spork-0.5.7
- old
+ new
@@ -1,50 +1,74 @@
class Spork::AppFramework
+ # A hash of procs where the key is the class name, and the proc takes no arguments and returns true if it detects that said application framework is being used in the project.
+ #
+ # The key :Rails maps to Spork::AppFramework::Rails
+ #
+ # This is used to reduce the amount of code needed to be loaded - only the detected application framework's support code is loaded.
SUPPORTED_FRAMEWORKS = {
- :Rails => lambda do
+ :Rails => lambda {
File.exist?("config/environment.rb") && File.read("config/environment.rb").include?('RAILS_GEM_VERSION')
- end
+ }
}
+ def self.setup_autoload
+ ([:Unknown] + SUPPORTED_FRAMEWORKS.keys).each do |name|
+ autoload name, File.join(File.dirname(__FILE__), "app_framework", name.to_s.downcase)
+ end
+ end
+
+ # Iterates through all SUPPORTED_FRAMEWORKS and returns the symbolic name of the project application framework detected. Otherwise, returns :Unknown
def self.detect_framework_name
SUPPORTED_FRAMEWORKS.each do |key, value|
return key if value.call
end
:Unknown
end
+ # Same as detect_framework_name, but returns an instance of the specific AppFramework class.
def self.detect_framework
name = detect_framework_name
self[name]
end
+ # Initializes, stores, and returns a singleton instance of the named AppFramework.
+ #
+ # == Parameters
+ #
+ # # +name+ - A symbolic name of a AppFramework subclass
+ #
+ # == Example
+ #
+ # Spork::AppFramework[:Rails]
def self.[](name)
- instances[name] ||= (
- require File.join(File.dirname(__FILE__), "app_framework", name.to_s.downcase)
- const_get(name).new
- )
+ instances[name] ||= const_get(name).new
end
- def self.instances
- @instances ||= {}
- end
-
def self.short_name
name.gsub('Spork::AppFramework::', '')
end
+ # If there is some stuff out of the box that the Spork can do to speed up tests without the test helper file being bootstrapped, this should return false.
def bootstrap_required?
entry_point.nil?
end
+ # Abstract: The path to the file that loads the project environment, ie config/environment.rb. Returns nil if there is none.
def entry_point
- nil
+ raise NotImplemented
end
def preload(&block)
yield
end
def short_name
self.class.short_name
end
-end
+
+ protected
+ def self.instances
+ @instances ||= {}
+ end
+end
+
+Spork::AppFramework.setup_autoload
\ No newline at end of file