Created
March 17, 2009 06:50
-
-
Save deepthawtz/80360 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Load Slice classes before the app's classes are loaded. | |
# | |
# This allows the application to override/merge any slice-level classes. | |
class Merb::Slices::Loader < Merb::BootLoader | |
before LoadClasses | |
class << self | |
# Gather all slices from search path and gems and load their classes. | |
def run | |
Merb::Slices.register_slices_from_search_path! if auto_register? | |
Merb::Slices.each_slice { |slice| slice.load_slice } | |
end | |
# Load a single file and its requirements. | |
# | |
# @param file<String> The file to load. | |
def load_file(file) | |
Merb::BootLoader::LoadClasses.load_file file | |
end | |
# Remove a single file and the classes loaded by it from ObjectSpace. | |
# | |
# @param file<String> The file to load. | |
def remove_classes_in_file(file) | |
Merb::BootLoader::LoadClasses.remove_classes_in_file file | |
end | |
# Load classes from given paths - using path/glob pattern. | |
# | |
# @param *paths <Array> Array of paths to load classes from - may contain glob pattern | |
def load_classes(*paths) | |
Merb::BootLoader::LoadClasses.load_classes paths | |
end | |
# Reload the router - takes all_slices into account to load slices at runtime. | |
def reload_router! | |
Merb::BootLoader::Router.reload! | |
end | |
# Slice-level paths for all loaded slices. | |
# | |
# @return <Array[String]> Any slice-level paths that have been loaded. | |
def slice_paths | |
paths = [] | |
Merb::Slices.each_slice { |slice| paths += slice.collected_slice_paths } | |
paths | |
end | |
# App-level paths for all loaded slices. | |
# | |
# @return <Array[String]> Any app-level paths that have been loaded. | |
def app_paths | |
paths = [] | |
Merb::Slices.each_slice { |slice| paths += slice.collected_app_paths } | |
paths | |
end | |
private | |
# Whether slices from search paths should be registered automatically. | |
# Defaults to true if not explicitly set. | |
def auto_register? | |
Merb::Plugins.config[:merb_slices][:auto_register] || !Merb::Plugins.config[:merb_slices].key?(:auto_register) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment