Class: Spork::AppFramework

Inherits:
Object
  • Object
show all
Defined in:
lib/spork/app_framework.rb

Direct Known Subclasses

Padrino, Rails, Unknown

Defined Under Namespace

Classes: Padrino, Rails, Unknown

Constant Summary

SUPPORTED_FRAMEWORKS =
{
  :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') ||
      (File.exist?("config/application.rb") && File.read("config/application.rb").include?("Rails::Application"))
    )
  }
}

Class Method Summary (collapse)

Instance Method Summary (collapse)

Class Method Details

+ (Object) [](name)

Initializes, stores, and returns a singleton instance of the named AppFramework.

Parameters

# name - A symbolic name of a AppFramework subclass

Example

Spork::AppFramework[:Rails]


48
49
50
# File 'lib/spork/app_framework.rb', line 48

def self.[](name)
  instances[name] ||= const_get(name).new
end

+ (Object) detect_framework

Same as detect_framework_name, but returns an instance of the specific AppFramework class.



34
35
36
37
# File 'lib/spork/app_framework.rb', line 34

def self.detect_framework
  name = detect_framework_name
  self[name]
end

+ (Object) detect_framework_name

Iterates through all SUPPORTED_FRAMEWORKS and returns the symbolic name of the project application framework detected. Otherwise, returns :Unknown



26
27
28
29
30
31
# File 'lib/spork/app_framework.rb', line 26

def self.detect_framework_name
  SUPPORTED_FRAMEWORKS.each do |key, value|
    return key if value.call
  end
  :Unknown
end

+ (Object) setup_autoload



19
20
21
22
23
# File 'lib/spork/app_framework.rb', line 19

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

+ (Object) short_name



52
53
54
# File 'lib/spork/app_framework.rb', line 52

def self.short_name
  name.gsub('Spork::AppFramework::', '')
end

Instance Method Details

- (Boolean) bootstrap_required?

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.

Returns:

  • (Boolean)


57
58
59
# File 'lib/spork/app_framework.rb', line 57

def bootstrap_required?
  entry_point.nil?
end

- (Object) entry_point

Abstract: The path to the file that loads the project environment, ie config/environment.rb. Returns nil if there is none.

Raises:

  • (NotImplementedError)


62
63
64
# File 'lib/spork/app_framework.rb', line 62

def entry_point
  raise NotImplementedError
end

- (Object) preload(&block)



66
67
68
# File 'lib/spork/app_framework.rb', line 66

def preload(&block)
  yield
end

- (Object) short_name



70
71
72
# File 'lib/spork/app_framework.rb', line 70

def short_name
  self.class.short_name
end