github
Advanced Search
  • Home
  • Pricing and Signup
  • Explore GitHub
  • Blog
  • Login

cldwalker / alias

  • Admin
  • Watch Unwatch
  • Fork
  • Your Fork
  • Pull Request
  • Download Source
    • 28
    • 0
  • Source
  • Commits
  • Network (0)
  • Issues (0)
  • Downloads (4)
  • Wiki (1)
  • Graphs
  • Branch: master

click here to add a description

click here to add a homepage

  • Branches (2)
    • gh-pages
    • master ✓
  • Tags (4)
    • v0.2.1
    • v0.2.0
    • v0.1.2
    • v0.1.1
Sending Request…
Enable Donations

Pledgie Donations

Once activated, we'll place the following badge in your repository's detail box:
Pledgie_example
This service is courtesy of Pledgie.

Creates, manages and saves aliases for class methods, instance methods, constants, delegated methods and more. — Read more

  cancel

http://tagaholic.me/alias/

  cancel
  • Private
  • Read-Only
  • HTTP Read-Only

This URL has Read+Write access

readme tweak 
cldwalker (author)
Thu Jul 16 14:40:34 -0700 2009
commit  c3980e3d3823c9a1974c0bb5d7e2b97329b56990
tree    be3fabc52c395e6f38b20e71e6cd1b63acf3b08c
parent  83c6ef9bfedbbfa1ea8739b4fbe67459a6c21030
alias /
name age
history
message
file CHANGELOG.rdoc Tue Jul 07 03:51:29 -0700 2009 changelog tweak [cldwalker]
file LICENSE.txt Sun Jan 25 16:09:11 -0800 2009 added working search and caching for alias_map [cldwalker]
file README.rdoc Thu Jul 16 14:40:34 -0700 2009 readme tweak [cldwalker]
file Rakefile Tue Jul 07 02:48:55 -0700 2009 added rubyforge [cldwalker]
file VERSION.yml Tue Jul 07 03:51:45 -0700 2009 Version bump to 0.2.1 [cldwalker]
file alias.gemspec Tue Jul 07 03:56:30 -0700 2009 Regenerated gemspec for version 0.2.1 [cldwalker]
directory lib/ Tue Jul 07 02:19:19 -0700 2009 changed list_aliases to search_aliases [cldwalker]
directory test/ Tue Jul 07 02:19:19 -0700 2009 changed list_aliases to search_aliases [cldwalker]
README.rdoc

Description

Creates aliases for class methods, instance methods, constants, delegated methods and more. Aliases can be easily searched or saved as YAML config files to load later. Custom alias types are easy to create with the DSL Alias provides. Although Alias was created with the irb user in mind, any Ruby console program can hook into Alias for creating configurable aliases.

Setup

Install the gem with:

    sudo gem install cldwalker-alias --source http://gems.github.com

To setup, simply drop these two lines in your .irbrc:

    require 'alias'
    Alias.create

This will assume a file in config/alias.yml or ~/.alias.yml. If you want it somewhere else, pass a :file option to create():

    Alias.create :file=>"/path/to/my/clandestine_aliases.yml"

If you’d like to define your aliases without a config file, pass Alias.create() an :aliases option:

    Alias.create :verbose=>true, :aliases=>{
      :constant=>{'Array' = 'A'},
      :instance_method=>{'String'=>{'downcase'=>'dc' }, 'Array'=>{'select'=>'s'}}
    }

Usage

An example within Rails’ script/console:

    bash> script/console
    >> require 'alias'
    => true

    # Import alias methods
    >> extend Alias::Console
    => main

    # First let's see what ruby code Alias generates to create an alias.
    >> create_aliases :class_method, {"ActiveRecord::Base"=>{'find'=>'[]'}}, :pretend=>true

    class ::ActiveRecord::Base; class<< self; alias_method :[], :find; end; end
    => true

    # Create the above class method alias
    >> create_aliases :class_method, "ActiveRecord::Base"=>{'find'=>'[]'}
    => true

    # Create the above constant alias
    >> create_aliases :constant, "ActiveRecord::Base"=>"AB"
    => true
    # Verify that it worked
    >> AB
    => ActiveRecord::Base

    # If we try to create the constant alias again, Alias prevents us and warns us
    >> create_aliases :constant, "ActiveRecord::Base"=>"AB"
    Constant 'AB' not created since it already exists
    => false
    # We can force Alias to override a method, class or constant that already exists
    >> create_aliases :constant, {"ActiveRecord::Base"=>"AB"}, :force=>true
    => true

    # Create the above instance method alias
    >> create_aliases :instance_method, "ActiveRecord::Base"=>{"update_attribute"=>'ua'}
    => true

    # By default aliases are saved to config/alias.yml in rails or ~/.alias.yml if not.
    >> save_aliases
    Saved created aliases to config/alias.yml.
    => true

Configuration

For an example config file see test/aliases.yml. For an explanation of the config file format see Alias.config_file.

Creating Custom Alias Types

See Alias::Creator.

Links

  • tagaholic.me/2009/07/07/alias-quickness-in-the-ruby-console.html

Todo

  • Allow loading of select aliases in a file.
  • Provide a way to autogenerate aliases with a given proc.
Blog | Support | Training | Contact | API | Status | Twitter | Help | Security
© 2010 GitHub Inc. All rights reserved. | Terms of Service | Privacy Policy
Powered by the Dedicated Servers and
Cloud Computing of Rackspace Hosting®
Dedicated Server