rubyrator 0.1.1

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: eb7d7045a9b95cb93f02bc9fd422c9dc68dea14e
4
+ data.tar.gz: 311b58e2bf61f656648a5b1700dcafa5769c5359
5
+ SHA512:
6
+ metadata.gz: 9a28cd53e733277331918048858cfbdcb874d8ce79a0044886db460071005f69a245d0aeef8b1302e646605bf880923d432b265594fbf71f3f0651666fd71b33
7
+ data.tar.gz: a4334474ecf7f102bc479b66569a4bf7aa148dab3a1a916c0b819225b72352f16dc1b300f9c06bd8fe2cab127f442d39a6b32a9bd4a79055f89a22e4630340e2
data/.gitignore ADDED
@@ -0,0 +1,19 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+ Gemfile.lock
15
+
16
+ # YARD artifacts
17
+ .yardoc
18
+ _yardoc
19
+ doc/
data/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source "http://rubygems.org"
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 Artur Termenji
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,64 @@
1
+ # Rubyrator
2
+
3
+ Python like method decorators for Ruby.
4
+
5
+ ## Installation
6
+ `gem install rubyrator`
7
+
8
+ ## Usage
9
+
10
+ Extend Rubyrator in a class where you want to use it, and then stick `decorate :decorator_method_name` before your method declaration to decorate the method.
11
+
12
+ You can set multiple decorators for your methods.
13
+
14
+ ```ruby
15
+ class Html
16
+ extend Rubyrator
17
+
18
+ def bold(dec_args, orig, *args, &block)
19
+ "<b>" + orig.call(*args, &block) + "</b>"
20
+ end
21
+
22
+ def italic(dec_args, orig, *args, &block)
23
+ "<i>" + orig.call(*args, &block) + "</i>"
24
+ end
25
+
26
+ decorate :bold
27
+ decorate :italic
28
+ def text(text)
29
+ text
30
+ end
31
+
32
+ end
33
+
34
+ puts Html.new.text("decorate me please") # => "<b><i>decorate me please</i></b>"
35
+ ```
36
+
37
+ You can add parameters to your decorator methods. Just pass them after a decorator method name, separated by the comma.
38
+
39
+ ```ruby
40
+ class Spamer
41
+ extend Rubyrator
42
+
43
+ def retry(dec_args, orig, *args, &block)
44
+ retry_num = dec_args[0]
45
+ retry_num.times do
46
+ orig.call(*args, &block)
47
+ end
48
+ end
49
+
50
+ decorate :retry, 3
51
+ def spam(spam_message)
52
+ print spam_message
53
+ end
54
+
55
+ end
56
+
57
+ Spamer.new.spam("spam") # => "spamspamspam"
58
+ ```
59
+
60
+ ## License
61
+
62
+ Released under the MIT License. See the [LICENSE][] file for further details.
63
+
64
+ [license]: LICENSE
data/Rakefile ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env rake
2
+ require "bundler/gem_tasks"
3
+
4
+ require "rspec/core/rake_task"
5
+
6
+ RSpec::Core::RakeTask.new(:spec)
7
+
8
+ task :default => :spec
@@ -0,0 +1,17 @@
1
+ module Rubyrator
2
+
3
+ def decorate(decorator, *decorator_args)
4
+ m_decorator = instance_method(decorator)
5
+ meth_added = method(:method_added)
6
+
7
+ define_singleton_method(:method_added) do |name|
8
+ to_decorate = instance_method(name)
9
+ define_singleton_method(:method_added, &meth_added)
10
+
11
+ define_method(name) do |*args, &block|
12
+ m_decorator.bind(self).call(decorator_args, to_decorate.bind(self), *args, &block)
13
+ end
14
+ end
15
+ end
16
+
17
+ end
@@ -0,0 +1,3 @@
1
+ module Rubyrator
2
+ VERSION = "0.1.1"
3
+ end
data/lib/rubyrator.rb ADDED
@@ -0,0 +1,6 @@
1
+ require 'rubyrator/version'
2
+ require 'rubyrator/rubyrator'
3
+
4
+ module Rubyrator
5
+
6
+ end
data/rubyrator.gemspec ADDED
@@ -0,0 +1,24 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib_dir = File.expand_path('lib', File.dirname(__FILE__))
3
+ $LOAD_PATH.unshift(lib_dir) unless $LOAD_PATH.include?(lib_dir)
4
+ require 'rubyrator/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "rubyrator"
8
+ gem.version = Rubyrator::VERSION
9
+ gem.authors = ["Artur Termenji"]
10
+ gem.email = ["atermenji@gmail.com"]
11
+ gem.summary = %q{Python like method decorators for Ruby}
12
+ gem.description = %q{Python like method decorators for Ruby}
13
+ gem.homepage = "http://github.com/atermenji/rubyrator"
14
+ gem.licenses = ["MIT"]
15
+
16
+ gem.files = `git ls-files`.split($\)
17
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
18
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
19
+ gem.require_paths = ["lib"]
20
+ gem.platform = Gem::Platform::RUBY
21
+
22
+ gem.add_development_dependency "rake"
23
+ gem.add_development_dependency "rspec"
24
+ end
@@ -0,0 +1,41 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rubyrator do
4
+
5
+ describe SimpleDecorator do
6
+
7
+ before :each do
8
+ @simple_dec = SimpleDecorator.new
9
+ end
10
+
11
+ it "decorates a method with multiple simple decoratos" do
12
+ @simple_dec.text_double_decorated("test").should eql "<b><i>test</i></b>"
13
+ end
14
+
15
+ it "is not decorating a method after decorated method" do
16
+ @simple_dec.text_not_decorated("test").should eql "test"
17
+ end
18
+
19
+ it "decorates a method with a single decorator" do
20
+ @simple_dec.text_single_decorated("test").should eql "<b>test</b>"
21
+ end
22
+
23
+ end
24
+
25
+ describe ArgumentsDecorator do
26
+
27
+ before :each do
28
+ @args_dec = ArgumentsDecorator.new
29
+ end
30
+
31
+ it "should receive single decorator argument" do
32
+ @args_dec.number(3).should eql 9
33
+ end
34
+
35
+ it "should receive multiple decorator arguments" do
36
+ @args_dec.number2(1).should eql 7
37
+ end
38
+
39
+ end
40
+
41
+ end
@@ -0,0 +1,59 @@
1
+ require 'rubyrator'
2
+
3
+ class SimpleDecorator
4
+ extend Rubyrator
5
+
6
+ def bold(dec_args, orig, *args, &block)
7
+ "<b>" + orig.call(*args, &block) + "</b>"
8
+ end
9
+
10
+ def italic(dec_args, orig, *args, &block)
11
+ "<i>" + orig.call(*args, &block) + "</i>"
12
+ end
13
+
14
+ decorate :bold
15
+ decorate :italic
16
+ def text_double_decorated(text)
17
+ text
18
+ end
19
+
20
+ def text_not_decorated(text)
21
+ text
22
+ end
23
+
24
+ decorate :bold
25
+ def text_single_decorated(text)
26
+ text
27
+ end
28
+
29
+ end
30
+
31
+ class ArgumentsDecorator
32
+ extend Rubyrator
33
+
34
+ def single_arg_decorator(dec_args, orig, *args, &block)
35
+ retry_num = dec_args[0]
36
+ result = 0
37
+
38
+ retry_num.times do
39
+ result += orig.call(*args, &block)
40
+ end
41
+
42
+ return result
43
+ end
44
+
45
+ def multiple_arg_decorator(dec_args, orig, *args, &block)
46
+ orig.call(*args, &block) + dec_args[0] + dec_args[1] + dec_args[2]
47
+ end
48
+
49
+ decorate :single_arg_decorator, 3
50
+ def number(number)
51
+ number
52
+ end
53
+
54
+ decorate :multiple_arg_decorator, 1, 2, 3
55
+ def number2(number)
56
+ number
57
+ end
58
+
59
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rubyrator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.1
5
+ platform: ruby
6
+ authors:
7
+ - Artur Termenji
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2013-04-28 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rake
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - '>='
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :development
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Python like method decorators for Ruby
42
+ email:
43
+ - atermenji@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - .gitignore
49
+ - Gemfile
50
+ - LICENSE
51
+ - README.md
52
+ - Rakefile
53
+ - lib/rubyrator.rb
54
+ - lib/rubyrator/rubyrator.rb
55
+ - lib/rubyrator/version.rb
56
+ - rubyrator.gemspec
57
+ - spec/rubyrator/rubyrator_spec.rb
58
+ - spec/spec_helper.rb
59
+ homepage: http://github.com/atermenji/rubyrator
60
+ licenses:
61
+ - MIT
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ requirements:
69
+ - - '>='
70
+ - !ruby/object:Gem::Version
71
+ version: '0'
72
+ required_rubygems_version: !ruby/object:Gem::Requirement
73
+ requirements:
74
+ - - '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 2.0.3
80
+ signing_key:
81
+ specification_version: 4
82
+ summary: Python like method decorators for Ruby
83
+ test_files:
84
+ - spec/rubyrator/rubyrator_spec.rb
85
+ - spec/spec_helper.rb