Module Alias

  1. lib/alias/console.rb
  2. lib/alias/creator.rb
  3. lib/alias/manager.rb
  4. lib/alias/util.rb
  5. lib/alias/validator.rb
  6. lib/alias.rb
  7. show all

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.

Methods

public instance

  1. config_file
  2. create
  3. manager

Classes and Modules

Module Alias::Console
Class Alias::Creator
Class Alias::Creators
Class Alias::Manager
Class Alias::Validator

Public instance methods

config_file ()

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.
[show source]
# File lib/alias.rb, line 46
  def config_file
    @config_file ||= File.exists?("config/alias.yml") ? 'config/alias.yml' : "#{ENV['HOME']}/.alias.yml"
  end
create (options={})

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]
[show source]
# File lib/alias.rb, line 29
  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 ()

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

[show source]
# File lib/alias.rb, line 51
  def manager
    @manager ||= Manager.new
  end