burgundy 0.0.1 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rspec +0 -1
- data/.travis.yml +1 -0
- data/README.md +2 -0
- data/burgundy.gemspec +14 -13
- data/lib/burgundy.rb +5 -5
- data/lib/burgundy/collection.rb +10 -2
- data/lib/burgundy/item.rb +6 -1
- data/lib/burgundy/version.rb +1 -1
- data/spec/burgundy_spec.rb +37 -22
- data/spec/spec_helper.rb +5 -6
- metadata +33 -18
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 4295b2c824c87c0092cbb3e80951774e4569e2a5
|
4
|
+
data.tar.gz: b76378908e014558208eb0d0bfd1f38341718f73
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cc96e010f0b3a4f3537a8f026b9040b39d200c5a9ee42d2a32344b62ab72fc7d3216872ed08781dcf4eae9f701d9c83c286efbcd10bcfaf3ece8233c46884c9f
|
7
|
+
data.tar.gz: 7a764ee903dfbdbb6c292e481f70ea3a7c4746757172df42ee8988f9164376f7dcf84111c141e9065b860bf836867a4e959ed6258cc967fa3c3513702cce261c
|
data/.rspec
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -56,6 +56,8 @@ class WorkshopsController < ApplicationController
|
|
56
56
|
end
|
57
57
|
```
|
58
58
|
|
59
|
+
or just call `WorkshopPresenter.wrap(Workshop.sorted_by_name)`. Both ways return a `Burgundy::Collection` instance.
|
60
|
+
|
59
61
|
The query will be performed only when needed, usually on the view. The collection is an enumerable object and can be passed directly to the `render` method. Each item will be wrapped by the provided class.
|
60
62
|
|
61
63
|
```erb
|
data/burgundy.gemspec
CHANGED
@@ -1,23 +1,24 @@
|
|
1
|
-
require
|
1
|
+
require './lib/burgundy/version'
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
|
-
spec.name =
|
4
|
+
spec.name = 'burgundy'
|
5
5
|
spec.version = Burgundy::VERSION
|
6
|
-
spec.authors = [
|
7
|
-
spec.email = [
|
8
|
-
spec.description =
|
6
|
+
spec.authors = ['Nando Vieira']
|
7
|
+
spec.email = ['fnando.vieira@gmail.com']
|
8
|
+
spec.description = 'A simple wrapper for objects (think of Burgundy as a decorator/presenter) in less than 100 lines.'
|
9
9
|
spec.summary = spec.description
|
10
|
-
spec.homepage =
|
11
|
-
spec.license =
|
10
|
+
spec.homepage = 'http://github.com/fnando/burgundy'
|
11
|
+
spec.license = 'MIT'
|
12
12
|
|
13
13
|
spec.files = `git ls-files`.split($/)
|
14
14
|
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
15
15
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
16
|
-
spec.require_paths = [
|
16
|
+
spec.require_paths = ['lib']
|
17
17
|
|
18
|
-
spec.add_development_dependency
|
19
|
-
spec.add_development_dependency
|
20
|
-
spec.add_development_dependency
|
21
|
-
spec.add_development_dependency
|
22
|
-
spec.add_development_dependency
|
18
|
+
spec.add_development_dependency 'bundler', '~> 1.3'
|
19
|
+
spec.add_development_dependency 'rake'
|
20
|
+
spec.add_development_dependency 'rspec'
|
21
|
+
spec.add_development_dependency 'rails'
|
22
|
+
spec.add_development_dependency 'rspec-rails'
|
23
|
+
spec.add_development_dependency 'pry-meta'
|
23
24
|
end
|
data/lib/burgundy.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
1
|
+
require 'delegate'
|
2
|
+
require 'burgundy/version'
|
3
|
+
require 'burgundy/item'
|
4
|
+
require 'burgundy/collection'
|
5
|
+
require 'burgundy/rails' if defined?(Rails)
|
data/lib/burgundy/collection.rb
CHANGED
@@ -2,17 +2,25 @@ module Burgundy
|
|
2
2
|
class Collection
|
3
3
|
include Enumerable
|
4
4
|
|
5
|
-
def initialize(items, wrapping_class)
|
5
|
+
def initialize(items, wrapping_class = nil)
|
6
6
|
@items = items
|
7
7
|
@wrapping_class = wrapping_class
|
8
8
|
end
|
9
9
|
|
10
|
+
def empty?
|
11
|
+
!any?
|
12
|
+
end
|
13
|
+
|
10
14
|
def each(&block)
|
11
15
|
to_ary.each(&block)
|
12
16
|
end
|
13
17
|
|
14
18
|
def to_ary
|
15
|
-
@cache ||= @wrapping_class
|
19
|
+
@cache ||= if @wrapping_class
|
20
|
+
@items.map {|item| @wrapping_class.new(item) }
|
21
|
+
else
|
22
|
+
@items.to_a
|
23
|
+
end
|
16
24
|
end
|
17
25
|
alias_method :to_a, :to_ary
|
18
26
|
end
|
data/lib/burgundy/item.rb
CHANGED
@@ -2,8 +2,13 @@ module Burgundy
|
|
2
2
|
class Item < SimpleDelegator
|
3
3
|
attr_reader :item
|
4
4
|
|
5
|
+
def self.wrap(collection)
|
6
|
+
Collection.new(collection, self)
|
7
|
+
end
|
8
|
+
|
5
9
|
def self.map(collection)
|
6
|
-
|
10
|
+
warn 'Burgundy::Item.map is deprecated; use Burgundy::Item.wrap instead.'
|
11
|
+
wrap(collection)
|
7
12
|
end
|
8
13
|
|
9
14
|
def initialize(item)
|
data/lib/burgundy/version.rb
CHANGED
data/spec/burgundy_spec.rb
CHANGED
@@ -1,45 +1,60 @@
|
|
1
|
-
require
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
3
|
describe Burgundy do
|
4
4
|
let(:wrapper) { Class.new(Burgundy::Item) }
|
5
5
|
|
6
|
-
it
|
7
|
-
item = wrapper.new(
|
8
|
-
expect(item.upcase).to eql(
|
6
|
+
it 'delegates everything' do
|
7
|
+
item = wrapper.new('hello')
|
8
|
+
expect(item.upcase).to eql('HELLO')
|
9
9
|
end
|
10
10
|
|
11
|
-
it
|
12
|
-
items = wrapper.
|
11
|
+
it 'wraps items' do
|
12
|
+
items = wrapper.wrap([1,2,3])
|
13
13
|
|
14
|
+
expect(items.class).to eql(Burgundy::Collection)
|
14
15
|
expect(items.first).to be_a(wrapper)
|
15
16
|
expect(items.first.to_i).to eql(1)
|
16
17
|
end
|
17
18
|
|
18
|
-
it
|
19
|
+
it 'deprecates Burgundy::Item.map' do
|
20
|
+
message = 'Burgundy::Item.map is deprecated; use Burgundy::Item.wrap instead.'
|
21
|
+
expect(wrapper).to receive(:warn).with(message)
|
22
|
+
wrapper.map([1,2,3])
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'wraps items in collection' do
|
19
26
|
collection = Burgundy::Collection.new([1,2,3], wrapper)
|
20
27
|
expect(collection.first).to eql(1)
|
21
28
|
end
|
22
29
|
|
23
|
-
it
|
30
|
+
it 'includes Enumerable' do
|
24
31
|
expect(Burgundy::Collection).to include(Enumerable)
|
25
32
|
end
|
26
33
|
|
27
|
-
it
|
28
|
-
|
34
|
+
it 'implements #empty?' do
|
35
|
+
collection = Burgundy::Collection.new([1,2,3])
|
36
|
+
expect(collection).not_to be_empty
|
37
|
+
|
38
|
+
collection = Burgundy::Collection.new([])
|
39
|
+
expect(collection).to be_empty
|
40
|
+
end
|
41
|
+
|
42
|
+
it 'responds to the routes method' do
|
43
|
+
item = wrapper.new('hello')
|
29
44
|
|
30
45
|
expect(item.respond_to?(:routes, true)).to be
|
31
46
|
expect(item.respond_to?(:r, true)).to be
|
32
47
|
end
|
33
48
|
|
34
|
-
it
|
35
|
-
item = wrapper.new(
|
49
|
+
it 'responds to the helpers method' do
|
50
|
+
item = wrapper.new('hello')
|
36
51
|
|
37
52
|
expect(item.respond_to?(:helpers, true)).to be
|
38
53
|
expect(item.respond_to?(:h, true)).to be
|
39
54
|
end
|
40
55
|
|
41
|
-
it
|
42
|
-
item = wrapper.new(
|
56
|
+
it 'responds to the I18n methods' do
|
57
|
+
item = wrapper.new('hello')
|
43
58
|
|
44
59
|
expect(item.respond_to?(:translate, true)).to be
|
45
60
|
expect(item.respond_to?(:t, true)).to be
|
@@ -47,25 +62,25 @@ describe Burgundy do
|
|
47
62
|
expect(item.respond_to?(:l, true)).to be
|
48
63
|
end
|
49
64
|
|
50
|
-
it
|
65
|
+
it 'returns route using action mailer options' do
|
51
66
|
wrapper = Class.new(Burgundy::Item) do
|
52
67
|
def profile_url; routes.profile_url(username) end
|
53
68
|
end
|
54
69
|
|
55
|
-
Rails.configuration.action_mailer.default_url_options = {host:
|
56
|
-
item = wrapper.new OpenStruct.new(username:
|
70
|
+
Rails.configuration.action_mailer.default_url_options = {host: 'example.org'}
|
71
|
+
item = wrapper.new OpenStruct.new(username: 'johndoe')
|
57
72
|
|
58
|
-
expect(item.profile_url).to eql(
|
73
|
+
expect(item.profile_url).to eql('http://example.org/johndoe')
|
59
74
|
end
|
60
75
|
|
61
|
-
it
|
76
|
+
it 'returns route using action controller options' do
|
62
77
|
wrapper = Class.new(Burgundy::Item) do
|
63
78
|
def profile_url; routes.profile_url(username) end
|
64
79
|
end
|
65
80
|
|
66
|
-
Rails.application.routes.default_url_options = {host:
|
67
|
-
item = wrapper.new OpenStruct.new(username:
|
81
|
+
Rails.application.routes.default_url_options = {host: 'example.org'}
|
82
|
+
item = wrapper.new OpenStruct.new(username: 'johndoe')
|
68
83
|
|
69
|
-
expect(item.profile_url).to eql(
|
84
|
+
expect(item.profile_url).to eql('http://example.org/johndoe')
|
70
85
|
end
|
71
86
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,12 @@
|
|
1
|
-
require
|
1
|
+
require 'bundler/setup'
|
2
2
|
Bundler.setup
|
3
3
|
|
4
|
-
ENV[
|
4
|
+
ENV['RAILS_ENV'] = 'test'
|
5
5
|
|
6
|
-
require File.expand_path(
|
7
|
-
require
|
8
|
-
require "rspec/autorun"
|
6
|
+
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
7
|
+
require 'rspec/rails'
|
9
8
|
|
10
|
-
require
|
9
|
+
require 'burgundy'
|
11
10
|
I18n.locale = :en
|
12
11
|
|
13
12
|
RSpec.configure do |config|
|
metadata
CHANGED
@@ -1,83 +1,97 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: burgundy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-07-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
15
15
|
requirement: !ruby/object:Gem::Requirement
|
16
16
|
requirements:
|
17
|
-
- - ~>
|
17
|
+
- - "~>"
|
18
18
|
- !ruby/object:Gem::Version
|
19
19
|
version: '1.3'
|
20
20
|
type: :development
|
21
21
|
prerelease: false
|
22
22
|
version_requirements: !ruby/object:Gem::Requirement
|
23
23
|
requirements:
|
24
|
-
- - ~>
|
24
|
+
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1.3'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
28
|
name: rake
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- -
|
31
|
+
- - ">="
|
32
32
|
- !ruby/object:Gem::Version
|
33
33
|
version: '0'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- -
|
38
|
+
- - ">="
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rspec
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
|
-
- -
|
45
|
+
- - ">="
|
46
46
|
- !ruby/object:Gem::Version
|
47
47
|
version: '0'
|
48
48
|
type: :development
|
49
49
|
prerelease: false
|
50
50
|
version_requirements: !ruby/object:Gem::Requirement
|
51
51
|
requirements:
|
52
|
-
- -
|
52
|
+
- - ">="
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
56
|
name: rails
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- -
|
59
|
+
- - ">="
|
60
60
|
- !ruby/object:Gem::Version
|
61
61
|
version: '0'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- -
|
66
|
+
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rspec-rails
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
|
-
- -
|
73
|
+
- - ">="
|
74
74
|
- !ruby/object:Gem::Version
|
75
75
|
version: '0'
|
76
76
|
type: :development
|
77
77
|
prerelease: false
|
78
78
|
version_requirements: !ruby/object:Gem::Requirement
|
79
79
|
requirements:
|
80
|
-
- -
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: pry-meta
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ">="
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
83
97
|
description: A simple wrapper for objects (think of Burgundy as a decorator/presenter)
|
@@ -88,9 +102,9 @@ executables: []
|
|
88
102
|
extensions: []
|
89
103
|
extra_rdoc_files: []
|
90
104
|
files:
|
91
|
-
- .gitignore
|
92
|
-
- .rspec
|
93
|
-
- .travis.yml
|
105
|
+
- ".gitignore"
|
106
|
+
- ".rspec"
|
107
|
+
- ".travis.yml"
|
94
108
|
- Gemfile
|
95
109
|
- LICENSE.txt
|
96
110
|
- README.md
|
@@ -153,17 +167,17 @@ require_paths:
|
|
153
167
|
- lib
|
154
168
|
required_ruby_version: !ruby/object:Gem::Requirement
|
155
169
|
requirements:
|
156
|
-
- -
|
170
|
+
- - ">="
|
157
171
|
- !ruby/object:Gem::Version
|
158
172
|
version: '0'
|
159
173
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
160
174
|
requirements:
|
161
|
-
- -
|
175
|
+
- - ">="
|
162
176
|
- !ruby/object:Gem::Version
|
163
177
|
version: '0'
|
164
178
|
requirements: []
|
165
179
|
rubyforge_project:
|
166
|
-
rubygems_version: 2.
|
180
|
+
rubygems_version: 2.2.2
|
167
181
|
signing_key:
|
168
182
|
specification_version: 4
|
169
183
|
summary: A simple wrapper for objects (think of Burgundy as a decorator/presenter)
|
@@ -211,3 +225,4 @@ test_files:
|
|
211
225
|
- spec/dummy/public/500.html
|
212
226
|
- spec/dummy/public/favicon.ico
|
213
227
|
- spec/spec_helper.rb
|
228
|
+
has_rdoc:
|