module Alias

Most of the core Alias actions are run through Alias::Manager except for Alias.create. See Alias::Manager for an explanation of how aliases are created.

Constants

VERSION

Public Instance Methods

config_file() click to toggle source

By default, looks for existing files in config/alias.yml and then ~/.alias.yml. A config file has the following keys:

:aliases

This takes a hash mapping creators to their config hashes. Valid creators are :instance_method, :class_method, :constant, :class_to_instance_method and :any_to_instance_method.

:verbose

Sets whether creators are verbose with boolean or array of creator symbols. A boolean sets verbosity for all creators whereas the array specifies which creators. Default is false.

:force

Sets whether creators force optional validations with boolean or array of creator symbols. Works the same as :verbose. Default is false.

# File lib/alias.rb, line 45
def config_file
  @config_file ||= File.exists?("config/alias.yml") ? 'config/alias.yml' : "#{ENV['HOME']}/.alias.yml"
end
create(options={}) click to toggle source

Creates aliases from Alias.config_file if it exists and merges them with any explicit aliases. This method takes the same keys used by config files (see Alias.config_file) and also the following options:

  • :file : Specifies a config file to override Alias.config_file. If set to false, no config file is loaded.

Examples:

# Loads any default files and the ones in :aliases.
# Sets global verbosity for creators.
create :aliases=>{:constant=>{"Array"=>"A"}}, :verbose=>true
# Loads the given file and sets verbosity just for the :instance_method creator.
create :file=>"some file", :verbose=>[:instance_method]
# File lib/alias.rb, line 28
def create(options={})
  file_config = load_config_file(options.delete(:file))
  new_config = Util.recursive_hash_merge(file_config, options)
  manager.verbose = new_config[:verbose] if new_config[:verbose]
  manager.force = new_config[:force] if new_config[:force]
  (new_config[:aliases] || {}).each do |creator_type, aliases|
    manager.create_aliases(creator_type, aliases)
  end
  @config = Util.recursive_hash_merge(config, new_config)
end
manager() click to toggle source

Contains primary Alias::Manager object which is used throughout Alias.

# File lib/alias.rb, line 50
def manager
  @manager ||= Manager.new
end