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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b54a032f0c4d79e05ae0dd1b1fbb5155b2025b9f
4
- data.tar.gz: ce63a137e7d1e7838e09360fbf2e7fc246b8cae4
3
+ metadata.gz: 4295b2c824c87c0092cbb3e80951774e4569e2a5
4
+ data.tar.gz: b76378908e014558208eb0d0bfd1f38341718f73
5
5
  SHA512:
6
- metadata.gz: e9a475b0e0e410eb4ab66762849166fbb611e7cac091523ef15e9356c35059577c5efb9d8cf3f251db0791b90f3a2371e99e4373e509d5152f4443cff8edaeb7
7
- data.tar.gz: 5329e76c0ff9b44bd28233bb536957aa2edf9f1f7772a957663f4bb2591b835b49914672f6bce55386e41c6475464f5cf64e14a40bd2fa6b78883b2c6f173995
6
+ metadata.gz: cc96e010f0b3a4f3537a8f026b9040b39d200c5a9ee42d2a32344b62ab72fc7d3216872ed08781dcf4eae9f701d9c83c286efbcd10bcfaf3ece8233c46884c9f
7
+ data.tar.gz: 7a764ee903dfbdbb6c292e481f70ea3a7c4746757172df42ee8988f9164376f7dcf84111c141e9065b860bf836867a4e959ed6258cc967fa3c3513702cce261c
data/.rspec CHANGED
@@ -1,2 +1 @@
1
- --format documentation
2
1
  --color
@@ -1,3 +1,4 @@
1
1
  language: ruby
2
2
  rvm:
3
3
  - 2.0.0
4
+ - 2.1.0
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
@@ -1,23 +1,24 @@
1
- require "./lib/burgundy/version"
1
+ require './lib/burgundy/version'
2
2
 
3
3
  Gem::Specification.new do |spec|
4
- spec.name = "burgundy"
4
+ spec.name = 'burgundy'
5
5
  spec.version = Burgundy::VERSION
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."
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 = "http://github.com/fnando/burgundy"
11
- spec.license = "MIT"
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 = ["lib"]
16
+ spec.require_paths = ['lib']
17
17
 
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"
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
@@ -1,5 +1,5 @@
1
- require "delegate"
2
- require "burgundy/version"
3
- require "burgundy/item"
4
- require "burgundy/collection"
5
- require "burgundy/rails" if defined?(Rails)
1
+ require 'delegate'
2
+ require 'burgundy/version'
3
+ require 'burgundy/item'
4
+ require 'burgundy/collection'
5
+ require 'burgundy/rails' if defined?(Rails)
@@ -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.map(@items.to_a)
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
@@ -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
- collection.map {|item| new(item) }
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)
@@ -1,3 +1,3 @@
1
1
  module Burgundy
2
- VERSION = "0.0.1"
2
+ VERSION = '0.0.3'
3
3
  end
@@ -1,45 +1,60 @@
1
- require "spec_helper"
1
+ require 'spec_helper'
2
2
 
3
3
  describe Burgundy do
4
4
  let(:wrapper) { Class.new(Burgundy::Item) }
5
5
 
6
- it "delegates everything" do
7
- item = wrapper.new("hello")
8
- expect(item.upcase).to eql("HELLO")
6
+ it 'delegates everything' do
7
+ item = wrapper.new('hello')
8
+ expect(item.upcase).to eql('HELLO')
9
9
  end
10
10
 
11
- it "wraps items" do
12
- items = wrapper.map([1,2,3])
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 "wraps items in collection" do
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 "includes Enumerable" do
30
+ it 'includes Enumerable' do
24
31
  expect(Burgundy::Collection).to include(Enumerable)
25
32
  end
26
33
 
27
- it "responds to the routes method" do
28
- item = wrapper.new("hello")
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 "responds to the helpers method" do
35
- item = wrapper.new("hello")
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 "responds to the I18n methods" do
42
- item = wrapper.new("hello")
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 "returns route using action mailer options" do
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: "example.org"}
56
- item = wrapper.new OpenStruct.new(username: "johndoe")
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("http://example.org/johndoe")
73
+ expect(item.profile_url).to eql('http://example.org/johndoe')
59
74
  end
60
75
 
61
- it "returns route using action controller options" do
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: "example.org"}
67
- item = wrapper.new OpenStruct.new(username: "johndoe")
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("http://example.org/johndoe")
84
+ expect(item.profile_url).to eql('http://example.org/johndoe')
70
85
  end
71
86
  end
@@ -1,13 +1,12 @@
1
- require "bundler/setup"
1
+ require 'bundler/setup'
2
2
  Bundler.setup
3
3
 
4
- ENV["RAILS_ENV"] = "test"
4
+ ENV['RAILS_ENV'] = 'test'
5
5
 
6
- require File.expand_path("../dummy/config/environment.rb", __FILE__)
7
- require "rspec/rails"
8
- require "rspec/autorun"
6
+ require File.expand_path('../dummy/config/environment.rb', __FILE__)
7
+ require 'rspec/rails'
9
8
 
10
- require "burgundy"
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.1
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: 2013-10-24 00:00:00.000000000 Z
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.0.3
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: