wrapup 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rspec +1 -0
- data/Gemfile +4 -0
- data/LICENSE +22 -0
- data/README.md +29 -0
- data/Rakefile +2 -0
- data/lib/wrapup.rb +5 -0
- data/lib/wrapup/version.rb +3 -0
- data/lib/wrapup/wrap.rb +16 -0
- data/spec/wrapup/wrap_spec.rb +48 -0
- data/wrapup.gemspec +19 -0
- metadata +68 -0
data/.gitignore
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--colour
|
data/Gemfile
ADDED
data/LICENSE
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Jon Rowe
|
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,29 @@
|
|
1
|
+
# WrapUp
|
2
|
+
|
3
|
+
Simple wrapper gem. Found myself writing this in too many projects.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'wrapup'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install wrapup
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
TODO: Write usage instructions here
|
22
|
+
|
23
|
+
## Contributing
|
24
|
+
|
25
|
+
1. Fork it
|
26
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
27
|
+
3. Commit your changes (`git commit -am 'Added some feature'`)
|
28
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
29
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
data/lib/wrapup.rb
ADDED
data/lib/wrapup/wrap.rb
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
module WrapUp
|
2
|
+
class Wrap
|
3
|
+
include Enumerable
|
4
|
+
|
5
|
+
def initialize(collection,wrapper_constant)
|
6
|
+
@collection = collection
|
7
|
+
@wrapper = wrapper_constant
|
8
|
+
end
|
9
|
+
|
10
|
+
def each(&block)
|
11
|
+
@collection.each do |item|
|
12
|
+
block.call @wrapper.new item
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'wrapup/wrap'
|
2
|
+
module WrapUp
|
3
|
+
describe Wrap do
|
4
|
+
describe "#initialize" do
|
5
|
+
it "takes a collection and a constant in which to wrap the collection" do
|
6
|
+
described_class.new [], double
|
7
|
+
end
|
8
|
+
end
|
9
|
+
|
10
|
+
describe "enumerability" do
|
11
|
+
it " has the standard enumerability module in its ancestors" do
|
12
|
+
described_class.ancestors.should include Enumerable
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#each" do
|
17
|
+
[:item_1,:item_2,:wrap_1,:wrap_2,:constant].each { |name| let(name) { double name } }
|
18
|
+
let(:collection) { [item_1,item_2] }
|
19
|
+
let(:output) { [] }
|
20
|
+
|
21
|
+
before do
|
22
|
+
constant.stub(:new).and_return do |item|
|
23
|
+
case item
|
24
|
+
when item_1 then wrap_1
|
25
|
+
when item_2 then wrap_2
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
let(:wrap) { described_class.new collection, constant }
|
31
|
+
subject { wrap.each { |i| output << i } }
|
32
|
+
|
33
|
+
it "iterates over the collection" do
|
34
|
+
collection.should_receive(:each)
|
35
|
+
subject
|
36
|
+
end
|
37
|
+
it "wraps the items in constant" do
|
38
|
+
constant.should_receive(:new).with(item_1).and_return(wrap_1)
|
39
|
+
constant.should_receive(:new).with(item_2).and_return(wrap_2)
|
40
|
+
subject
|
41
|
+
end
|
42
|
+
it "yields wrapped items to block" do
|
43
|
+
subject
|
44
|
+
output.should == [wrap_1,wrap_2]
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
data/wrapup.gemspec
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
require File.expand_path('../lib/wrapup/version', __FILE__)
|
3
|
+
|
4
|
+
Gem::Specification.new do |gem|
|
5
|
+
gem.authors = ["Jon Rowe"]
|
6
|
+
gem.email = ["hello@jonrowe.co.uk"]
|
7
|
+
gem.description = %q{WrapUp, a simple wrapper gem for collections}
|
8
|
+
gem.summary = %q{WrapUp, a simple wrapper gem for collections}
|
9
|
+
gem.homepage = "https://github.com/JonRowe/wrapup"
|
10
|
+
|
11
|
+
gem.files = `git ls-files`.split($\)
|
12
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
13
|
+
gem.test_files = gem.files.grep(%r{^(spec|features)/})
|
14
|
+
gem.name = "wrapup"
|
15
|
+
gem.require_paths = ["lib"]
|
16
|
+
gem.version = WrapUp::VERSION
|
17
|
+
|
18
|
+
gem.add_development_dependency 'rspec'
|
19
|
+
end
|
metadata
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: wrapup
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Jon Rowe
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-07-15 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: &70242471053300 !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: *70242471053300
|
25
|
+
description: WrapUp, a simple wrapper gem for collections
|
26
|
+
email:
|
27
|
+
- hello@jonrowe.co.uk
|
28
|
+
executables: []
|
29
|
+
extensions: []
|
30
|
+
extra_rdoc_files: []
|
31
|
+
files:
|
32
|
+
- .gitignore
|
33
|
+
- .rspec
|
34
|
+
- Gemfile
|
35
|
+
- LICENSE
|
36
|
+
- README.md
|
37
|
+
- Rakefile
|
38
|
+
- lib/wrapup.rb
|
39
|
+
- lib/wrapup/version.rb
|
40
|
+
- lib/wrapup/wrap.rb
|
41
|
+
- spec/wrapup/wrap_spec.rb
|
42
|
+
- wrapup.gemspec
|
43
|
+
homepage: https://github.com/JonRowe/wrapup
|
44
|
+
licenses: []
|
45
|
+
post_install_message:
|
46
|
+
rdoc_options: []
|
47
|
+
require_paths:
|
48
|
+
- lib
|
49
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
50
|
+
none: false
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
56
|
+
none: false
|
57
|
+
requirements:
|
58
|
+
- - ! '>='
|
59
|
+
- !ruby/object:Gem::Version
|
60
|
+
version: '0'
|
61
|
+
requirements: []
|
62
|
+
rubyforge_project:
|
63
|
+
rubygems_version: 1.8.10
|
64
|
+
signing_key:
|
65
|
+
specification_version: 3
|
66
|
+
summary: WrapUp, a simple wrapper gem for collections
|
67
|
+
test_files:
|
68
|
+
- spec/wrapup/wrap_spec.rb
|