alias 0.2.1 → 0.2.2
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG.rdoc +5 -0
- data/README.rdoc +5 -1
- data/Rakefile +24 -39
- data/gemspec +20 -0
- data/lib/alias.rb +1 -2
- data/lib/alias/version.rb +3 -0
- data/test/alias_test.rb +52 -54
- data/test/any_to_instance_method_creator_test.rb +28 -30
- data/test/class_method_creator_test.rb +31 -34
- data/test/class_to_instance_method_creator_test.rb +42 -44
- data/test/console_test.rb +29 -26
- data/test/constant_creator_test.rb +27 -29
- data/test/creator_test.rb +19 -23
- data/test/instance_method_creator_test.rb +31 -33
- data/test/manager_test.rb +102 -101
- data/test/test_helper.rb +7 -7
- data/test/util_test.rb +36 -38
- data/test/validator_test.rb +54 -56
- metadata +70 -31
- data/VERSION.yml +0 -4
data/CHANGELOG.rdoc
CHANGED
data/README.rdoc
CHANGED
@@ -9,7 +9,7 @@ console program can hook into Alias for creating configurable aliases.
|
|
9
9
|
|
10
10
|
Install the gem with:
|
11
11
|
|
12
|
-
sudo gem install
|
12
|
+
sudo gem install alias
|
13
13
|
|
14
14
|
To setup, simply drop these two lines in your .irbrc:
|
15
15
|
|
@@ -83,6 +83,10 @@ For an explanation of the config file format see Alias.config_file.
|
|
83
83
|
|
84
84
|
See Alias::Creator.
|
85
85
|
|
86
|
+
== Links
|
87
|
+
* http://tagaholic.me/2009/07/07/alias-quickness-in-the-ruby-console.html
|
88
|
+
|
86
89
|
== Todo
|
90
|
+
* Fix tests
|
87
91
|
* Allow loading of select aliases in a file.
|
88
92
|
* Provide a way to autogenerate aliases with a given proc.
|
data/Rakefile
CHANGED
@@ -1,50 +1,35 @@
|
|
1
1
|
require 'rake'
|
2
|
-
require '
|
3
|
-
require 'rake/rdoctask'
|
4
|
-
begin
|
5
|
-
require 'rcov/rcovtask'
|
2
|
+
require 'fileutils'
|
6
3
|
|
7
|
-
|
8
|
-
|
9
|
-
t.test_files = FileList['test/**/*_test.rb']
|
10
|
-
t.rcov_opts = ["-T -x '/Library/Ruby/*'"]
|
11
|
-
t.verbose = true
|
12
|
-
end
|
13
|
-
rescue LoadError
|
14
|
-
puts "Rcov not available. Install it for rcov-related tasks with: sudo gem install rcov"
|
4
|
+
def gemspec
|
5
|
+
@gemspec ||= eval(File.read('gemspec'), binding, 'gemspec')
|
15
6
|
end
|
16
7
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
|
29
|
-
s.files = FileList["Rakefile", "VERSION.yml", "README.rdoc", "CHANGELOG.rdoc", "LICENSE.txt", "{lib,test}/**/*"]
|
30
|
-
end
|
8
|
+
desc "Build the gem"
|
9
|
+
task :gem=>:gemspec do
|
10
|
+
sh "gem build gemspec"
|
11
|
+
FileUtils.mkdir_p 'pkg'
|
12
|
+
FileUtils.mv "#{gemspec.name}-#{gemspec.version}.gem", 'pkg'
|
13
|
+
end
|
14
|
+
|
15
|
+
desc "Install the gem locally"
|
16
|
+
task :install => :gem do
|
17
|
+
sh %{gem install pkg/#{gemspec.name}-#{gemspec.version}}
|
18
|
+
end
|
31
19
|
|
32
|
-
|
33
|
-
|
20
|
+
desc "Generate the gemspec"
|
21
|
+
task :generate do
|
22
|
+
puts gemspec.to_ruby
|
34
23
|
end
|
35
24
|
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
t.verbose = false
|
25
|
+
desc "Validate the gemspec"
|
26
|
+
task :gemspec do
|
27
|
+
gemspec.validate
|
40
28
|
end
|
41
29
|
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
rdoc.options << '--line-numbers' << '--inline-source'
|
46
|
-
rdoc.rdoc_files.include('README*')
|
47
|
-
rdoc.rdoc_files.include('lib/**/*.rb')
|
30
|
+
desc 'Run tests'
|
31
|
+
task :test do |t|
|
32
|
+
sh 'bacon -q -Ilib -I. test/*_test.rb'
|
48
33
|
end
|
49
34
|
|
50
|
-
task :default => :test
|
35
|
+
task :default => :test
|
data/gemspec
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require 'rubygems' unless Object.const_defined?(:Gem)
|
3
|
+
require File.dirname(__FILE__) + "/lib/alias/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "alias"
|
7
|
+
s.version = Alias::VERSION
|
8
|
+
s.authors = ["Gabriel Horner"]
|
9
|
+
s.email = "gabriel.horner@gmail.com"
|
10
|
+
s.homepage = "http://tagaholic.me/alias/"
|
11
|
+
s.summary = "Creates, manages and saves aliases for class methods, instance methods, constants, delegated methods and more."
|
12
|
+
s.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."
|
13
|
+
s.required_rubygems_version = ">= 1.3.6"
|
14
|
+
s.rubyforge_project = 'tagaholic'
|
15
|
+
s.add_development_dependency 'bacon'
|
16
|
+
s.add_development_dependency 'mocha'
|
17
|
+
s.add_development_dependency 'mocha-on-bacon'
|
18
|
+
s.files = Dir.glob(%w[{lib,test}/**/*.{rb,yml} bin/* [A-Z]*.{txt,rdoc} ext/**/*.{rb,c}]) + %w{Rakefile gemspec}
|
19
|
+
s.extra_rdoc_files = ["README.rdoc", "LICENSE.txt"]
|
20
|
+
end
|
data/lib/alias.rb
CHANGED
@@ -1,5 +1,3 @@
|
|
1
|
-
$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) ||
|
2
|
-
$:.include?(File.expand_path(File.dirname(__FILE__)))
|
3
1
|
require 'yaml'
|
4
2
|
require 'alias/manager'
|
5
3
|
require 'alias/validator'
|
@@ -11,6 +9,7 @@ require 'alias/creators/class_to_instance_method_creator'
|
|
11
9
|
require 'alias/creators/any_to_instance_method_creator'
|
12
10
|
require 'alias/util'
|
13
11
|
require 'alias/console'
|
12
|
+
require 'alias/version'
|
14
13
|
|
15
14
|
# Most of the core Alias actions are run through Alias::Manager except for Alias.create.
|
16
15
|
# See Alias::Manager for an explanation of how aliases are created.
|
data/test/alias_test.rb
CHANGED
@@ -1,63 +1,61 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper.rb')
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
end
|
3
|
+
describe "Alias" do
|
4
|
+
it "loads config file config/alias.yml if found" do
|
5
|
+
File.expects(:exists?).with('config/alias.yml').returns(true)
|
6
|
+
Alias.config_file.should == 'config/alias.yml'
|
7
|
+
end
|
9
8
|
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
9
|
+
describe "create" do
|
10
|
+
before { Alias.instance_eval "@manager = @config = @config_file = nil"}
|
11
|
+
|
12
|
+
it "with aliases option creates aliases" do
|
13
|
+
options = {:aliases=>{:constant=> {'Array'=>'Arr'}, :instance_method=>{'String'=>{'to_s'=>'s'}} } , :file=>false}
|
14
|
+
Alias.create options
|
15
|
+
Alias.manager.aliases_of(:instance_method).empty?.should == false
|
16
|
+
Alias.manager.aliases_of(:constant).empty?.should == false
|
17
|
+
Alias.config.should == options
|
18
|
+
end
|
19
|
+
|
20
|
+
it "with file option creates aliases" do
|
21
|
+
Alias.create :file=>File.join(File.dirname(__FILE__),'aliases.yml')
|
22
|
+
Alias.manager.aliases_of(:instance_method).empty?.should == false
|
23
|
+
Alias.manager.aliases_of(:class_method).empty?.should == false
|
24
|
+
Alias.manager.aliases_of(:constant).empty?.should == false
|
25
|
+
Alias.manager.aliases_of(:class_to_instance_method).empty?.should == false
|
26
|
+
end
|
28
27
|
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
28
|
+
it "with false file option doesn't load config file" do
|
29
|
+
Alias.create :file=>'blah'
|
30
|
+
File.expects(:exists?).never
|
31
|
+
Alias.create :file=>false
|
32
|
+
end
|
34
33
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
34
|
+
it "with invalid file option creates nothing" do
|
35
|
+
Alias.create :file=>'blah'
|
36
|
+
Alias.config.should == {:aliases=>{}}
|
37
|
+
end
|
38
|
+
|
39
|
+
it "with verbose option sets manager's verbose" do
|
40
|
+
Alias.manager.verbose.should == false
|
41
|
+
Alias.create :verbose=>true, :aliases=>{}, :file=>false
|
42
|
+
Alias.manager.verbose.should == true
|
43
|
+
end
|
45
44
|
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
45
|
+
it "with force option sets manager's verbose" do
|
46
|
+
Alias.manager.force.should == false
|
47
|
+
Alias.create :force=>true, :aliases=>{}
|
48
|
+
Alias.manager.force.should == true
|
49
|
+
end
|
51
50
|
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
end
|
51
|
+
it "called twice recursively merges config" do
|
52
|
+
hash1 = {:constant=>{"Blah"=>"B"}}
|
53
|
+
Alias.manager.expects(:create_aliases).with(:constant, hash1[:constant])
|
54
|
+
Alias.create :aliases=>hash1, :file=>false
|
55
|
+
hash2 = {:constant=>{"Blah2"=>"B2"}}
|
56
|
+
Alias.manager.expects(:create_aliases).with(:constant, hash2[:constant])
|
57
|
+
Alias.create :aliases=>hash2, :file=>false
|
58
|
+
Alias.config.should == {:aliases=>{:constant=>{"Blah"=>"B", "Blah2"=>"B2"}} }
|
61
59
|
end
|
62
60
|
end
|
63
|
-
end
|
61
|
+
end
|
@@ -1,39 +1,37 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper.rb')
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
before(:each) { @manager = Alias::Manager.new }
|
3
|
+
describe "AnyToInstanceMethodCreator" do
|
4
|
+
before { @manager = Manager.new }
|
6
5
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
6
|
+
def expect_aliases(hash)
|
7
|
+
arr = Creators::AnyToInstanceMethodCreator.maps_config(hash)
|
8
|
+
Creators::AnyToInstanceMethodCreator.expects(:generates_aliases).with(arr).returns('')
|
9
|
+
end
|
11
10
|
|
12
|
-
|
13
|
-
|
14
|
-
|
11
|
+
def create_aliases(hash)
|
12
|
+
@manager.create_aliases(:any_to_instance_method, hash)
|
13
|
+
end
|
15
14
|
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
15
|
+
xit "deletes invalid classes" do
|
16
|
+
expect_aliases 'String'=>{'String.to_s'=>'s'}
|
17
|
+
create_aliases 'String'=>{'String.to_s'=>'s'}, 'AnotherString'=>{'String.to_s'=>'s'}
|
18
|
+
end
|
20
19
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
20
|
+
xit "deletes existing method aliases" do
|
21
|
+
expect_aliases 'String'=>{'Date.commercial'=>'s'}
|
22
|
+
create_aliases 'String'=>{'Date.civil'=>'strip', 'Date.commercial'=>'s'}
|
23
|
+
end
|
25
24
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
25
|
+
it "creates aliases" do
|
26
|
+
Kernel.eval %[
|
27
|
+
class ::SomeClass
|
28
|
+
def self.cap; 'itup'; end
|
29
|
+
end
|
30
|
+
module ::SomeModule; end
|
31
|
+
]
|
32
|
+
create_aliases 'SomeModule'=>{'SomeClass.cap.to_sym'=>'c', 'SomeClass.cap.gsub'=>'gsub'}
|
33
|
+
obj = Object.new.extend SomeModule
|
34
|
+
SomeClass.cap.to_sym.should == obj.c
|
35
|
+
SomeClass.cap.gsub('cap','smack').should == obj.gsub('cap','smack')
|
38
36
|
end
|
39
37
|
end
|
@@ -1,42 +1,39 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper.rb')
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
Alias::Creators::ClassMethodCreator.expects(:generates_aliases).with(arr).returns('')
|
10
|
-
end
|
3
|
+
describe "ClassMethodCreator" do
|
4
|
+
before { @manager = Manager.new }
|
5
|
+
def expect_aliases(hash)
|
6
|
+
arr = Creators::ClassMethodCreator.maps_config(hash)
|
7
|
+
Creators::ClassMethodCreator.expects(:generates_aliases).with(arr).returns('')
|
8
|
+
end
|
11
9
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
test "deletes invalid class method keys" do
|
17
|
-
expect_aliases "Array"=>{}, "String"=>{'yaml_new'=>'yn'}
|
18
|
-
create_aliases 'String'=>{'yaml_new'=>'yn'},'Array'=>{'blah'=>'bl'}
|
19
|
-
end
|
10
|
+
def create_aliases(hash)
|
11
|
+
@manager.create_aliases(:class_method, hash)
|
12
|
+
end
|
20
13
|
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
14
|
+
it "deletes invalid class method keys" do
|
15
|
+
expect_aliases "Array"=>{}, "String"=>{'yaml_new'=>'yn'}
|
16
|
+
create_aliases 'String'=>{'yaml_new'=>'yn'},'Array'=>{'blah'=>'bl'}
|
17
|
+
end
|
25
18
|
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
19
|
+
it "deletes invalid classes" do
|
20
|
+
expect_aliases "String"=>{'yaml_new'=>'yn'}
|
21
|
+
create_aliases 'String'=>{'yaml_new'=>'yn'},'Blah'=>{'new'=>'n'}
|
22
|
+
end
|
23
|
+
|
24
|
+
it "deletes existing class method aliases" do
|
25
|
+
expect_aliases 'Date'=>{'valid_time?'=>'vt'}
|
26
|
+
create_aliases 'Date'=>{'civil_to_jd'=>'civil', 'valid_time?'=>'vt'}
|
27
|
+
end
|
30
28
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
end
|
29
|
+
it "creates class method aliases" do
|
30
|
+
Kernel.eval %[
|
31
|
+
class ::SampleClass
|
32
|
+
def self.cap; 'itup'; end
|
33
|
+
end
|
34
|
+
]
|
35
|
+
hash1 = {'SampleClass'=>{:cap=>:capohow}, 'Array'=>{:blah=>:bl}}
|
36
|
+
@manager.create_aliases(:class_method, hash1)
|
37
|
+
SampleClass.capohow.should == SampleClass.cap
|
41
38
|
end
|
42
39
|
end
|
@@ -1,48 +1,46 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper.rb')
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
SampleClass.cap.should == obj.c
|
46
|
-
end
|
3
|
+
describe "ClassToInstanceMethodCreator" do
|
4
|
+
before { @manager = Manager.new }
|
5
|
+
|
6
|
+
def expect_aliases(hash)
|
7
|
+
arr = Creators::ClassToInstanceMethodCreator.maps_config(hash)
|
8
|
+
Creators::ClassToInstanceMethodCreator.expects(:generates_aliases).with(arr).returns('')
|
9
|
+
end
|
10
|
+
|
11
|
+
def create_aliases(hash)
|
12
|
+
@manager.create_aliases(:class_to_instance_method, hash)
|
13
|
+
end
|
14
|
+
|
15
|
+
xit "deletes invalid to classes" do
|
16
|
+
expect_aliases 'String'=>{'String.to_s'=>'s'}
|
17
|
+
create_aliases 'String'=>{'AnotherString.name'=>'n', 'String.to_s'=>'s'}
|
18
|
+
end
|
19
|
+
|
20
|
+
xit "deletes invalid classes" do
|
21
|
+
expect_aliases 'String'=>{'String.to_s'=>'s'}
|
22
|
+
create_aliases 'String'=>{'String.to_s'=>'s'}, 'AnotherString'=>{'String.to_s'=>'s'}
|
23
|
+
end
|
24
|
+
|
25
|
+
xit "deletes existing method aliases" do
|
26
|
+
expect_aliases 'String'=>{'Date.commercial'=>'s'}
|
27
|
+
create_aliases 'String'=>{'Date.civil'=>'strip', 'Date.commercial'=>'s'}
|
28
|
+
end
|
29
|
+
|
30
|
+
it "deletes invalid to methods" do
|
31
|
+
expect_aliases 'String'=>{'Date.civil'=>'c'}
|
32
|
+
create_aliases 'String'=>{'Date.civil'=>'c', 'Date.uncivil'=>'uc'}
|
33
|
+
end
|
34
|
+
|
35
|
+
it "creates aliases" do
|
36
|
+
Kernel.eval %[
|
37
|
+
class ::SampleClass
|
38
|
+
def self.cap; 'itup'; end
|
39
|
+
end
|
40
|
+
module ::SampleModule; end
|
41
|
+
]
|
42
|
+
create_aliases 'SampleModule'=>{'SampleClass.cap'=>'c', 'Sampleclass.dap'=>'d'}
|
43
|
+
obj = Object.new.extend SampleModule
|
44
|
+
SampleClass.cap.should == obj.c
|
47
45
|
end
|
48
46
|
end
|