sugar-high 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -9,16 +9,35 @@ class Module
9
9
  # insert_into_xxx becomes inject_into_xxx and update_xxx
10
10
  # read_xxx becomes xxx_content (overriding default :after action to insert at the X)
11
11
 
12
- def multi_alias name, options={}
13
- config_options = options[:options]
12
+ def multi_alias *args
13
+ name = case args.first
14
+ when Symbol, String
15
+ args.first.to_s
16
+ when Hash
17
+ # default is :after
18
+ args.first[:_before_] ? :before : :after
19
+ end
20
+
21
+ if name.kind_of? Symbol
22
+ config_options = name
23
+ options = args.first
24
+ name = options[:"_#{name}_"]
25
+ else
26
+ options = args[1]
27
+ end
28
+
29
+ raise ArgumentError, "Name of method pattern to alias not specified. Please pass name as either first argument or as :before or :after option" if !name
30
+
31
+ options.delete(:_after_)
32
+ options.delete(:_before_)
33
+
14
34
  options.each_pair do |original, aliases|
15
- next if original == :options
16
- alias_methods name, original, [aliases].flatten, config_options
35
+ alias_methods name.to_sym, original, [aliases].flatten, config_options
17
36
  end
18
37
  end
19
38
 
20
39
  def alias_methods name, original, aliases, config_options
21
- aliases.each do |alias_name|
40
+ aliases.each do |alias_name|
22
41
  new_alias = make_name(name, alias_name.to_s, config_options)
23
42
  original_name = make_name(name, original.to_s, config_options)
24
43
  begin
@@ -32,12 +51,12 @@ class Module
32
51
  protected
33
52
 
34
53
  def make_name name, alias_name, config_options
35
- return alias_name.gsub(/X/, name.to_s) if alias_name =~ /X/
54
+ return alias_name.gsub(/X/, name.to_s) if alias_name =~ /X/
36
55
  case config_options
37
- when :after
38
- "#{alias_name}_#{name}"
39
56
  when :before
40
57
  "#{name}_#{alias_name}"
58
+ else # default
59
+ "#{alias_name}_#{name}"
41
60
  end
42
61
  end
43
62
  end
@@ -9,25 +9,41 @@ require 'spec_helper'
9
9
  require 'sugar-high/alias'
10
10
 
11
11
  class Abc
12
+ def hello_kristian
13
+ 'hello'
14
+ end
15
+ multi_alias :_after_ => :kristian, :hello => :howdy
16
+ end
17
+
18
+ class Xyz
12
19
  def hello_kristian
13
20
  'hi'
14
21
  end
15
- multi_alias :kristian, :hello => :howdy, :options => :after
22
+
23
+ multi_alias :kristian, :hello => :alloha
24
+ end
25
+
26
+ class Ged
27
+ def kristian_hello
28
+ 'hejsa'
29
+ end
30
+
31
+ multi_alias :_before_ => :kristian, :hello => :hejsa
16
32
  end
17
33
 
18
34
  describe "SugarHigh" do
19
- describe "Arguments" do
20
- before do
21
- @obj = Abc.new
22
- end
23
-
24
- context 'Aliased :hello_kristian with :howdy_kristian ' do
35
+ describe "Arguments" do
36
+ context 'hould alias :hello_kristian with :howdy_kristian ' do
25
37
  it "should find alias" do
26
- @obj.respond_to?(:howdy_kristian).should be_true
38
+ Abc.new.respond_to?(:howdy_kristian).should be_true
39
+ end
40
+
41
+ it "should find -alloha alias method for kristian" do
42
+ Xyz.new.respond_to?(:alloha_kristian).should be_true
27
43
  end
28
44
 
29
- it "should find all methods saying 'hi' to kristian" do
30
- Abc.new.get_methods(:all).sort.grep(/(.*)_kristian$/).should have(2).items
45
+ it "should find -hejsa alias method for kristian" do
46
+ Ged.new.respond_to?(:kristian_hejsa).should be_true
31
47
  end
32
48
  end
33
49
  end
data/sugar-high.gemspec CHANGED
@@ -5,7 +5,7 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{sugar-high}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Kristian Mandrup"]
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 1
8
- - 1
9
- version: 0.1.1
8
+ - 2
9
+ version: 0.1.2
10
10
  platform: ruby
11
11
  authors:
12
12
  - Kristian Mandrup