substituter 0.0.2 → 0.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # Substituter
2
2
 
3
- Substituter is designed to easily override an existing class instance method with a provided Proc. The existing method is renamed and a reference is kept to this original method so that the new Proc that is executed will be able to call the original method and has access to its parameters.
3
+ Substituter is designed to easily substitute an existing class instance method with a provided Proc. The existing method is renamed and a reference is kept to this original method so that the new Proc that is executed will be able to call the original method and has access to its parameters.
4
4
 
5
5
  ## Installation
6
6
 
@@ -24,9 +24,14 @@ my_proc = Proc.new{|original_method,*args|
24
24
  }
25
25
 
26
26
  Substituter.sub String, :to_s, my_proc
27
- puts String.new("So Cool!")
27
+ puts String.new("So Cool!").to_s
28
28
 
29
- #returns "My proc info and original methods value = So Cool!"
29
+ #-> "My proc info and original methods value = So Cool!"
30
+
31
+ #to see a list of all substituted methods
32
+ Substituter.ls
33
+
34
+ #-> {"String" => [:to_s]}
30
35
 
31
36
  #to restore the original method just clear the substitute
32
37
  Substituter.clear String, :to_s
@@ -61,7 +66,7 @@ Sample.new.taking_a_param_and_block("Hello") do |param|
61
66
  "#{param} World"
62
67
  end
63
68
 
64
- #returns "My proc info and original methods value = Hello World!"
69
+ #-> "My proc info and original methods value = Hello World!"
65
70
 
66
71
  #see the spec/substituter_spec.rb for examples
67
72
 
data/lib/substituter.rb CHANGED
@@ -1,7 +1,4 @@
1
1
  require "substituter/version"
2
- def Hijack(klass, method, &aproc)
3
- Substituter.sub(klass, method, &aproc)
4
- end
5
2
 
6
3
  module Substituter
7
4
 
@@ -14,7 +11,6 @@ module Substituter
14
11
 
15
12
  def clear(klass, method)
16
13
  klass.class_eval %Q(
17
- remove_method method
18
14
  alias_method :#{method.to_s}, :#{prefix(method)}
19
15
  remove_method :#{prefix(method)}
20
16
  ), __FILE__, __LINE__
@@ -25,6 +21,10 @@ module Substituter
25
21
  @stored_procs[klass.to_s + method.to_s]
26
22
  end
27
23
 
24
+ def ls
25
+ @handled_methods.select{|key,value| !value.empty?}
26
+ end
27
+
28
28
  def prefix(method)
29
29
  @method_rename_prefix + method.to_s
30
30
  end
@@ -1,3 +1,3 @@
1
1
  module Substituter
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -51,6 +51,14 @@ describe Substituter do
51
51
  Substituter.clear SampleClass, :one_param
52
52
  end
53
53
 
54
+ it ".ls will provide a hash of all the currently substituted methods" do
55
+ Substituter.sub(SampleClass, :one_param) {"a"}
56
+ Substituter.sub(SampleClass, :two_params) {"a"}
57
+ Substituter.ls.must_equal({"SampleClass"=>[:one_param,:two_params]})
58
+ Substituter.clear SampleClass, :one_param
59
+ Substituter.clear SampleClass, :two_params
60
+ end
61
+
54
62
  it ".sub handles two params properly" do
55
63
  myproc = Proc.new { |original_method, *args|
56
64
  "Proc knows original = #{original_method.call(*args)}"
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: substituter
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2014-04-04 00:00:00.000000000 Z
12
+ date: 2014-04-07 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -77,7 +77,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
77
77
  version: '0'
78
78
  segments:
79
79
  - 0
80
- hash: 2961750756671559302
80
+ hash: -398152166756221061
81
81
  required_rubygems_version: !ruby/object:Gem::Requirement
82
82
  none: false
83
83
  requirements:
@@ -86,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
86
86
  version: '0'
87
87
  segments:
88
88
  - 0
89
- hash: 2961750756671559302
89
+ hash: -398152166756221061
90
90
  requirements: []
91
91
  rubyforge_project:
92
92
  rubygems_version: 1.8.23