class Anvil::ExtensionsManager

Manage loading and finding anvil tasks and config extensions

Constants

PATTERNS

Attributes

tasks_loaded[RW]

Public Class Methods

load_config_extensions() click to toggle source
# File lib/anvil/extensions_manager.rb, line 27
def load_config_extensions
  new.load_config_extensions
end
load_tasks() click to toggle source
# File lib/anvil/extensions_manager.rb, line 23
def load_tasks
  new.load_tasks
end
tasks_by_name() click to toggle source
# File lib/anvil/extensions_manager.rb, line 19
def tasks_by_name
  new.tasks_by_name
end

Public Instance Methods

all_files_for(extension_type) click to toggle source

@param extension_type [Symbol] either :tasks or :config. @see {Anvil::ExtensionsManager::PATTERNS} @return [Array] all known anvil files for a given extension type

# File lib/anvil/extensions_manager.rb, line 55
def all_files_for(extension_type)
  [files_from_env(extension_type),
   files_from_anvil(extension_type),
   files_from_current_project(extension_type),
   files_from_gems(extension_type)
  ].compact.reduce(&:+).uniq
end
all_tasks() click to toggle source

@return [Array] all known {Anvil::Task} desdendants

# File lib/anvil/extensions_manager.rb, line 37
def all_tasks
  load_tasks unless self.class.tasks_loaded
  ::Anvil::Task.descendants
end
files_from_anvil(extension_type) click to toggle source

@param extension_type [Symbol] either :tasks or :config. @see {Anvil::ExtensionsManager::PATTERNS} @return [Array] all the core anvil extensions

# File lib/anvil/extensions_manager.rb, line 66
def files_from_anvil(extension_type)
  files_from_path(File.expand_path('../..', __FILE__), extension_type)
end
files_from_current_project(pattern) click to toggle source

@param extension_type [Symbol] either :tasks or :config. @see {Anvil::ExtensionsManager::PATTERNS} @return [Array] all possible anvil extensions

# File lib/anvil/extensions_manager.rb, line 73
def files_from_current_project(pattern)
  path = current_project_path + '/lib/anvil/'
  files_from_path(path, pattern)
end
files_from_env(pattern) click to toggle source

@param extension_type [Symbol] either :tasks or :config. @see {Anvil::ExtensionsManager::PATTERNS} @return [Array] anvil tasks in the specified dir

# File lib/anvil/extensions_manager.rb, line 88
def files_from_env(pattern)
  if ENV['ANVIL_EXTENSIONS_DIR']
    env_dir_list = ENV['ANVIL_EXTENSIONS_DIR'].split(':').join(',')

    Dir["{#{env_dir_list}}#{PATTERNS[pattern]}"]
  else
    []
  end
end
files_from_gems(pattern) click to toggle source

@param extension_type [Symbol] either :tasks or :config. @see {Anvil::ExtensionsManager::PATTERNS} @return [Array] anvil extensions installed in gems

# File lib/anvil/extensions_manager.rb, line 81
def files_from_gems(pattern)
  Gem.find_latest_files "anvil#{PATTERNS[pattern]}"
end
load_config_extensions() click to toggle source
# File lib/anvil/extensions_manager.rb, line 48
def load_config_extensions
  all_files_for(:config_extensions).each { |file| load(file) }
end
load_tasks() click to toggle source

Loads all known anvil tasks

# File lib/anvil/extensions_manager.rb, line 43
def load_tasks
  all_files_for(:tasks).each { |file| load(file) }
  self.class.tasks_loaded = true
end
tasks_by_name() click to toggle source
# File lib/anvil/extensions_manager.rb, line 32
def tasks_by_name
  all_tasks.sort_by { |t| t.name }
end

Protected Instance Methods

current_project_path() click to toggle source

@return [String] top level dir if this is a git managed project

# File lib/anvil/extensions_manager.rb, line 101
def current_project_path
  Rugged::Repository.discover(Dir.pwd).path.gsub('.git/', '')
rescue Rugged::RepositoryError
  ''
end
files_from_path(path, pattern) click to toggle source

@param path [String] a path to glob their anvil tasks @param pattern [Symbol] the pattern to load files @return [Array] all anvil tasks in the given path

# File lib/anvil/extensions_manager.rb, line 110
def files_from_path(path, pattern)
  Dir["#{path}#{PATTERNS[pattern]}"]
end