armin-joellenbeck-decorator 0.0.2

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 ADDED
@@ -0,0 +1,54 @@
1
+ =Decorator Pattern for Ruby
2
+
3
+ This library supports the Decorator Pattern for Ruby.
4
+
5
+ =Installation
6
+
7
+ Install the *decorator* gem itself by the following command:
8
+
9
+ $ gem install armin-joellenbeck-decorator
10
+
11
+ =Usage
12
+
13
+ ...
14
+
15
+ =Support
16
+
17
+ The project home is at
18
+ GitHub[http://github.com/armin-joellenbeck/decorator/tree/master]:
19
+ http://github.com/armin-joellenbeck/decorator/tree/master
20
+
21
+ Feel free to send:
22
+ * bug reports
23
+ * support requests
24
+ * feature requests
25
+ * patches
26
+
27
+ =Copyright
28
+
29
+ Copyright (c) 2008 by Armin Jöllenbeck
30
+ <armin@joellenbeck.net[mailto:armin@joellenbeck.net]>
31
+
32
+ All rights reserved.
33
+
34
+ Redistribution and use in source and binary forms, with or without
35
+ modification, are permitted provided that the following conditions
36
+ are met:
37
+ 1. Redistributions of source code must retain the above copyright
38
+ notice, this list of conditions and the following disclaimer.
39
+ 2. Redistributions in binary form must reproduce the above copyright
40
+ notice, this list of conditions and the following disclaimer in the
41
+ documentation and/or other materials provided with the distribution.
42
+ 3. The names of the contributors may not be used to endorse or promote products
43
+ derived from this software without specific prior written permission.
44
+
45
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
46
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO,
47
+ THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
48
+ ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
49
+ LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
50
+ CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
51
+ GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
52
+ HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
53
+ LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
54
+ OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,32 @@
1
+ require 'rake/gempackagetask'
2
+ require 'rake/rdoctask'
3
+ require 'spec/rake/spectask'
4
+
5
+ task :default => 'spec'
6
+
7
+ task :all => [:clobber, :spec, :doc, :package]
8
+
9
+ Spec::Rake::SpecTask.new do |t|
10
+ t.libs << 'spec' << 'examples' << 'lib'
11
+ t.spec_opts << '--diff' << 'unified'
12
+ t.spec_opts << '--format' << 'progress'
13
+ end
14
+
15
+ Rake::RDocTask.new(:doc) do |t|
16
+ t.rdoc_dir = 'doc'
17
+ t.rdoc_files.include('README', 'lib/**/*.rb')
18
+ t.options = [
19
+ '--all',
20
+ '--charset', 'utf8',
21
+ '--inline-source',
22
+ '--main', 'README',
23
+ '--title', 'Decorator Pattern for Ruby'
24
+ ]
25
+ end
26
+
27
+ Rake::GemPackageTask.new(eval(File.read('decorator.gemspec'))) do |pkg|
28
+ end
29
+
30
+ task :auto do
31
+ sh 'RUBYLIB=spec:examples:lib:$RUBYLIB autospec'
32
+ end
@@ -0,0 +1,26 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'decorator'
3
+ s.version = '0.0.2'
4
+ s.summary = 'Decorator Pattern for Ruby.'
5
+ s.author = 'Armin Joellenbeck'
6
+ s.email = 'armin@joellenbeck.net'
7
+ s.homepage = 'http://github.com/armin-joellenbeck/decorator/tree/master'
8
+ s.description = <<-EOF
9
+ EOF
10
+ s.files = Dir.glob([
11
+ 'README',
12
+ 'Rakefile',
13
+ '*.gemspec',
14
+ 'examples/**/*',
15
+ 'lib/**/*',
16
+ 'spec/**/*'
17
+ ])
18
+ s.has_rdoc = true
19
+ s.extra_rdoc_files << 'README'
20
+ s.rdoc_options = [
21
+ '--all',
22
+ '--charset', 'utf8',
23
+ '--main', 'README',
24
+ '--title', 'Decorator Pattern for Ruby'
25
+ ]
26
+ end
@@ -0,0 +1,31 @@
1
+ class Decorator
2
+ alias_method :__class__, :class
3
+
4
+ instance_methods.each do |method|
5
+ undef_method(method) unless /__.+__/ === method
6
+ end
7
+
8
+ # Initialize with the object which should be decorated.
9
+ def initialize(object)
10
+ @object = object
11
+ end
12
+
13
+ # The standard implementation delegates to the decorated object.
14
+ def method_missing(method, *args)
15
+ @object.send(method, *args)
16
+ end
17
+ end
18
+
19
+
20
+ class Class
21
+ # Declare the using of a decorator class within a class defination.
22
+ # Each instance of that class is decorated by an individual instance of the
23
+ # decorator class. A decorator class should inherit from Decorator.
24
+ def decorate(decorator_class)
25
+ old_new = self.method(:new)
26
+ (class << self; self; end).send(:define_method, :new) do |*args|
27
+ object = old_new.call(*args)
28
+ decorator_class.new(object)
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,28 @@
1
+ require 'spec_helper'
2
+
3
+ require 'decorator'
4
+
5
+
6
+ describe 'A decorator' do
7
+ before do
8
+ @object = Object.new
9
+ @decorator = Decorator.new(@object)
10
+ end
11
+
12
+ it 'should delegate to the decorated object' do
13
+ mock(@object).foo
14
+ @decorator.foo
15
+ end
16
+ end
17
+
18
+
19
+ describe 'Decorating a class' do
20
+ it 'should delegate to each decorated object' do
21
+ decorator_class = Class.new(Decorator)
22
+ decorator_class.send(:define_method, :foo) {:bar}
23
+ object_class = Class.new
24
+ object_class.decorate(decorator_class)
25
+ object = object_class.new
26
+ object.foo.should == :bar
27
+ end
28
+ end
@@ -0,0 +1,3 @@
1
+ --color
2
+ --diff unified
3
+ --format specdoc
@@ -0,0 +1,8 @@
1
+ require 'rubygems'
2
+
3
+ require 'spec'
4
+ require 'rr'
5
+
6
+ Spec::Runner.configure do |config|
7
+ config.mock_with :rr
8
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: armin-joellenbeck-decorator
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - Armin Joellenbeck
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-10-27 00:00:00 -07:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: ""
17
+ email: armin@joellenbeck.net
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README
24
+ files:
25
+ - README
26
+ - Rakefile
27
+ - decorator.gemspec
28
+ - lib/decorator.rb
29
+ - spec/spec_helper.rb
30
+ - spec/decorator_spec.rb
31
+ - spec/spec.opts
32
+ has_rdoc: true
33
+ homepage: http://github.com/armin-joellenbeck/decorator/tree/master
34
+ post_install_message:
35
+ rdoc_options:
36
+ - --all
37
+ - --charset
38
+ - utf8
39
+ - --main
40
+ - README
41
+ - --title
42
+ - Decorator Pattern for Ruby
43
+ require_paths:
44
+ - lib
45
+ required_ruby_version: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - ">="
48
+ - !ruby/object:Gem::Version
49
+ version: "0"
50
+ version:
51
+ required_rubygems_version: !ruby/object:Gem::Requirement
52
+ requirements:
53
+ - - ">="
54
+ - !ruby/object:Gem::Version
55
+ version: "0"
56
+ version:
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.2.0
61
+ signing_key:
62
+ specification_version: 2
63
+ summary: Decorator Pattern for Ruby.
64
+ test_files: []
65
+