wallpapering 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.ruby-version +1 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +49 -0
- data/Rakefile +1 -0
- data/lib/core_ext/array.rb +5 -0
- data/lib/wallpapering.rb +9 -0
- data/lib/wallpapering/decorator.rb +7 -0
- data/lib/wallpapering/version.rb +3 -0
- data/spec/lib/core_ext/array_spec.rb +15 -0
- data/spec/lib/wallpapering/decorator_spec.rb +37 -0
- data/wallpapering.gemspec +21 -0
- metadata +76 -0
data/.gitignore
ADDED
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
1.9.3-p362
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Matt House
|
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,49 @@
|
|
1
|
+
# Wallpapering
|
2
|
+
|
3
|
+
Wallpapering is a really simple implementation of the decorator pattern for use in Rails applications
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'wallpapering'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install wallpapering
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Basic Decorators are classes that inherit from `Wallpapering::Decorator`. They accept an object to decorate as the single argument for the initializer. They maintain the interface of the decorated object and are entirely transparent. You can add (and remove) methods if you wish, you can override methods - super will do what you expect.
|
22
|
+
|
23
|
+
to create a Decorator just do the following:
|
24
|
+
|
25
|
+
class WithSugar < Wallpapering::Decorator
|
26
|
+
def calories
|
27
|
+
super + 50
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
coffee_with_sugar = WithSugar.new(Coffee.new))
|
32
|
+
|
33
|
+
You can also easily decorate an array of objects
|
34
|
+
|
35
|
+
@posts.map_as(PostPresenter) # Returns an array of Presented Posts!
|
36
|
+
|
37
|
+
## Contributing
|
38
|
+
|
39
|
+
Basic contribution guidelines are as follows. I'm always amenable to patches and pull requests however please bear in mind that wallpapering is designed to be pretty much the simplest thing that can work. Also no patches will be accepted without accompanying tests. Thanks :)
|
40
|
+
|
41
|
+
1. Fork it
|
42
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
43
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
44
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
45
|
+
5. Create new Pull Request
|
46
|
+
|
47
|
+
## Thanks
|
48
|
+
|
49
|
+
Cheers [Russell](http://rsslldnphy.com/) for `map_as`
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/wallpapering.rb
ADDED
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative '../../../lib/core_ext/array'
|
2
|
+
|
3
|
+
describe Array do
|
4
|
+
class Foo
|
5
|
+
def initialize(n); end
|
6
|
+
end
|
7
|
+
|
8
|
+
subject{ [1,2,3].map_as(Foo) }
|
9
|
+
|
10
|
+
it 'maps the new class onto each element of the array' do
|
11
|
+
subject.each do |elem|
|
12
|
+
expect(elem.class).to be(Foo)
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'wallpapering'
|
2
|
+
|
3
|
+
module Wallpapering
|
4
|
+
describe "inheriting from decorator" do
|
5
|
+
class FooDecorator < Decorator
|
6
|
+
def normal_method
|
7
|
+
end
|
8
|
+
|
9
|
+
def normal_method_that_calls_super
|
10
|
+
super
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
let(:decorated){ Object.new }
|
15
|
+
|
16
|
+
subject{ FooDecorator.new(decorated) }
|
17
|
+
|
18
|
+
it "delegates non existent methods to the decorated object" do
|
19
|
+
decorated.should_receive(:foobar)
|
20
|
+
subject.foobar
|
21
|
+
end
|
22
|
+
|
23
|
+
it "intercepts decorated methods" do
|
24
|
+
decorated.should_not_receive(:normal_method)
|
25
|
+
subject.normal_method
|
26
|
+
end
|
27
|
+
|
28
|
+
it "passes super to the decorated object" do
|
29
|
+
decorated.should_receive(:normal_method_that_calls_super)
|
30
|
+
subject.normal_method_that_calls_super
|
31
|
+
end
|
32
|
+
|
33
|
+
it "masquerades as the class of the decorated object" do
|
34
|
+
expect(subject.class).to be(Object)
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'wallpapering/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "wallpapering"
|
8
|
+
gem.version = Wallpapering::VERSION
|
9
|
+
gem.authors = ["Matt House"]
|
10
|
+
gem.email = ["matt@eightbitraptor.com"]
|
11
|
+
gem.description = %q{Wallpapering is a simple decorator pattern implementation}
|
12
|
+
gem.summary = %q{Implements the decorator pattern in Ruby, as simply as possible}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
|
20
|
+
gem.add_development_dependency "rspec"
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wallpapering
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Matt House
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2013-02-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ! '>='
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '0'
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
version_requirements: !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ! '>='
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
version: '0'
|
30
|
+
description: Wallpapering is a simple decorator pattern implementation
|
31
|
+
email:
|
32
|
+
- matt@eightbitraptor.com
|
33
|
+
executables: []
|
34
|
+
extensions: []
|
35
|
+
extra_rdoc_files: []
|
36
|
+
files:
|
37
|
+
- .gitignore
|
38
|
+
- .ruby-version
|
39
|
+
- Gemfile
|
40
|
+
- LICENSE.txt
|
41
|
+
- README.md
|
42
|
+
- Rakefile
|
43
|
+
- lib/core_ext/array.rb
|
44
|
+
- lib/wallpapering.rb
|
45
|
+
- lib/wallpapering/decorator.rb
|
46
|
+
- lib/wallpapering/version.rb
|
47
|
+
- spec/lib/core_ext/array_spec.rb
|
48
|
+
- spec/lib/wallpapering/decorator_spec.rb
|
49
|
+
- wallpapering.gemspec
|
50
|
+
homepage: ''
|
51
|
+
licenses: []
|
52
|
+
post_install_message:
|
53
|
+
rdoc_options: []
|
54
|
+
require_paths:
|
55
|
+
- lib
|
56
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ! '>='
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: '0'
|
68
|
+
requirements: []
|
69
|
+
rubyforge_project:
|
70
|
+
rubygems_version: 1.8.24
|
71
|
+
signing_key:
|
72
|
+
specification_version: 3
|
73
|
+
summary: Implements the decorator pattern in Ruby, as simply as possible
|
74
|
+
test_files:
|
75
|
+
- spec/lib/core_ext/array_spec.rb
|
76
|
+
- spec/lib/wallpapering/decorator_spec.rb
|