burgundy 0.2.0 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/.gitignore +1 -0
- data/.travis.yml +12 -2
- data/Gemfile +1 -1
- data/README.md +4 -1
- data/Rakefile +7 -3
- data/burgundy.gemspec +15 -16
- data/lib/burgundy.rb +5 -5
- data/lib/burgundy/collection.rb +8 -7
- data/lib/burgundy/item.rb +2 -2
- data/lib/burgundy/version.rb +1 -1
- data/{spec → test}/dummy/README.rdoc +0 -0
- data/{spec → test}/dummy/Rakefile +0 -0
- data/{spec → test}/dummy/app/assets/images/.keep +0 -0
- data/{spec → test}/dummy/app/assets/javascripts/application.js +0 -0
- data/{spec → test}/dummy/app/assets/stylesheets/application.css +0 -0
- data/{spec → test}/dummy/app/controllers/application_controller.rb +0 -0
- data/{spec → test}/dummy/app/controllers/concerns/.keep +0 -0
- data/{spec → test}/dummy/app/helpers/application_helper.rb +0 -0
- data/{spec → test}/dummy/app/mailers/.keep +0 -0
- data/{spec → test}/dummy/app/models/.keep +0 -0
- data/{spec → test}/dummy/app/models/concerns/.keep +0 -0
- data/{spec → test}/dummy/app/views/layouts/application.html.erb +0 -0
- data/{spec → test}/dummy/app/views/site/contact.html.erb +0 -0
- data/{spec → test}/dummy/bin/bundle +0 -0
- data/{spec → test}/dummy/bin/rails +0 -0
- data/{spec → test}/dummy/bin/rake +0 -0
- data/{spec → test}/dummy/config.ru +0 -0
- data/{spec → test}/dummy/config/application.rb +0 -0
- data/{spec → test}/dummy/config/boot.rb +0 -0
- data/{spec → test}/dummy/config/database.yml +0 -0
- data/{spec → test}/dummy/config/environment.rb +0 -0
- data/{spec → test}/dummy/config/environments/development.rb +0 -0
- data/{spec → test}/dummy/config/environments/production.rb +0 -0
- data/{spec → test}/dummy/config/environments/test.rb +1 -0
- data/{spec → test}/dummy/config/initializers/backtrace_silencers.rb +0 -0
- data/{spec → test}/dummy/config/initializers/filter_parameter_logging.rb +0 -0
- data/{spec → test}/dummy/config/initializers/inflections.rb +0 -0
- data/{spec → test}/dummy/config/initializers/mime_types.rb +0 -0
- data/{spec → test}/dummy/config/initializers/secret_token.rb +0 -0
- data/{spec → test}/dummy/config/initializers/session_store.rb +0 -0
- data/{spec → test}/dummy/config/initializers/wrap_parameters.rb +0 -0
- data/{spec → test}/dummy/config/locales/en.yml +0 -0
- data/{spec → test}/dummy/config/routes.rb +0 -0
- data/{spec → test}/dummy/lib/assets/.keep +0 -0
- data/{spec → test}/dummy/log/.keep +0 -0
- data/{spec → test}/dummy/public/404.html +0 -0
- data/{spec → test}/dummy/public/422.html +0 -0
- data/{spec → test}/dummy/public/500.html +0 -0
- data/{spec → test}/dummy/public/favicon.ico +0 -0
- data/test/test_helper.rb +26 -0
- data/test/unit/burgundy_test.rb +186 -0
- metadata +94 -97
- data/.rspec +0 -1
- data/spec/burgundy_spec.rb +0 -154
- data/spec/dummy/log/test.log +0 -45
- data/spec/spec_helper.rb +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 627aed370f1235851c0330858cb8132589b2763dd1e98ce217950a4e3f610285
|
4
|
+
data.tar.gz: 83c93daace0616835204810154b38b34c3ac9f325ca08d1dc4656118a2c30597
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1c732548588122cda059ec94dbab67f6e3a722249df688f339b812a75ba45e0d1809538771a2f9979f7fc08ae07f360c70969363d426047c82a8405c6cf9eaa7
|
7
|
+
data.tar.gz: 5dc524c77481653f1949e79ed8981e00cd9e1cfa1ab44781bdcd0ab2ef15b6e32bb9ed9fc1c0cf2ce6299c839b0f81a792f6419df1beaec20499e112d9da3e08
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
@@ -1,6 +1,16 @@
|
|
1
1
|
language: ruby
|
2
2
|
sudo: false
|
3
3
|
cache: bundler
|
4
|
+
notifications:
|
5
|
+
email: false
|
4
6
|
rvm:
|
5
|
-
|
6
|
-
|
7
|
+
- 2.5.2
|
8
|
+
before_script:
|
9
|
+
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
10
|
+
- chmod +x ./cc-test-reporter
|
11
|
+
- "./cc-test-reporter before-build"
|
12
|
+
after_script:
|
13
|
+
- "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
|
14
|
+
env:
|
15
|
+
global:
|
16
|
+
secure: LIU2voUl12O5yOXGTwOFOJgdv49YOpFN4FyH3Eqvc48tvy3cRypMuqvFiG/KL4jQvE2IydZZmG+DtsgTsi6kOe5cYlxeU2fTiK9dflNqBIV7+CfwXqguUAcwJLW1dt6Gtmis2VuOffJDBqpojTpFDrUosDdISc1gkOXh4+8yHQA=
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
# Burgundy
|
2
2
|
|
3
|
-
[![
|
3
|
+
[![Travis-CI](https://travis-ci.org/fnando/burgundy.svg)](https://travis-ci.org/fnando/burgundy)
|
4
4
|
[![Code Climate](https://codeclimate.com/github/fnando/burgundy/badges/gpa.svg)](https://codeclimate.com/github/fnando/burgundy)
|
5
|
+
[![Test Coverage](https://codeclimate.com/github/fnando/burgundy/badges/coverage.svg)](https://codeclimate.com/github/fnando/burgundy/coverage)
|
6
|
+
[![Gem](https://img.shields.io/gem/v/burgundy.svg)](https://rubygems.org/gems/burgundy)
|
7
|
+
[![Gem](https://img.shields.io/gem/dt/burgundy.svg)](https://rubygems.org/gems/burgundy)
|
5
8
|
|
6
9
|
A simple wrapper for objects (think of Burgundy as a decorator/presenter) in less than 150 lines.
|
7
10
|
|
data/Rakefile
CHANGED
@@ -1,6 +1,10 @@
|
|
1
1
|
require "bundler/gem_tasks"
|
2
|
-
require "
|
2
|
+
require "rake/testtask"
|
3
3
|
|
4
|
-
|
4
|
+
Rake::TestTask.new(:test) do |t|
|
5
|
+
t.libs << "test"
|
6
|
+
t.test_files = FileList["test/**/*_test.rb"]
|
7
|
+
t.warning = false
|
8
|
+
end
|
5
9
|
|
6
|
-
task :default => :
|
10
|
+
task :default => :test
|
data/burgundy.gemspec
CHANGED
@@ -1,25 +1,24 @@
|
|
1
|
-
require
|
1
|
+
require "./lib/burgundy/version"
|
2
2
|
|
3
3
|
Gem::Specification.new do |spec|
|
4
|
-
spec.
|
5
|
-
spec.name = 'burgundy'
|
4
|
+
spec.name = "burgundy"
|
6
5
|
spec.version = Burgundy::VERSION
|
7
|
-
spec.authors = [
|
8
|
-
spec.email = [
|
9
|
-
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."
|
10
9
|
spec.summary = spec.description
|
11
|
-
spec.homepage =
|
12
|
-
spec.license =
|
10
|
+
spec.homepage = "http://github.com/fnando/burgundy"
|
11
|
+
spec.license = "MIT"
|
13
12
|
|
14
13
|
spec.files = `git ls-files`.split($/)
|
15
|
-
spec.executables = spec.files.grep(%r{^bin/}) {
|
14
|
+
spec.executables = spec.files.grep(%r{^bin/}) {|f| File.basename(f) }
|
16
15
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
17
|
-
spec.require_paths = [
|
16
|
+
spec.require_paths = ["lib"]
|
18
17
|
|
19
|
-
spec.add_development_dependency
|
20
|
-
spec.add_development_dependency
|
21
|
-
spec.add_development_dependency
|
22
|
-
spec.add_development_dependency
|
23
|
-
spec.add_development_dependency
|
24
|
-
spec.add_development_dependency
|
18
|
+
spec.add_development_dependency "bundler"
|
19
|
+
spec.add_development_dependency "minitest-utils"
|
20
|
+
spec.add_development_dependency "pry-meta"
|
21
|
+
spec.add_development_dependency "rails"
|
22
|
+
spec.add_development_dependency "rake"
|
23
|
+
spec.add_development_dependency "simplecov"
|
25
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
@@ -1,20 +1,21 @@
|
|
1
1
|
module Burgundy
|
2
|
-
class Collection
|
3
|
-
include Enumerable
|
4
|
-
|
2
|
+
class Collection
|
5
3
|
def initialize(items, wrapping_class = nil, *args)
|
6
4
|
@items = items
|
7
5
|
@wrapping_class = wrapping_class
|
8
6
|
@args = args
|
9
|
-
__setobj__(@items)
|
10
7
|
end
|
11
8
|
|
12
|
-
def
|
13
|
-
to_ary.
|
9
|
+
def method_missing(name, *args, &block)
|
10
|
+
to_ary.send(name, *args, &block)
|
11
|
+
end
|
12
|
+
|
13
|
+
def respond_to?(name, include_all = false)
|
14
|
+
to_ary.respond_to?(name, include_all)
|
14
15
|
end
|
15
16
|
|
16
17
|
def to_ary
|
17
|
-
@
|
18
|
+
@to_ary ||= if @wrapping_class
|
18
19
|
@items.map {|item| @wrapping_class.new(item, *@args) }
|
19
20
|
else
|
20
21
|
@items.to_a
|
data/lib/burgundy/item.rb
CHANGED
@@ -11,7 +11,7 @@ module Burgundy
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def self.map(collection)
|
14
|
-
warn
|
14
|
+
warn "Burgundy::Item.map is deprecated; use Burgundy::Item.wrap instead."
|
15
15
|
wrap(collection)
|
16
16
|
end
|
17
17
|
|
@@ -20,7 +20,7 @@ module Burgundy
|
|
20
20
|
|
21
21
|
if args.any?
|
22
22
|
@attributes = {}
|
23
|
-
@attributes = args.pop if args.last.
|
23
|
+
@attributes = args.pop if args.last.is_a?(Hash)
|
24
24
|
@attributes.merge!(args.zip(args).to_h)
|
25
25
|
end
|
26
26
|
|
data/lib/burgundy/version.rb
CHANGED
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
require "simplecov"
|
2
|
+
SimpleCov.start do
|
3
|
+
add_filter "/test/"
|
4
|
+
end
|
5
|
+
|
6
|
+
require "bundler/setup"
|
7
|
+
Bundler.setup
|
8
|
+
|
9
|
+
require "minitest/utils"
|
10
|
+
require "minitest/autorun"
|
11
|
+
|
12
|
+
ENV["RAILS_ENV"] = "test"
|
13
|
+
|
14
|
+
require File.expand_path("dummy/config/environment.rb", __dir__)
|
15
|
+
|
16
|
+
require "burgundy"
|
17
|
+
I18n.locale = :en
|
18
|
+
|
19
|
+
class ItemWithAdditionalArgs < Burgundy::Item
|
20
|
+
attr_reader :args
|
21
|
+
|
22
|
+
def initialize(target, *args)
|
23
|
+
super(target)
|
24
|
+
@args = args
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,186 @@
|
|
1
|
+
require "test_helper"
|
2
|
+
|
3
|
+
class BurgundyTest < Minitest::Test
|
4
|
+
let(:wrapper) { Class.new(Burgundy::Item) }
|
5
|
+
let(:wrapper_with_args) { ItemWithAdditionalArgs }
|
6
|
+
|
7
|
+
test "delegates everything" do
|
8
|
+
item = wrapper.new("hello")
|
9
|
+
assert_equal "HELLO", item.upcase
|
10
|
+
end
|
11
|
+
|
12
|
+
test "wraps items" do
|
13
|
+
items = wrapper.wrap([1, 2, 3])
|
14
|
+
|
15
|
+
assert_equal Burgundy::Collection, items.class
|
16
|
+
assert_kind_of wrapper, items.first
|
17
|
+
assert_equal 1, items.first.to_i
|
18
|
+
end
|
19
|
+
|
20
|
+
test "wraps items with additional arguments" do
|
21
|
+
items = wrapper_with_args.wrap([1], 2, 3)
|
22
|
+
|
23
|
+
assert_equal Burgundy::Collection, items.class
|
24
|
+
assert_kind_of wrapper_with_args, items.first
|
25
|
+
assert_equal 1, items.first.item
|
26
|
+
assert_equal [2, 3], items.first.args
|
27
|
+
end
|
28
|
+
|
29
|
+
test "deprecates Burgundy::Item.map" do
|
30
|
+
message = "Burgundy::Item.map is deprecated; use Burgundy::Item.wrap instead."
|
31
|
+
|
32
|
+
_, err = capture_io do
|
33
|
+
wrapper.map([1, 2, 3])
|
34
|
+
end
|
35
|
+
|
36
|
+
assert err.include?(message)
|
37
|
+
end
|
38
|
+
|
39
|
+
test "wraps items in collection" do
|
40
|
+
collection = Burgundy::Collection.new([1, 2, 3], wrapper)
|
41
|
+
assert_equal 1, collection.first
|
42
|
+
end
|
43
|
+
|
44
|
+
test "delegates collection calls" do
|
45
|
+
collection = Burgundy::Collection.new([1, 2, 3], wrapper)
|
46
|
+
assert_equal 3, collection.size
|
47
|
+
end
|
48
|
+
|
49
|
+
test "collection uses to_a result when have no wrapper class" do
|
50
|
+
items = Class.new do
|
51
|
+
def to_a
|
52
|
+
[1, 2, 3]
|
53
|
+
end
|
54
|
+
end.new
|
55
|
+
|
56
|
+
collection = Burgundy::Collection.new(items)
|
57
|
+
|
58
|
+
assert_equal [1, 2, 3], collection.to_ary
|
59
|
+
end
|
60
|
+
|
61
|
+
test "implements #empty?" do
|
62
|
+
collection = Burgundy::Collection.new([1, 2, 3])
|
63
|
+
refute collection.empty?
|
64
|
+
|
65
|
+
collection = Burgundy::Collection.new([])
|
66
|
+
assert collection.empty?
|
67
|
+
end
|
68
|
+
|
69
|
+
test "responds to the routes method" do
|
70
|
+
item = wrapper.new("hello")
|
71
|
+
|
72
|
+
assert_respond_to item, :routes
|
73
|
+
assert_respond_to item, :r
|
74
|
+
end
|
75
|
+
|
76
|
+
test "responds to the helpers method" do
|
77
|
+
item = wrapper.new("hello")
|
78
|
+
|
79
|
+
assert_respond_to item, :helpers
|
80
|
+
assert_respond_to item, :h
|
81
|
+
end
|
82
|
+
|
83
|
+
test "responds to the I18n methods" do
|
84
|
+
item = wrapper.new("hello")
|
85
|
+
|
86
|
+
assert_respond_to item, :translate
|
87
|
+
assert_respond_to item, :t
|
88
|
+
assert_respond_to item, :localize
|
89
|
+
assert_respond_to item, :l
|
90
|
+
end
|
91
|
+
|
92
|
+
test "returns route using action mailer options" do
|
93
|
+
wrapper = Class.new(Burgundy::Item) do
|
94
|
+
def profile_url
|
95
|
+
routes.profile_url(username)
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
Rails.configuration.action_mailer.default_url_options = {host: "example.com"}
|
100
|
+
item = wrapper.new OpenStruct.new(username: "johndoe")
|
101
|
+
|
102
|
+
assert_equal "http://example.com/johndoe", item.profile_url
|
103
|
+
end
|
104
|
+
|
105
|
+
test "returns route using action controller options" do
|
106
|
+
wrapper = Class.new(Burgundy::Item) do
|
107
|
+
def profile_url
|
108
|
+
routes.profile_url(username)
|
109
|
+
end
|
110
|
+
end
|
111
|
+
|
112
|
+
Rails.application.routes.default_url_options = {host: "example.com"}
|
113
|
+
item = wrapper.new OpenStruct.new(username: "johndoe")
|
114
|
+
|
115
|
+
assert_equal "http://example.com/johndoe", item.profile_url
|
116
|
+
end
|
117
|
+
|
118
|
+
test "returns attributes" do
|
119
|
+
wrapper = Class.new(Burgundy::Item) do
|
120
|
+
attributes :name, :email
|
121
|
+
end
|
122
|
+
|
123
|
+
object = OpenStruct.new(name: "John Doe", email: "john@example.com", username: "johndoe")
|
124
|
+
item = wrapper.new(object)
|
125
|
+
|
126
|
+
expected = {name: "John Doe", email: "john@example.com"}
|
127
|
+
|
128
|
+
assert_equal expected, item.attributes
|
129
|
+
end
|
130
|
+
|
131
|
+
test "returns remaps attribute" do
|
132
|
+
wrapper = Class.new(Burgundy::Item) do
|
133
|
+
attributes :name, :username => :login
|
134
|
+
end
|
135
|
+
|
136
|
+
object = OpenStruct.new(name: "John Doe", username: "johndoe")
|
137
|
+
item = wrapper.new(object)
|
138
|
+
|
139
|
+
expected = {name: "John Doe", login: "johndoe"}
|
140
|
+
|
141
|
+
assert_equal expected, item.attributes
|
142
|
+
end
|
143
|
+
|
144
|
+
test "implements to_hash/to_h protocol" do
|
145
|
+
wrapper = Class.new(Burgundy::Item) do
|
146
|
+
attributes :name, :email
|
147
|
+
end
|
148
|
+
|
149
|
+
object = OpenStruct.new(name: "John Doe", email: "john@example.com", username: "johndoe")
|
150
|
+
item = wrapper.new(object)
|
151
|
+
|
152
|
+
assert_equal item.to_hash, item.attributes
|
153
|
+
assert_equal item.to_h, item.attributes
|
154
|
+
end
|
155
|
+
|
156
|
+
test "inherits attributes" do
|
157
|
+
parent_wrapper = Class.new(Burgundy::Item) do
|
158
|
+
attributes :name, :username
|
159
|
+
end
|
160
|
+
|
161
|
+
wrapper = Class.new(parent_wrapper)
|
162
|
+
object = OpenStruct.new(name: "John Doe", username: "johndoe")
|
163
|
+
item = wrapper.new(object)
|
164
|
+
|
165
|
+
expected = {name: "John Doe", username: "johndoe"}
|
166
|
+
|
167
|
+
assert_equal expected, item.attributes
|
168
|
+
end
|
169
|
+
|
170
|
+
test "always wrap items fetched from collection" do
|
171
|
+
wrapper = Class.new(Burgundy::Item)
|
172
|
+
collection = wrapper.wrap([1])
|
173
|
+
|
174
|
+
assert_kind_of wrapper, collection[0]
|
175
|
+
assert_kind_of wrapper, collection.fetch(0)
|
176
|
+
assert_kind_of wrapper, collection.at(0)
|
177
|
+
end
|
178
|
+
|
179
|
+
test "responds to methods present on the underying wrapped object" do
|
180
|
+
wrapper = Class.new(Burgundy::Item)
|
181
|
+
collection = wrapper.wrap([1])
|
182
|
+
|
183
|
+
assert collection.respond_to?(:first)
|
184
|
+
refute collection.respond_to?(:missing)
|
185
|
+
end
|
186
|
+
end
|
metadata
CHANGED
@@ -1,31 +1,31 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: burgundy
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
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: 2018-12-27 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
|
-
version: '
|
19
|
+
version: '0'
|
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
|
-
version: '
|
26
|
+
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: minitest-utils
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name:
|
42
|
+
name: pry-meta
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -67,7 +67,7 @@ dependencies:
|
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
|
-
name:
|
70
|
+
name: rake
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
72
72
|
requirements:
|
73
73
|
- - ">="
|
@@ -81,7 +81,7 @@ dependencies:
|
|
81
81
|
- !ruby/object:Gem::Version
|
82
82
|
version: '0'
|
83
83
|
- !ruby/object:Gem::Dependency
|
84
|
-
name:
|
84
|
+
name: simplecov
|
85
85
|
requirement: !ruby/object:Gem::Requirement
|
86
86
|
requirements:
|
87
87
|
- - ">="
|
@@ -103,7 +103,6 @@ extensions: []
|
|
103
103
|
extra_rdoc_files: []
|
104
104
|
files:
|
105
105
|
- ".gitignore"
|
106
|
-
- ".rspec"
|
107
106
|
- ".travis.yml"
|
108
107
|
- CHANGELOG.md
|
109
108
|
- Gemfile
|
@@ -116,48 +115,47 @@ files:
|
|
116
115
|
- lib/burgundy/item.rb
|
117
116
|
- lib/burgundy/rails.rb
|
118
117
|
- lib/burgundy/version.rb
|
119
|
-
-
|
120
|
-
-
|
121
|
-
-
|
122
|
-
-
|
123
|
-
-
|
124
|
-
-
|
125
|
-
-
|
126
|
-
-
|
127
|
-
-
|
128
|
-
-
|
129
|
-
-
|
130
|
-
-
|
131
|
-
-
|
132
|
-
-
|
133
|
-
-
|
134
|
-
-
|
135
|
-
-
|
136
|
-
-
|
137
|
-
-
|
138
|
-
-
|
139
|
-
-
|
140
|
-
-
|
141
|
-
-
|
142
|
-
-
|
143
|
-
-
|
144
|
-
-
|
145
|
-
-
|
146
|
-
-
|
147
|
-
-
|
148
|
-
-
|
149
|
-
-
|
150
|
-
-
|
151
|
-
-
|
152
|
-
-
|
153
|
-
-
|
154
|
-
-
|
155
|
-
-
|
156
|
-
-
|
157
|
-
-
|
158
|
-
-
|
159
|
-
-
|
160
|
-
- spec/spec_helper.rb
|
118
|
+
- test/dummy/README.rdoc
|
119
|
+
- test/dummy/Rakefile
|
120
|
+
- test/dummy/app/assets/images/.keep
|
121
|
+
- test/dummy/app/assets/javascripts/application.js
|
122
|
+
- test/dummy/app/assets/stylesheets/application.css
|
123
|
+
- test/dummy/app/controllers/application_controller.rb
|
124
|
+
- test/dummy/app/controllers/concerns/.keep
|
125
|
+
- test/dummy/app/helpers/application_helper.rb
|
126
|
+
- test/dummy/app/mailers/.keep
|
127
|
+
- test/dummy/app/models/.keep
|
128
|
+
- test/dummy/app/models/concerns/.keep
|
129
|
+
- test/dummy/app/views/layouts/application.html.erb
|
130
|
+
- test/dummy/app/views/site/contact.html.erb
|
131
|
+
- test/dummy/bin/bundle
|
132
|
+
- test/dummy/bin/rails
|
133
|
+
- test/dummy/bin/rake
|
134
|
+
- test/dummy/config.ru
|
135
|
+
- test/dummy/config/application.rb
|
136
|
+
- test/dummy/config/boot.rb
|
137
|
+
- test/dummy/config/database.yml
|
138
|
+
- test/dummy/config/environment.rb
|
139
|
+
- test/dummy/config/environments/development.rb
|
140
|
+
- test/dummy/config/environments/production.rb
|
141
|
+
- test/dummy/config/environments/test.rb
|
142
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
143
|
+
- test/dummy/config/initializers/filter_parameter_logging.rb
|
144
|
+
- test/dummy/config/initializers/inflections.rb
|
145
|
+
- test/dummy/config/initializers/mime_types.rb
|
146
|
+
- test/dummy/config/initializers/secret_token.rb
|
147
|
+
- test/dummy/config/initializers/session_store.rb
|
148
|
+
- test/dummy/config/initializers/wrap_parameters.rb
|
149
|
+
- test/dummy/config/locales/en.yml
|
150
|
+
- test/dummy/config/routes.rb
|
151
|
+
- test/dummy/lib/assets/.keep
|
152
|
+
- test/dummy/log/.keep
|
153
|
+
- test/dummy/public/404.html
|
154
|
+
- test/dummy/public/422.html
|
155
|
+
- test/dummy/public/500.html
|
156
|
+
- test/dummy/public/favicon.ico
|
157
|
+
- test/test_helper.rb
|
158
|
+
- test/unit/burgundy_test.rb
|
161
159
|
homepage: http://github.com/fnando/burgundy
|
162
160
|
licenses:
|
163
161
|
- MIT
|
@@ -170,7 +168,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
170
168
|
requirements:
|
171
169
|
- - ">="
|
172
170
|
- !ruby/object:Gem::Version
|
173
|
-
version:
|
171
|
+
version: '0'
|
174
172
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
175
173
|
requirements:
|
176
174
|
- - ">="
|
@@ -178,51 +176,50 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
178
176
|
version: '0'
|
179
177
|
requirements: []
|
180
178
|
rubyforge_project:
|
181
|
-
rubygems_version: 2.
|
179
|
+
rubygems_version: 2.7.6
|
182
180
|
signing_key:
|
183
181
|
specification_version: 4
|
184
182
|
summary: A simple wrapper for objects (think of Burgundy as a decorator/presenter)
|
185
183
|
in less than 100 lines.
|
186
184
|
test_files:
|
187
|
-
-
|
188
|
-
-
|
189
|
-
-
|
190
|
-
-
|
191
|
-
-
|
192
|
-
-
|
193
|
-
-
|
194
|
-
-
|
195
|
-
-
|
196
|
-
-
|
197
|
-
-
|
198
|
-
-
|
199
|
-
-
|
200
|
-
-
|
201
|
-
-
|
202
|
-
-
|
203
|
-
-
|
204
|
-
-
|
205
|
-
-
|
206
|
-
-
|
207
|
-
-
|
208
|
-
-
|
209
|
-
-
|
210
|
-
-
|
211
|
-
-
|
212
|
-
-
|
213
|
-
-
|
214
|
-
-
|
215
|
-
-
|
216
|
-
-
|
217
|
-
-
|
218
|
-
-
|
219
|
-
-
|
220
|
-
-
|
221
|
-
-
|
222
|
-
-
|
223
|
-
-
|
224
|
-
-
|
225
|
-
-
|
226
|
-
-
|
227
|
-
-
|
228
|
-
- spec/spec_helper.rb
|
185
|
+
- test/dummy/README.rdoc
|
186
|
+
- test/dummy/Rakefile
|
187
|
+
- test/dummy/app/assets/images/.keep
|
188
|
+
- test/dummy/app/assets/javascripts/application.js
|
189
|
+
- test/dummy/app/assets/stylesheets/application.css
|
190
|
+
- test/dummy/app/controllers/application_controller.rb
|
191
|
+
- test/dummy/app/controllers/concerns/.keep
|
192
|
+
- test/dummy/app/helpers/application_helper.rb
|
193
|
+
- test/dummy/app/mailers/.keep
|
194
|
+
- test/dummy/app/models/.keep
|
195
|
+
- test/dummy/app/models/concerns/.keep
|
196
|
+
- test/dummy/app/views/layouts/application.html.erb
|
197
|
+
- test/dummy/app/views/site/contact.html.erb
|
198
|
+
- test/dummy/bin/bundle
|
199
|
+
- test/dummy/bin/rails
|
200
|
+
- test/dummy/bin/rake
|
201
|
+
- test/dummy/config.ru
|
202
|
+
- test/dummy/config/application.rb
|
203
|
+
- test/dummy/config/boot.rb
|
204
|
+
- test/dummy/config/database.yml
|
205
|
+
- test/dummy/config/environment.rb
|
206
|
+
- test/dummy/config/environments/development.rb
|
207
|
+
- test/dummy/config/environments/production.rb
|
208
|
+
- test/dummy/config/environments/test.rb
|
209
|
+
- test/dummy/config/initializers/backtrace_silencers.rb
|
210
|
+
- test/dummy/config/initializers/filter_parameter_logging.rb
|
211
|
+
- test/dummy/config/initializers/inflections.rb
|
212
|
+
- test/dummy/config/initializers/mime_types.rb
|
213
|
+
- test/dummy/config/initializers/secret_token.rb
|
214
|
+
- test/dummy/config/initializers/session_store.rb
|
215
|
+
- test/dummy/config/initializers/wrap_parameters.rb
|
216
|
+
- test/dummy/config/locales/en.yml
|
217
|
+
- test/dummy/config/routes.rb
|
218
|
+
- test/dummy/lib/assets/.keep
|
219
|
+
- test/dummy/log/.keep
|
220
|
+
- test/dummy/public/404.html
|
221
|
+
- test/dummy/public/422.html
|
222
|
+
- test/dummy/public/500.html
|
223
|
+
- test/dummy/public/favicon.ico
|
224
|
+
- test/test_helper.rb
|
225
|
+
- test/unit/burgundy_test.rb
|
data/.rspec
DELETED
@@ -1 +0,0 @@
|
|
1
|
-
--color
|
data/spec/burgundy_spec.rb
DELETED
@@ -1,154 +0,0 @@
|
|
1
|
-
require 'spec_helper'
|
2
|
-
|
3
|
-
describe Burgundy do
|
4
|
-
let(:wrapper) { Class.new(Burgundy::Item) }
|
5
|
-
let(:wrapper_with_args) { ItemWithAdditionalArgs }
|
6
|
-
|
7
|
-
it 'delegates everything' do
|
8
|
-
item = wrapper.new('hello')
|
9
|
-
expect(item.upcase).to eql('HELLO')
|
10
|
-
end
|
11
|
-
|
12
|
-
it 'wraps items' do
|
13
|
-
items = wrapper.wrap([1,2,3])
|
14
|
-
|
15
|
-
expect(items.class).to eql(Burgundy::Collection)
|
16
|
-
expect(items.first).to be_a(wrapper)
|
17
|
-
expect(items.first.to_i).to eql(1)
|
18
|
-
end
|
19
|
-
|
20
|
-
it 'wraps items with additional arguments' do
|
21
|
-
items = wrapper_with_args.wrap([1], 2, 3)
|
22
|
-
|
23
|
-
expect(items.class).to eql(Burgundy::Collection)
|
24
|
-
expect(items.first).to be_a(wrapper_with_args)
|
25
|
-
expect(items.first.item).to eql(1)
|
26
|
-
expect(items.first.args).to eql([2, 3])
|
27
|
-
end
|
28
|
-
|
29
|
-
it 'deprecates Burgundy::Item.map' do
|
30
|
-
message = 'Burgundy::Item.map is deprecated; use Burgundy::Item.wrap instead.'
|
31
|
-
expect(wrapper).to receive(:warn).with(message)
|
32
|
-
wrapper.map([1,2,3])
|
33
|
-
end
|
34
|
-
|
35
|
-
it 'wraps items in collection' do
|
36
|
-
collection = Burgundy::Collection.new([1,2,3], wrapper)
|
37
|
-
expect(collection.first).to eql(1)
|
38
|
-
end
|
39
|
-
|
40
|
-
it 'wraps items with additional arguments' do
|
41
|
-
collection = Burgundy::Collection.new([1], wrapper_with_args, 2, 3)
|
42
|
-
|
43
|
-
expect(collection.first.item).to eq(1)
|
44
|
-
expect(collection.first.args).to eq([2, 3])
|
45
|
-
end
|
46
|
-
|
47
|
-
it 'delegates collection calls' do
|
48
|
-
collection = Burgundy::Collection.new([1,2,3], wrapper)
|
49
|
-
expect(collection.size).to eql(3)
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'includes Enumerable' do
|
53
|
-
expect(Burgundy::Collection).to include(Enumerable)
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'implements #empty?' do
|
57
|
-
collection = Burgundy::Collection.new([1,2,3])
|
58
|
-
expect(collection).not_to be_empty
|
59
|
-
|
60
|
-
collection = Burgundy::Collection.new([])
|
61
|
-
expect(collection).to be_empty
|
62
|
-
end
|
63
|
-
|
64
|
-
it 'responds to the routes method' do
|
65
|
-
item = wrapper.new('hello')
|
66
|
-
|
67
|
-
expect(item).to respond_to(:routes)
|
68
|
-
expect(item).to respond_to(:r)
|
69
|
-
end
|
70
|
-
|
71
|
-
it 'responds to the helpers method' do
|
72
|
-
item = wrapper.new('hello')
|
73
|
-
|
74
|
-
expect(item).to respond_to(:helpers)
|
75
|
-
expect(item).to respond_to(:h)
|
76
|
-
end
|
77
|
-
|
78
|
-
it 'responds to the I18n methods' do
|
79
|
-
item = wrapper.new('hello')
|
80
|
-
|
81
|
-
expect(item).to respond_to(:translate)
|
82
|
-
expect(item).to respond_to(:t)
|
83
|
-
expect(item).to respond_to(:localize)
|
84
|
-
expect(item).to respond_to(:l)
|
85
|
-
end
|
86
|
-
|
87
|
-
it 'returns route using action mailer options' do
|
88
|
-
wrapper = Class.new(Burgundy::Item) do
|
89
|
-
def profile_url; routes.profile_url(username) end
|
90
|
-
end
|
91
|
-
|
92
|
-
Rails.configuration.action_mailer.default_url_options = {host: 'example.org'}
|
93
|
-
item = wrapper.new OpenStruct.new(username: 'johndoe')
|
94
|
-
|
95
|
-
expect(item.profile_url).to eql('http://example.org/johndoe')
|
96
|
-
end
|
97
|
-
|
98
|
-
it 'returns route using action controller options' do
|
99
|
-
wrapper = Class.new(Burgundy::Item) do
|
100
|
-
def profile_url; routes.profile_url(username) end
|
101
|
-
end
|
102
|
-
|
103
|
-
Rails.application.routes.default_url_options = {host: 'example.org'}
|
104
|
-
item = wrapper.new OpenStruct.new(username: 'johndoe')
|
105
|
-
|
106
|
-
expect(item.profile_url).to eql('http://example.org/johndoe')
|
107
|
-
end
|
108
|
-
|
109
|
-
it 'returns attributes' do
|
110
|
-
wrapper = Class.new(Burgundy::Item) do
|
111
|
-
attributes :name, :email
|
112
|
-
end
|
113
|
-
|
114
|
-
object = OpenStruct.new(name: 'John Doe', email: 'john@example.org', username: 'johndoe')
|
115
|
-
item = wrapper.new(object)
|
116
|
-
|
117
|
-
expect(item.attributes).to eq(name: 'John Doe', email: 'john@example.org')
|
118
|
-
end
|
119
|
-
|
120
|
-
it 'returns remaps attribute' do
|
121
|
-
wrapper = Class.new(Burgundy::Item) do
|
122
|
-
attributes :name, :username => :login
|
123
|
-
end
|
124
|
-
|
125
|
-
object = OpenStruct.new(name: 'John Doe', username: 'johndoe')
|
126
|
-
item = wrapper.new(object)
|
127
|
-
|
128
|
-
expect(item.attributes).to eq(name: 'John Doe', login: 'johndoe')
|
129
|
-
end
|
130
|
-
|
131
|
-
it 'implements to_hash/to_h protocol' do
|
132
|
-
wrapper = Class.new(Burgundy::Item) do
|
133
|
-
attributes :name, :email
|
134
|
-
end
|
135
|
-
|
136
|
-
object = OpenStruct.new(name: 'John Doe', email: 'john@example.org', username: 'johndoe')
|
137
|
-
item = wrapper.new(object)
|
138
|
-
|
139
|
-
expect(item.attributes).to eq(item.to_hash)
|
140
|
-
expect(item.attributes).to eq(item.to_h)
|
141
|
-
end
|
142
|
-
|
143
|
-
it 'inherits attributes' do
|
144
|
-
parent_wrapper = Class.new(Burgundy::Item) do
|
145
|
-
attributes :name, :username
|
146
|
-
end
|
147
|
-
|
148
|
-
wrapper = Class.new(parent_wrapper)
|
149
|
-
object = OpenStruct.new(name: 'John Doe', username: 'johndoe')
|
150
|
-
item = wrapper.new(object)
|
151
|
-
|
152
|
-
expect(item.attributes).to eq(name: 'John Doe', username: 'johndoe')
|
153
|
-
end
|
154
|
-
end
|
data/spec/dummy/log/test.log
DELETED
@@ -1,45 +0,0 @@
|
|
1
|
-
Processing by SiteController#index as HTML
|
2
|
-
Rendered text template (0.0ms)
|
3
|
-
Completed 200 OK in 12ms (Views: 11.8ms)
|
4
|
-
Processing by Admin::CategoriesController#index as HTML
|
5
|
-
Completed 200 OK in 1ms (Views: 0.5ms)
|
6
|
-
Processing by CategoriesController#show as HTML
|
7
|
-
Completed 200 OK in 1ms (Views: 0.6ms)
|
8
|
-
Processing by SiteController#contact as HTML
|
9
|
-
Completed 200 OK in 30ms (Views: 30.2ms)
|
10
|
-
Processing by SiteController#index as HTML
|
11
|
-
Rendered text template (0.0ms)
|
12
|
-
Completed 200 OK in 31ms (Views: 30.7ms)
|
13
|
-
Processing by Admin::CategoriesController#index as HTML
|
14
|
-
Completed 200 OK in 1ms (Views: 0.5ms)
|
15
|
-
Processing by CategoriesController#show as HTML
|
16
|
-
Completed 200 OK in 1ms (Views: 0.5ms)
|
17
|
-
Processing by SiteController#contact as HTML
|
18
|
-
Completed 200 OK in 25ms (Views: 25.3ms)
|
19
|
-
Processing by SiteController#index as HTML
|
20
|
-
Rendered text template (0.1ms)
|
21
|
-
Completed 200 OK in 36ms (Views: 36.1ms)
|
22
|
-
Processing by Admin::CategoriesController#index as HTML
|
23
|
-
Completed 200 OK in 1ms (Views: 0.6ms)
|
24
|
-
Processing by CategoriesController#show as HTML
|
25
|
-
Completed 200 OK in 1ms (Views: 0.5ms)
|
26
|
-
Processing by SiteController#contact as HTML
|
27
|
-
Completed 200 OK in 26ms (Views: 25.8ms)
|
28
|
-
Processing by SiteController#index as HTML
|
29
|
-
Rendered text template (0.0ms)
|
30
|
-
Completed 200 OK in 37ms (Views: 37.0ms)
|
31
|
-
Processing by Admin::CategoriesController#index as HTML
|
32
|
-
Completed 200 OK in 1ms (Views: 0.5ms)
|
33
|
-
Processing by CategoriesController#show as HTML
|
34
|
-
Completed 200 OK in 1ms (Views: 0.5ms)
|
35
|
-
Processing by SiteController#contact as HTML
|
36
|
-
Completed 200 OK in 28ms (Views: 28.1ms)
|
37
|
-
Processing by SiteController#index as HTML
|
38
|
-
Rendered text template (0.0ms)
|
39
|
-
Completed 200 OK in 33ms (Views: 32.9ms)
|
40
|
-
Processing by Admin::CategoriesController#index as HTML
|
41
|
-
Completed 200 OK in 1ms (Views: 0.9ms)
|
42
|
-
Processing by CategoriesController#show as HTML
|
43
|
-
Completed 200 OK in 1ms (Views: 0.5ms)
|
44
|
-
Processing by SiteController#contact as HTML
|
45
|
-
Completed 200 OK in 25ms (Views: 25.2ms)
|
data/spec/spec_helper.rb
DELETED
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'bundler/setup'
|
2
|
-
Bundler.setup
|
3
|
-
|
4
|
-
ENV['RAILS_ENV'] = 'test'
|
5
|
-
|
6
|
-
require File.expand_path('../dummy/config/environment.rb', __FILE__)
|
7
|
-
require 'rspec/rails'
|
8
|
-
|
9
|
-
require 'burgundy'
|
10
|
-
I18n.locale = :en
|
11
|
-
|
12
|
-
class ItemWithAdditionalArgs < Burgundy::Item
|
13
|
-
attr_reader :args
|
14
|
-
|
15
|
-
def initialize(target, *args)
|
16
|
-
super(target)
|
17
|
-
@args = args
|
18
|
-
end
|
19
|
-
end
|