oprah 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/CHANGELOG.md +7 -0
- data/README.md +6 -1
- data/lib/oprah.rb +1 -0
- data/lib/oprah/cache.rb +3 -4
- data/lib/oprah/presenter.rb +10 -0
- data/lib/oprah/test_helpers.rb +11 -0
- data/lib/oprah/version.rb +1 -1
- data/test/helper.rb +5 -0
- data/test/oprah/presenter_test.rb +14 -5
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: b1e9fd6ab8d90759dcb787eadca9fd7ef1c2afe8
|
4
|
+
data.tar.gz: 9aeae5743f0dc4572659e5da7cae55bcfcbdeec8
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3398aba9e5893f76f10378beb116b6d87669e578e78bb90404c2d5fcb305a9e40f4c90cb51e14348f62758eefec15ea3635f465b56c607af6541717fca431f58
|
7
|
+
data.tar.gz: 1eef4021cd796d65299e84a53f97ca1eae5d66b14dafb45e25a81297dd3302d7e43f46620ae83a640cd4c3e673720b512373bc01375268340eed1c41f28856e7
|
data/.travis.yml
CHANGED
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,10 @@
|
|
1
1
|
# Oprah
|
2
2
|
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/oprah.svg)](https://badge.fury.io/rb/oprah)
|
4
|
+
[![Build Status](https://travis-ci.org/endofunky/oprah.svg)](https://travis-ci.org/endofunky/oprah)
|
5
|
+
[![Code Climate](https://codeclimate.com/github/endofunky/oprah.svg)](https://codeclimate.com/github/endofunky/oprah)
|
6
|
+
[![Dependency Status](https://gemnasium.com/badges/github.com/endofunky/oprah.svg)](https://gemnasium.com/github.com/endofunky/oprah)
|
7
|
+
|
3
8
|
Opinionated presenters for Rails 5 - without the cruft.
|
4
9
|
|
5
10
|
## Table of Contents
|
@@ -102,7 +107,7 @@ what's going on, even if that means to be (at least a little bit) explicit.
|
|
102
107
|
Here's how you can use Oprah presenters from your controller:
|
103
108
|
|
104
109
|
``` ruby
|
105
|
-
class
|
110
|
+
class UsersController < ApplicationController
|
106
111
|
def show
|
107
112
|
@user = present User.find(params[:id])
|
108
113
|
end
|
data/lib/oprah.rb
CHANGED
data/lib/oprah/cache.rb
CHANGED
@@ -15,9 +15,8 @@ module Oprah
|
|
15
15
|
@mutex.synchronize do
|
16
16
|
key = class_name_for(object)
|
17
17
|
|
18
|
-
|
19
|
-
|
20
|
-
end
|
18
|
+
cached = @mapping[key]
|
19
|
+
return cached if cached
|
21
20
|
|
22
21
|
@mapping[key] = presenter_classes_for(object)
|
23
22
|
end
|
@@ -42,7 +41,7 @@ module Oprah
|
|
42
41
|
class_for(object).ancestors.map do |klass|
|
43
42
|
begin
|
44
43
|
(klass.name + "Presenter").constantize
|
45
|
-
rescue
|
44
|
+
rescue NameError
|
46
45
|
end
|
47
46
|
end.compact.reverse
|
48
47
|
end
|
data/lib/oprah/presenter.rb
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
module Oprah
|
2
2
|
class Presenter
|
3
|
+
extend Forwardable
|
4
|
+
|
3
5
|
# @return [Object] The presented object
|
4
6
|
attr_reader :object
|
5
7
|
|
@@ -11,6 +13,14 @@ module Oprah
|
|
11
13
|
# @!visibility private
|
12
14
|
@@cache = Oprah::Cache.new
|
13
15
|
|
16
|
+
# @!method inspect
|
17
|
+
# @see Object#inspect
|
18
|
+
# @return [String]
|
19
|
+
# @!method to_s
|
20
|
+
# @see Object#to_s
|
21
|
+
# @return [String]
|
22
|
+
def_delegators :@object, :inspect, :to_s
|
23
|
+
|
14
24
|
class << self
|
15
25
|
# Returns the shared presenter cache object.
|
16
26
|
#
|
data/lib/oprah/version.rb
CHANGED
data/test/helper.rb
CHANGED
@@ -49,6 +49,11 @@ module Oprah
|
|
49
49
|
assert_kind_of ActionView::Context, presenter.view_context
|
50
50
|
end
|
51
51
|
|
52
|
+
def test_default_view_context_unique_per_presenter
|
53
|
+
refute_equal present(User.new).view_context,
|
54
|
+
present(User.new).view_context
|
55
|
+
end
|
56
|
+
|
52
57
|
def test_method_missing_delegation
|
53
58
|
assert_equal "Foo Bar", present(User.new).name
|
54
59
|
assert_equal "Foo", present(User.new).first_name
|
@@ -94,14 +99,18 @@ module Oprah
|
|
94
99
|
refute_equal user_presenter, project_presenter
|
95
100
|
end
|
96
101
|
|
97
|
-
|
102
|
+
def test_inspect
|
103
|
+
user = User.new
|
104
|
+
presenter = present(user)
|
98
105
|
|
99
|
-
|
100
|
-
Oprah.present_many(*args, &block)
|
106
|
+
assert_equal user.inspect, presenter.inspect
|
101
107
|
end
|
102
108
|
|
103
|
-
def
|
104
|
-
|
109
|
+
def test_to_s
|
110
|
+
user = User.new
|
111
|
+
presenter = present(user)
|
112
|
+
|
113
|
+
assert_equal user.to_s, presenter.to_s
|
105
114
|
end
|
106
115
|
end
|
107
116
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: oprah
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tobias Svensson
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -128,6 +128,7 @@ files:
|
|
128
128
|
- lib/oprah/controller_helpers.rb
|
129
129
|
- lib/oprah/presenter.rb
|
130
130
|
- lib/oprah/railtie.rb
|
131
|
+
- lib/oprah/test_helpers.rb
|
131
132
|
- lib/oprah/version.rb
|
132
133
|
- oprah.gemspec
|
133
134
|
- tasks/bundler.rb
|