class TrustyCms::ExtensionPath

def self.clear_paths!


Currently only used in testing.
Forgets all recorded extension paths.
def self.clear_paths!
  @@known_paths = {}
end

def self.from_path(path, name = nil)


If two arguments are given, the second is taken to be the full extension name.

ExtensionLoader, to load and activate the extension.
is returned, and also remembered here for later use by the initializer (to find load paths) and the
stripping the extra bits from trusty-something-extension-1.0.0 to leave just 'something'. The object
Builds a new ExtensionPath object from the supplied path, working out the name of the extension by
def self.from_path(path, name = nil)
  name = path if name.blank?
  name = File.basename(name).gsub(/^trusty-|-extension(-[\d\.a-z]+|-[a-z\d]+)*$/, '')
  new(name: name, path: path)
end

def check_subdirectory(subpath)


If the supplied path within the extension root exists and is a directory, its absolute path is returned. Otherwise, nil.
def check_subdirectory(subpath)
  subdirectory = File.join(path, subpath)
  subdirectory if File.directory?(subdirectory)
end

def controller_paths


Call the class method ExtensionPath.controller_paths to get a list of the controller paths found in all enabled extensions.
Returns the app/controllers path if it is found within this extension root.
def controller_paths
  check_subdirectory('app/controllers')
end

def eager_load_paths


Call the class method ExtensionPath.eager_load_paths to get a list for all enabled extensions.

controllers are loaded before running cucumber features, and there may be a better way to achieve that.
includes all the controller, model and helper paths. The main purpose here is to ensure that extension
Returns a list of extension subdirectories that should be marked for eager loading. At the moment that
def eager_load_paths
  [controller_paths, model_paths, helper_paths].flatten.compact
end

def enabled


are being passed around as symbols.
Note that at this stage, in line with the usage of config.extensions = [], the extension names

If a configured extension has not been found during initialization, a LoadError will be thrown here.
Returns a list of path objects for all the enabled extensions in the configured order.
def enabled
  enabled_extensions = TrustyCms::Application.config.enabled_extensions
  @@known_paths.values_at(*enabled_extensions).compact
end

def enabled_paths


Returns a list of the root paths to all the enabled extensions, in the configured order.
def enabled_paths
  enabled.map(&:path)
end

def find(name)


Returns the ExtensionPath object for the given extension name.
def find(name)
  raise LoadError, "Cannot return path for unknown extension: #{name}" unless @@known_paths[name.to_sym]
  @@known_paths[name.to_sym]
end

def for(name)


Returns the root path recorded for the given extension name.
def for(name)
  find(name).path
end

def helper_paths


Call the class method ExtensionPath.helper_paths to get a list of the helper paths found in all enabled extensions.
Returns the app/helpers path if it is found within this extension root.
def helper_paths
  check_subdirectory('app/helpers')
end

def initialize(options = {}) #:nodoc

:nodoc
def initialize(options = {}) #:nodoc
  @name = options[:name].underscore
  @path = options[:path]
  @@known_paths[@name.to_sym] = self
end

def load_paths


You can call the class method ExtensionPath.load_paths to get a flattened list of all the load paths in all the enabled extensions.

* path/test/helpers
* path/app/helpers
* path/app/metal
* path/app/controllers
* path/app/models
* path/lib
* path

that exist and are directories:
Returns a list of all the likely load paths found within this extension root. It includes all of these
def load_paths
  %w(lib app/models app/controllers app/metal app/helpers test/helpers).collect { |d| check_subdirectory(d) }.push(path).flatten.compact
end

def locale_paths


in reverse order so that locale definitions override one another correctly.
Call the class method ExtensionPath.locale_paths to get a list of the locale files found in all enabled extensions
Returns a list of names of all the locale files found within this extension root.
def locale_paths
  if check_subdirectory('config/locales')
    Dir[File.join(path.to_s, 'config/locales', '*.{rb,yml}')]
  end
end

def metal_paths


Call the class method ExtensionPath.metal_paths to get a list of the metal paths found in all enabled extensions.
Returns the app/metal path if it is found within this extension root.
def metal_paths
  check_subdirectory('app/metal')
end

def model_paths


Call the class method ExtensionPath.model_paths to get a list of the model paths found in all enabled extensions.
Returns the app/models path if it is found within this extension root.
def model_paths
  check_subdirectory('app/models')
end

def plugin_paths


Call the class method ExtensionPath.plugin_paths to get a list of the plugin paths found in all enabled extensions.
Returns a list of all the +vendor/plugin+ paths found within this extension root.
def plugin_paths
  check_subdirectory('vendor/plugins')
end

def rake_task_paths


Returns a list of all the rake task files found within this extension root.
def rake_task_paths
  if check_subdirectory('lib/tasks')
    Dir[File.join(path.to_s, 'lib/tasks/**', '*.rake')]
  end
end

def required

def required
  File.join(path, "#{name}_extension")
end

def to_s

def to_s
  path
end

def view_paths


in reverse order so that views override one another correctly.
Call the class method ExtensionPath.view_paths to get a list of the view paths found in all enabled extensions
Returns the app/views path if it is found within this extension root.
def view_paths
  check_subdirectory('app/views')
end