rubyrator 0.1.1 → 0.2.0
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.
- checksums.yaml +4 -4
- data/CHANGELOG.md +14 -0
- data/README.md +0 -2
- data/lib/rubyrator/rubyrator.rb +35 -1
- data/lib/rubyrator/version.rb +1 -1
- data/spec/rubyrator/rubyrator_spec.rb +8 -0
- data/spec/spec_helper.rb +12 -0
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: aed36798d3d4c431031f61fd8916b8d75b8e79ee
|
|
4
|
+
data.tar.gz: 27a0f8bcef922005cd6a60a1fb2efc255e697c4a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3bd83e6837a300c4e75afe6cc182364fc92e4cedb7c607880efd4c77b69a0c05726e84347847a43ded9545483b6cc5e9c738d35d98ed6501824788e9662e94cc
|
|
7
|
+
data.tar.gz: a4f66b905adb14de24fdf074dd4fd06ac206dfd72734b2bcc88a3f0686e80ea1f09af24e1d3b550ed1c4fe5356cb3bcf0c88c40fa757ae91f5bb89c62b20edcf
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
Change Log
|
|
2
|
+
===============================================================================
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
Version 0.2.0 *(2013-05-03)*
|
|
6
|
+
----------------------------
|
|
7
|
+
* Possibility to decorate class methods.
|
|
8
|
+
* Respecting method visibility, private stays private.
|
|
9
|
+
* Small refactorings.
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
Version 0.1.1 *(2013-04-27)*
|
|
13
|
+
----------------------------
|
|
14
|
+
Initial release.
|
data/README.md
CHANGED
|
@@ -28,7 +28,6 @@ class Html
|
|
|
28
28
|
def text(text)
|
|
29
29
|
text
|
|
30
30
|
end
|
|
31
|
-
|
|
32
31
|
end
|
|
33
32
|
|
|
34
33
|
puts Html.new.text("decorate me please") # => "<b><i>decorate me please</i></b>"
|
|
@@ -51,7 +50,6 @@ class Spamer
|
|
|
51
50
|
def spam(spam_message)
|
|
52
51
|
print spam_message
|
|
53
52
|
end
|
|
54
|
-
|
|
55
53
|
end
|
|
56
54
|
|
|
57
55
|
Spamer.new.spam("spam") # => "spamspamspam"
|
data/lib/rubyrator/rubyrator.rb
CHANGED
|
@@ -1,17 +1,51 @@
|
|
|
1
1
|
module Rubyrator
|
|
2
2
|
|
|
3
3
|
def decorate(decorator, *decorator_args)
|
|
4
|
+
decorate_class_method(decorator, *decorator_args)
|
|
5
|
+
decorate_instance_method(decorator, *decorator_args)
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
private
|
|
9
|
+
|
|
10
|
+
def decorate_class_method(decorator, *decorator_args)
|
|
11
|
+
m_decorator = instance_method(decorator)
|
|
12
|
+
|
|
13
|
+
define_singleton_method(:singleton_method_added) do |name|
|
|
14
|
+
if name.to_sym != :method_added && name.to_sym != :singleton_method_added
|
|
15
|
+
class << self
|
|
16
|
+
remove_method :singleton_method_added
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
to_decorate = method(name)
|
|
20
|
+
define_singleton_method(name) do |*args, &block|
|
|
21
|
+
m_decorator.bind(self.new).call(decorator_args, to_decorate, *args, &block)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def decorate_instance_method(decorator, *decorator_args)
|
|
4
28
|
m_decorator = instance_method(decorator)
|
|
5
29
|
meth_added = method(:method_added)
|
|
6
30
|
|
|
7
31
|
define_singleton_method(:method_added) do |name|
|
|
8
32
|
to_decorate = instance_method(name)
|
|
9
33
|
define_singleton_method(:method_added, &meth_added)
|
|
34
|
+
|
|
35
|
+
if private_method_defined?(name); visibility = :private
|
|
36
|
+
elsif protected_method_defined?(name); visibility = :protected
|
|
37
|
+
else visibility = :public
|
|
38
|
+
end
|
|
10
39
|
|
|
11
40
|
define_method(name) do |*args, &block|
|
|
12
41
|
m_decorator.bind(self).call(decorator_args, to_decorate.bind(self), *args, &block)
|
|
13
42
|
end
|
|
43
|
+
|
|
44
|
+
case visibility
|
|
45
|
+
when :protected; protected name
|
|
46
|
+
when :private; private name
|
|
47
|
+
end
|
|
14
48
|
end
|
|
15
|
-
end
|
|
49
|
+
end
|
|
16
50
|
|
|
17
51
|
end
|
data/lib/rubyrator/version.rb
CHANGED
|
@@ -20,6 +20,14 @@ describe Rubyrator do
|
|
|
20
20
|
@simple_dec.text_single_decorated("test").should eql "<b>test</b>"
|
|
21
21
|
end
|
|
22
22
|
|
|
23
|
+
it "decorates a class method" do
|
|
24
|
+
SimpleDecorator.text_class_method("test").should eql "<b>test</b>"
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
it "should not change method visibility" do
|
|
28
|
+
expect { @simple_dec.text_private("test") }.to raise_error(NoMethodError)
|
|
29
|
+
end
|
|
30
|
+
|
|
23
31
|
end
|
|
24
32
|
|
|
25
33
|
describe ArgumentsDecorator do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: rubyrator
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.2.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Artur Termenji
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: bin
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2013-
|
|
11
|
+
date: 2013-05-03 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: rake
|
|
@@ -46,6 +46,7 @@ extensions: []
|
|
|
46
46
|
extra_rdoc_files: []
|
|
47
47
|
files:
|
|
48
48
|
- .gitignore
|
|
49
|
+
- CHANGELOG.md
|
|
49
50
|
- Gemfile
|
|
50
51
|
- LICENSE
|
|
51
52
|
- README.md
|