Module: Merb::Slices::ModuleMixin

Module | Merb::Slices::ModuleMixin
In: | lib/merb-slices/module_mixin.rb

### Methods

[] []= activate app_components app_dir_for app_glob_for app_path_for app_paths application_file? clone_slice! collect_load_paths collected_app_paths collected_slice_paths config deactivate dir_for extended glob_for init load_slice loadable_files loaded manifest mirror_all! mirror_app! mirror_file mirror_files_for mirror_public! mirror_stubs! mirrored_app_components mirrored_components mirrored_public_components named_routes public_components public_dir_for public_path_for push_app_path push_path registered remove_app_paths remove_paths root_path routed? setup_default_structure! setup_router slice_path_for slice_paths split_name standalone? to_param unpack_file? unpack_slice! view_templates_glob

### Public Class methods

extended(slice_module)

### Public Instance methods

[](key)

@param <Symbol> The configuration key. @return <Object> The configuration value.

[]=(key, value)

@param <Symbol> The configuration key. @param <Object> The configuration value.

activate()

Stub activation hook - runs after AfterAppLoads BootLoader.

app_components()

Return all application path component types

@return <Array[Symbol]> Component types.

app_dir_for(type)

Retrieve the absolute path to a app-level directory.

@param type<Symbol> The type of path to retrieve directory for, e.g. :view.

@return <String> The directory for the requested type.

app_glob_for(type)

@param type<Symbol> The type of path to retrieve glob for, e.g. :view.

@return <String> The pattern with which to match files within the type directory.

app_path_for(type, *segments)

Construct an app-level path.

@param <Symbol> The type of component. @param *segments<Array[to_s]> Path segments to append.

@return <String>

     A path within the host application, with added segments.

app_paths()

The app-level load paths to use when loading the slice.

@return <Hash> The load paths which make up the app-level structure.

clone_slice!()

Clone all files from the slice to their app-level location; this will also copy /lib, causing merb-slices to pick up the slice there.

@return <Array[Array]>

      Array of two arrays, one for all copied files, the other for overrides
      that may have been preserved to resolve collisions.

collected_app_paths()

The app-level load paths that have been used when the slice was loaded.

This may be a subset of app_paths, which includes any path to look for.

@return <Array[String]> Application load paths (with glob pattern)

collected_slice_paths()

The slice-level load paths that have been used when the slice was loaded.

This may be a subset of app_paths, which includes any path to look for.

@return <Array[String]> load paths (with glob pattern)

config()

@return <Hash> The configuration for this slice.

deactivate()

Stub deactivation method - not triggered automatically.

dir_for(type)

Retrieve the absolute path to a slice-level directory.

@param type<Symbol> The type of path to retrieve directory for, e.g. :view.

@return <String> The absolute path for the requested type.

glob_for(type)

@param type<Symbol> The type of path to retrieve glob for, e.g. :view.

@return <String> The pattern with which to match files within the type directory.

init()

Stub initialization hook - runs before AfterAppLoads BootLoader.

load_slice()

Load slice and it‘s classes located in the slice-level load paths.

Assigns collected_slice_paths and collected_app_paths, then loads the collected_slice_paths and triggers the loaded hook method.

loadable_files()

Return all *.rb files from valid component paths

@return <Array> Full paths to loadable ruby files.

loaded()

Stub classes loaded hook - runs before LoadClasses BootLoader right after a slice‘s classes have been loaded internally.

manifest(type = :root)

Return all slice files mapped from the source to their relative path

@param type<Symbol> Which type to use; defaults to :root (all) @return <Array[Array]> An array of arrays [abs. source, relative dest.]

mirror_all!()

Copies all files from mirrored_components to their app-level location

This includes application and public components.

@return <Array[Array]>

      Array of two arrays, one for all copied files, the other for overrides
      that may have been preserved to resolve collisions.

mirror_app!()

Copies all application files from mirrored_components to their app-level location

@return <Array[Array]>

      Array of two arrays, one for all copied files, the other for overrides
      that may have been preserved to resolve collisions.

mirror_files_for(*types)

Copy files from specified component path types to their app-level location

App-level overrides are preserved by creating duplicates before writing gem-level files. Because of their _override postfix they will load after their original implementation. In the case of views, this won‘t work, but the user override is preserved nonetheless.

@return <Array[Array]>

      Array of two arrays, one for all copied files, the other for overrides
      that may have been preserved to resolve collisions.

@note Only explicitly defined component paths will be taken into account to avoid

      cluttering the app's Merb.root by mistake - since undefined paths default to that.

mirror_public!()

Copies all application files from mirrored_components to their app-level location

@return <Array[Array]>

      Array of two arrays, one for all copied files, the other for overrides
      that may have been preserved to resolve collisions.

mirror_stubs!()

Copies all files from the (optional) stubs directory to their app-level location

@return <Array[Array]>

      Array of two arrays, one for all copied files, the other for overrides
      that may have been preserved to resolve collisions.

mirrored_app_components()

Return all application path component types to mirror

@return <Array[Symbol]> Component types.

mirrored_components()

Return all path component types to mirror

If config option :mirror is set return a subset, otherwise return all types.

@return <Array[Symbol]> Component types.

mirrored_public_components()

Return all public path component types to mirror

@return <Array[Symbol]> Component types.

named_routes()

@return <Hash> The named routes for this slice.

public_components()

Return all public path component types

@return <Array[Symbol]> Component types.

public_dir_for(type)

Retrieve the relative path to a public directory.

@param type<Symbol> The type of path to retrieve directory for, e.g. :view.

@return <String> The relative path to the public directory for the requested type.

public_path_for(type, *segments)

Construct a path relative to the public directory

@param <Symbol> The type of component. @param *segments<Array[to_s]> Path segments to append.

@return <String>

     A path relative to the public directory, with added segments.

push_app_path(type, path, file_glob = "**/*.rb")

This is the core mechanism for setting up your app-level layout.

@param type<Symbol> The type of path being registered (i.e. :view) @param path<String> The full path @param file_glob<String>

      A glob that will be used to autoload files under the path. Defaults to "**/*.rb".

@note The :public path is adapted when the slice is run from bin/slice.

push_path(type, path, file_glob = "**/*.rb")

This is the core mechanism for setting up your slice-level layout.

@param type<Symbol> The type of path being registered (i.e. :view) @param path<String> The full path @param file_glob<String>

      A glob that will be used to autoload files under the path. Defaults to "**/*.rb".

registered()

Stub that gets triggered when a slice has been registered.

@note This is rarely needed but still provided for edge cases.

remove_app_paths(*args)

Removes given types of application components from app-level load path this slice uses for autoloading.

@param *args<Array[Symbol]> Components names, for instance, :views, :models

remove_paths(*args)

Removes given types of application components from slice-level load path this slice uses for autoloading.

@param *args<Array[Symbol]> Components names, for instance, :views, :models

root_path(*path)

@param *path<to_s>

      The relative path (or list of path components) to a directory under the
      root of the application.

@return <String> The full path including the root.

routed?()

Check if there have been any routes setup.

setup_default_structure!()

This sets up the default slice-level and app-level structure.

You can create your own structure by implementing setup_structure and using the push_path and push_app_paths. By default this setup matches what the merb-gen slice generator creates.

setup_router(scope)

Stub to setup routes inside the host application.

slice_path_for(type, *segments)

Construct a slice-level path.

@param <Symbol> The type of component. @param *segments<Array[to_s]> Path segments to append.

@return <String>

     A path within the slice source (Gem), with added segments.

slice_paths()

The slice-level load paths to use when loading the slice.

@return <Hash> The load paths which make up the slice-level structure.

standalone?()

Whether we‘re in an application or running from the slice dir itself.

to_param()

Return a value suitable for routes/urls.

unpack_slice!()

Unpack a subset of files from the slice to their app-level location; this will also copy /lib, causing merb-slices to pick up the slice there.

@return <Array[Array]>

      Array of two arrays, one for all copied files, the other for overrides
      that may have been preserved to resolve collisions.

@note Files for the :stub component type are skipped.

### Protected Instance methods

application_file?()

Predicate method to check if the :application component is a file

collect_load_paths(modify_load_path = true, push_merb_path = true)

Collect slice-level and app-level load paths to load from.

@param modify_load_path<Boolean>

      Whether to add certain paths to $LOAD_PATH; defaults to true.

@param push_merb_path<Boolean>

      Whether to add app-level paths using Merb.push_path; defaults to true.

mirror_file(source, dest, copied = [], duplicated = [], postfix = '_override')

Helper method to copy a source file to destination while resolving any conflicts.

@param source<String> The source path. @param dest<String> The destination path. @param copied<Array> Keep track of all copied files - relative paths. @param duplicated<Array> Keep track of all duplicated files - relative paths. @param postfix<String> The postfix to use for resolving conflicting filenames.

split_name(name)

Split a file name so a postfix can be inserted

@return <Array[String]>

      The first element will be the name up to the first dot, the second will be the rest.

unpack_file?(file)

Predicate method to check if a file should be taken into account when unpacking files

By default any public component paths and stubs are skipped; additionally you can set the :skip_files in the slice‘s config for other relative paths to skip.

@param file<String> The relative path to test. @return <TrueClass,FalseClass> True if the file may be mirrored.

view_templates_glob()

Glob pattern matching all valid template extensions

[Validate]