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/test/test_helper.rb
CHANGED
@@ -1,12 +1,12 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
require 'mocha' #gem install mocha
|
5
|
-
require 'matchy' #gem install jeremymcanally-matchy -s http://gems.github.com
|
6
|
-
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
1
|
+
require 'bacon'
|
2
|
+
require 'mocha'
|
3
|
+
require 'mocha-on-bacon'
|
7
4
|
require 'alias'
|
5
|
+
include Alias
|
8
6
|
|
9
|
-
class
|
7
|
+
class Bacon::Context
|
8
|
+
def before_all; yield; end
|
9
|
+
def xit(*args); end
|
10
10
|
def capture_stdout(&block)
|
11
11
|
original_stdout = $stdout
|
12
12
|
$stdout = fake = StringIO.new
|
data/test/util_test.rb
CHANGED
@@ -1,42 +1,40 @@
|
|
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
|
-
Util.make_shortest_aliases(['Yo','Yay','Cool','Man']).should == expected_hash
|
40
|
-
end
|
3
|
+
describe "Util" do
|
4
|
+
it "any_const_get fetches simple class" do
|
5
|
+
Util.any_const_get("Array").should == Array
|
6
|
+
end
|
7
|
+
|
8
|
+
it "any_const_get fetches nested class" do
|
9
|
+
eval "module ::Somemodule; class Someclass; end; end"
|
10
|
+
Util.any_const_get("Somemodule::Someclass").should == Somemodule::Someclass
|
11
|
+
end
|
12
|
+
|
13
|
+
it "any_const_get returns nil for nonexistent class" do
|
14
|
+
Util.any_const_get("NonexistentClass").should == nil
|
15
|
+
end
|
16
|
+
|
17
|
+
it "slice only returns valid keys given" do
|
18
|
+
Util.slice({:a=>1,:b=>2}, :a, :c).should == {:a=>1}
|
19
|
+
end
|
20
|
+
|
21
|
+
it "slice_off! returns given keys but takes them off existing hash" do
|
22
|
+
h = {:a=>1, :b=>2}
|
23
|
+
Util.slice_off!(h, :a, :c).should == {:a=>1}
|
24
|
+
h.should == {:b=>2}
|
25
|
+
end
|
26
|
+
|
27
|
+
it "camelize should uppercase non-underscored string" do
|
28
|
+
Util.camelize('man').should == 'Man'
|
29
|
+
end
|
30
|
+
|
31
|
+
it "camelize should camelize underscored string" do
|
32
|
+
Util.camelize('some_test').should == 'SomeTest'
|
33
|
+
end
|
34
|
+
|
35
|
+
it "make_shortest_aliases" do
|
36
|
+
eval "::Y = 'some value'"
|
37
|
+
expected_hash = {"Yo"=>"Y", "Man"=>"M", "Cool"=>"C", 'Yay'=>'Ya'}
|
38
|
+
Util.make_shortest_aliases(['Yo','Yay','Cool','Man']).should == expected_hash
|
41
39
|
end
|
42
40
|
end
|
data/test/validator_test.rb
CHANGED
@@ -1,72 +1,70 @@
|
|
1
1
|
require File.join(File.dirname(__FILE__), 'test_helper.rb')
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
before(:each) { Alias::Validator.instance_eval "@validators = {}"}
|
3
|
+
describe "Validator" do
|
4
|
+
before_all { eval "class ::TestCreator < Alias::Creator; end"}
|
5
|
+
before { Validator.instance_eval "@validators = {}"}
|
7
6
|
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
7
|
+
def validate(options={})
|
8
|
+
creator = TestCreator.new
|
9
|
+
options.each {|k,v| creator.send("#{k}=",v)}
|
10
|
+
@validator.validate(creator, {}, :blah)
|
11
|
+
end
|
13
12
|
|
14
|
-
|
15
|
-
|
16
|
-
|
13
|
+
def validator_message
|
14
|
+
@validator.create_message(:blah)
|
15
|
+
end
|
17
16
|
|
18
|
-
|
19
|
-
|
20
|
-
|
17
|
+
def create_validator(options)
|
18
|
+
@validator = TestCreator.valid :num, options
|
19
|
+
end
|
21
20
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
21
|
+
def create_parent_validator(key)
|
22
|
+
Validator.register_validators [{:key=>key, :if=>lambda {|e| 'yo'}, :message=>lambda {|e| 'cool'}}]
|
23
|
+
@parent_validator = Validator.validators[key]
|
24
|
+
end
|
26
25
|
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
26
|
+
it "copies a validator when using a previous one" do
|
27
|
+
create_parent_validator :num
|
28
|
+
create_validator :if=>:num
|
29
|
+
@parent_validator.validate(TestCreator.new, {}, :blah).should == validate
|
30
|
+
end
|
32
31
|
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
32
|
+
it "inherits a validator's message when using a previous one" do
|
33
|
+
create_parent_validator :num
|
34
|
+
create_validator :if=>:num
|
35
|
+
validator_message.should == 'cool'
|
36
|
+
end
|
38
37
|
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
38
|
+
it "overrides an inherited message with explicit message" do
|
39
|
+
create_parent_validator :num
|
40
|
+
create_validator :if=>:num, :message=>lambda {|e| 'cooler'}
|
41
|
+
validator_message.should == 'cooler'
|
42
|
+
end
|
44
43
|
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
44
|
+
it "sets a default message if an invalid one is given" do
|
45
|
+
create_validator :if=>lambda {|e| 'yo'}, :message=>:blah
|
46
|
+
validator_message.should =~ /Validation failed/
|
47
|
+
end
|
49
48
|
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
49
|
+
it "with :with option sets proc arg" do
|
50
|
+
create_validator :if=>lambda {|e| 'yo'}, :with=>[:a, :b]
|
51
|
+
@validator.validation_proc.expects(:call).with(['a','c'])
|
52
|
+
@validator.validate(TestCreator.new, {:a=>'a', :b=>'c', :c=>'d'}, :c)
|
53
|
+
end
|
55
54
|
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
55
|
+
it "with :unless option negates result and changes message" do
|
56
|
+
create_validator :unless=>lambda {|e| true }, :message=>lambda {|e| "yo doesn't exist"}
|
57
|
+
validate.should == false
|
58
|
+
validator_message.should == 'yo already exists'
|
59
|
+
end
|
61
60
|
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
61
|
+
it "with :optional option can be forced" do
|
62
|
+
create_validator :if=>lambda { false }, :optional=>true
|
63
|
+
validate(:force=>true).should == true
|
64
|
+
end
|
66
65
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
end
|
66
|
+
it "without :optional option cannot be forced" do
|
67
|
+
create_validator :if=>lambda {|e| false }
|
68
|
+
validate(:force=>true).should == false
|
71
69
|
end
|
72
70
|
end
|
metadata
CHANGED
@@ -1,7 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: alias
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 2
|
8
|
+
- 2
|
9
|
+
version: 0.2.2
|
5
10
|
platform: ruby
|
6
11
|
authors:
|
7
12
|
- Gabriel Horner
|
@@ -9,10 +14,48 @@ autorequire:
|
|
9
14
|
bindir: bin
|
10
15
|
cert_chain: []
|
11
16
|
|
12
|
-
date:
|
17
|
+
date: 2010-06-11 00:00:00 -04:00
|
13
18
|
default_executable:
|
14
|
-
dependencies:
|
15
|
-
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: bacon
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
none: false
|
25
|
+
requirements:
|
26
|
+
- - ">="
|
27
|
+
- !ruby/object:Gem::Version
|
28
|
+
segments:
|
29
|
+
- 0
|
30
|
+
version: "0"
|
31
|
+
type: :development
|
32
|
+
version_requirements: *id001
|
33
|
+
- !ruby/object:Gem::Dependency
|
34
|
+
name: mocha
|
35
|
+
prerelease: false
|
36
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
37
|
+
none: false
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 0
|
43
|
+
version: "0"
|
44
|
+
type: :development
|
45
|
+
version_requirements: *id002
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: mocha-on-bacon
|
48
|
+
prerelease: false
|
49
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
segments:
|
55
|
+
- 0
|
56
|
+
version: "0"
|
57
|
+
type: :development
|
58
|
+
version_requirements: *id003
|
16
59
|
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.
|
17
60
|
email: gabriel.horner@gmail.com
|
18
61
|
executables: []
|
@@ -20,15 +63,9 @@ executables: []
|
|
20
63
|
extensions: []
|
21
64
|
|
22
65
|
extra_rdoc_files:
|
23
|
-
- LICENSE.txt
|
24
66
|
- README.rdoc
|
25
|
-
files:
|
26
|
-
- CHANGELOG.rdoc
|
27
67
|
- LICENSE.txt
|
28
|
-
|
29
|
-
- Rakefile
|
30
|
-
- VERSION.yml
|
31
|
-
- lib/alias.rb
|
68
|
+
files:
|
32
69
|
- lib/alias/console.rb
|
33
70
|
- lib/alias/creator.rb
|
34
71
|
- lib/alias/creators/any_to_instance_method_creator.rb
|
@@ -39,8 +76,9 @@ files:
|
|
39
76
|
- lib/alias/manager.rb
|
40
77
|
- lib/alias/util.rb
|
41
78
|
- lib/alias/validator.rb
|
79
|
+
- lib/alias/version.rb
|
80
|
+
- lib/alias.rb
|
42
81
|
- test/alias_test.rb
|
43
|
-
- test/aliases.yml
|
44
82
|
- test/any_to_instance_method_creator_test.rb
|
45
83
|
- test/class_method_creator_test.rb
|
46
84
|
- test/class_to_instance_method_creator_test.rb
|
@@ -52,44 +90,45 @@ files:
|
|
52
90
|
- test/test_helper.rb
|
53
91
|
- test/util_test.rb
|
54
92
|
- test/validator_test.rb
|
93
|
+
- test/aliases.yml
|
94
|
+
- LICENSE.txt
|
95
|
+
- CHANGELOG.rdoc
|
96
|
+
- README.rdoc
|
97
|
+
- Rakefile
|
98
|
+
- gemspec
|
55
99
|
has_rdoc: true
|
56
100
|
homepage: http://tagaholic.me/alias/
|
57
101
|
licenses: []
|
58
102
|
|
59
103
|
post_install_message:
|
60
|
-
rdoc_options:
|
61
|
-
|
104
|
+
rdoc_options: []
|
105
|
+
|
62
106
|
require_paths:
|
63
107
|
- lib
|
64
108
|
required_ruby_version: !ruby/object:Gem::Requirement
|
109
|
+
none: false
|
65
110
|
requirements:
|
66
111
|
- - ">="
|
67
112
|
- !ruby/object:Gem::Version
|
113
|
+
segments:
|
114
|
+
- 0
|
68
115
|
version: "0"
|
69
|
-
version:
|
70
116
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
71
118
|
requirements:
|
72
119
|
- - ">="
|
73
120
|
- !ruby/object:Gem::Version
|
74
|
-
|
75
|
-
|
121
|
+
segments:
|
122
|
+
- 1
|
123
|
+
- 3
|
124
|
+
- 6
|
125
|
+
version: 1.3.6
|
76
126
|
requirements: []
|
77
127
|
|
78
128
|
rubyforge_project: tagaholic
|
79
|
-
rubygems_version: 1.3.
|
129
|
+
rubygems_version: 1.3.7
|
80
130
|
signing_key:
|
81
131
|
specification_version: 3
|
82
132
|
summary: Creates, manages and saves aliases for class methods, instance methods, constants, delegated methods and more.
|
83
|
-
test_files:
|
84
|
-
|
85
|
-
- test/any_to_instance_method_creator_test.rb
|
86
|
-
- test/class_method_creator_test.rb
|
87
|
-
- test/class_to_instance_method_creator_test.rb
|
88
|
-
- test/console_test.rb
|
89
|
-
- test/constant_creator_test.rb
|
90
|
-
- test/creator_test.rb
|
91
|
-
- test/instance_method_creator_test.rb
|
92
|
-
- test/manager_test.rb
|
93
|
-
- test/test_helper.rb
|
94
|
-
- test/util_test.rb
|
95
|
-
- test/validator_test.rb
|
133
|
+
test_files: []
|
134
|
+
|
data/VERSION.yml
DELETED