rubyrator 0.1.1 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eb7d7045a9b95cb93f02bc9fd422c9dc68dea14e
4
- data.tar.gz: 311b58e2bf61f656648a5b1700dcafa5769c5359
3
+ metadata.gz: aed36798d3d4c431031f61fd8916b8d75b8e79ee
4
+ data.tar.gz: 27a0f8bcef922005cd6a60a1fb2efc255e697c4a
5
5
  SHA512:
6
- metadata.gz: 9a28cd53e733277331918048858cfbdcb874d8ce79a0044886db460071005f69a245d0aeef8b1302e646605bf880923d432b265594fbf71f3f0651666fd71b33
7
- data.tar.gz: a4334474ecf7f102bc479b66569a4bf7aa148dab3a1a916c0b819225b72352f16dc1b300f9c06bd8fe2cab127f442d39a6b32a9bd4a79055f89a22e4630340e2
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"
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Rubyrator
2
- VERSION = "0.1.1"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -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
@@ -26,6 +26,18 @@ class SimpleDecorator
26
26
  text
27
27
  end
28
28
 
29
+ decorate :bold
30
+ def self.text_class_method(text)
31
+ text
32
+ end
33
+
34
+ private
35
+
36
+ decorate :bold
37
+ def text_private(text)
38
+ text
39
+ end
40
+
29
41
  end
30
42
 
31
43
  class ArgumentsDecorator
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.1.1
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-04-28 00:00:00.000000000 Z
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