Class: Spork::AppFramework
- Inherits:
-
Object
- Object
- Spork::AppFramework
- Defined in:
- lib/spork/app_framework.rb
Defined Under Namespace
Classes: Padrino, Rails, Unknown
Constant Summary collapse
- SUPPORTED_FRAMEWORKS =
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.
{ :Padrino => lambda { File.exist?("config/boot.rb") && File.read("config/boot.rb").include?('PADRINO') }, :Rails => lambda { File.exist?("config/environment.rb") && File.read("config/environment.rb").include?('RAILS_GEM_VERSION') } }
Class Method Summary collapse
-
.[](name) ⇒ Object
Initializes, stores, and returns a singleton instance of the named AppFramework.
-
.detect_framework ⇒ Object
Same as detect_framework_name, but returns an instance of the specific AppFramework class.
-
.detect_framework_name ⇒ Object
Iterates through all SUPPORTED_FRAMEWORKS and returns the symbolic name of the project application framework detected.
- .setup_autoload ⇒ Object
- .short_name ⇒ Object
Instance Method Summary collapse
-
#bootstrap_required? ⇒ Boolean
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.
-
#entry_point ⇒ Object
Abstract: The path to the file that loads the project environment, ie config/environment.rb.
- #preload(&block) ⇒ Object
- #short_name ⇒ Object
Class Method Details
.[](name) ⇒ Object
Initializes, stores, and returns a singleton instance of the named AppFramework.
Parameters
# name
- A symbolic name of a AppFramework subclass
Example
Spork::AppFramework[:Rails]
45 46 47 |
# File 'lib/spork/app_framework.rb', line 45 def self.[](name) instances[name] ||= const_get(name).new end |
.detect_framework ⇒ Object
Same as detect_framework_name, but returns an instance of the specific AppFramework class.
31 32 33 34 |
# File 'lib/spork/app_framework.rb', line 31 def self.detect_framework name = detect_framework_name self[name] end |
.detect_framework_name ⇒ Object
Iterates through all SUPPORTED_FRAMEWORKS and returns the symbolic name of the project application framework detected. Otherwise, returns :Unknown
23 24 25 26 27 28 |
# File 'lib/spork/app_framework.rb', line 23 def self.detect_framework_name SUPPORTED_FRAMEWORKS.each do |key, value| return key if value.call end :Unknown end |
.setup_autoload ⇒ Object
16 17 18 19 20 |
# File 'lib/spork/app_framework.rb', line 16 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 |
.short_name ⇒ Object
49 50 51 |
# File 'lib/spork/app_framework.rb', line 49 def self.short_name name.gsub('Spork::AppFramework::', '') end |
Instance Method Details
#bootstrap_required? ⇒ Boolean
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.
54 55 56 |
# File 'lib/spork/app_framework.rb', line 54 def bootstrap_required? entry_point.nil? end |
#entry_point ⇒ Object
Abstract: The path to the file that loads the project environment, ie config/environment.rb. Returns nil if there is none.
59 60 61 |
# File 'lib/spork/app_framework.rb', line 59 def entry_point raise NotImplementedError end |
#preload(&block) ⇒ Object
63 64 65 |
# File 'lib/spork/app_framework.rb', line 63 def preload(&block) yield end |
#short_name ⇒ Object
67 68 69 |
# File 'lib/spork/app_framework.rb', line 67 def short_name self.class.short_name end |