wrapit 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -24,6 +24,8 @@ Or install it yourself as:
24
24
 
25
25
  ## Usage
26
26
 
27
+ ### attr_wrappable
28
+
27
29
  So lets say we want to create some setters and getters for a class that come all
28
30
  wrapped and ready to go.
29
31
 
@@ -54,6 +56,8 @@ In addition to wrapping up the attribute readers, attr_wrappable creates *_naked
54
56
  foo.test_attr = "foo"
55
57
  foo.test_attr_naked = "foo"
56
58
 
59
+ ### method_wrappable
60
+
57
61
  Now lets say you have a method you have inherited from a superclass you want to wrap.
58
62
 
59
63
  class Foo
@@ -76,6 +80,11 @@ Now lets say you have a method you have inherited from a superclass you want to
76
80
 
77
81
  And that's it!
78
82
 
83
+ ### Further Reading
84
+
85
+ For more info on what you can do with a wrapped value have a look at the
86
+ [wrapped](https://github.com/mike-burns/wrapped) gem.
87
+
79
88
  ## Limitations
80
89
 
81
90
  At the moment method_wrappable is only usable on methods defined in a superclass and
@@ -5,37 +5,24 @@ module Wrapit::MethodWrappable
5
5
 
6
6
  def method_wrappable(*args)
7
7
  args.each do |method|
8
- has_args = (instance_method(method).arity != 0)
9
- mw_create_naked_method(method, has_args)
10
- mw_create_wrapped_method(method, has_args)
8
+ mw_create_naked_method(method)
9
+ mw_create_wrapped_method(method)
11
10
  end
12
11
  end
13
12
 
14
- def mw_create_naked_method(method, has_args)
13
+ def mw_create_naked_method(method)
15
14
  raise Wrapit::InvalidCallerError unless caller[0] =~ /method_wrappable/
16
15
 
17
- if has_args
18
- define_method :"#{method}_naked" do |*args|
19
- self.class.superclass.instance_method(method).bind(self).call(*args)
20
- end
21
- else
22
- define_method :"#{method}_naked" do
23
- self.class.superclass.instance_method(method).bind(self).call
24
- end
16
+ define_method :"#{method}_naked" do |*args|
17
+ self.class.superclass.instance_method(method).bind(self).call(*args)
25
18
  end
26
19
  end
27
20
 
28
- def mw_create_wrapped_method(method, has_args)
21
+ def mw_create_wrapped_method(method)
29
22
  raise Wrapit::InvalidCallerError unless caller[0] =~ /method_wrappable/
30
23
 
31
- if has_args
32
- define_method method do |*args|
33
- super(*args).wrapped
34
- end
35
- else
36
- define_method method do
37
- super().wrapped
38
- end
24
+ define_method method do |*args|
25
+ super(*args).wrapped
39
26
  end
40
27
  end
41
28
  end
@@ -1,3 +1,3 @@
1
1
  module Wrapit
2
- VERSION = "0.2.2"
2
+ VERSION = "0.2.3"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: wrapit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -127,7 +127,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
127
127
  version: '0'
128
128
  segments:
129
129
  - 0
130
- hash: -1557926693994722533
130
+ hash: 2232055303226340921
131
131
  required_rubygems_version: !ruby/object:Gem::Requirement
132
132
  none: false
133
133
  requirements:
@@ -136,7 +136,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
136
  version: '0'
137
137
  segments:
138
138
  - 0
139
- hash: -1557926693994722533
139
+ hash: 2232055303226340921
140
140
  requirements: []
141
141
  rubyforge_project:
142
142
  rubygems_version: 1.8.25