resubject 0.1.0 → 0.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,3 +1,10 @@
1
+ # 0.1.1
2
+
3
+ - bugfixes
4
+ - [#2] presents' implicit presenter class blows up with nil association
5
+ - enhancements
6
+ - Calls ActiveSupport.run_load_hooks when gem is loaded
7
+
1
8
  # 0.1.0
2
9
 
3
10
  - enhancements
data/README.md CHANGED
@@ -10,7 +10,7 @@ Uber simple presenters using Ruby's SimpleDelegator.
10
10
  Add this line to your application's Gemfile:
11
11
 
12
12
  ```ruby
13
- gem 'resubject', '~> 0.1.0'
13
+ gem 'resubject', '~> 0.1.1'
14
14
  ```
15
15
 
16
16
  And then execute:
@@ -113,7 +113,7 @@ class BoxesController < ActionController::Base
113
113
  end
114
114
  ```
115
115
 
116
- The `#present` mehtod will automatically identify the presenter class by the object's class name. If you want to customize the class:
116
+ The `#present` method will automatically identify the presenter class by the object's class name. If you want to customize the class:
117
117
 
118
118
  ```ruby
119
119
  def index
@@ -3,3 +3,5 @@ require 'resubject/naming'
3
3
  require 'resubject/presenter'
4
4
  require 'resubject/builder'
5
5
  require 'resubject/rails' if defined? Rails
6
+
7
+ ActiveSupport.run_load_hooks(:resubject, Resubject::Presenter)
@@ -56,9 +56,16 @@ module Resubject
56
56
  # Builder.present_one box, context, CustomPresenter # => <CustomPresenter>
57
57
  # Builder.present_one box, context, OnePresenter, TwoPresenter # => <TwoPresenter<OnePresenter>>
58
58
  #
59
+ # @example Skips nil classes
60
+ #
61
+ # Builder.present_one nil
62
+ # # => nil
63
+ #
59
64
  # @see .present
60
65
  #
61
66
  def self.present_one(object, template, *presenters)
67
+ return unless object
68
+
62
69
  presenters = [Naming.presenter_for(object)] unless presenters.any?
63
70
 
64
71
  unless presenters.all? { |p| p.is_a?(Class) && p.ancestors.include?(Resubject::Presenter) }
@@ -70,6 +70,12 @@ module Resubject
70
70
  #
71
71
  # BoxPresenter.new(box).name # => <NamePresenter>
72
72
  #
73
+ # @example When the parent method is nil, it returns nil
74
+ #
75
+ # box = BoxPresenter.new Box.new(name: nil)
76
+ # box.name
77
+ # # => nil
78
+ #
73
79
  def self.presents(attribute, *presenters)
74
80
  define_method attribute do
75
81
  present to_model.send(attribute), *presenters
@@ -1,3 +1,3 @@
1
1
  module Resubject
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -10,6 +10,11 @@ describe Resubject::Builder do
10
10
  end
11
11
 
12
12
  describe '.present_one' do
13
+ it 'does not attempt to present nil' do
14
+ presented = Resubject::Builder.present_one nil, template
15
+ expect(presented).to be_nil
16
+ end
17
+
13
18
  it 'presents the object with related class' do
14
19
  presented = Resubject::Builder.present_one Box.new, template
15
20
  expect(presented).to be_a BoxPresenter
@@ -54,6 +54,12 @@ describe Resubject::Presenter do
54
54
  expect(presenter.new(box).item).to be_a ItemPresenter
55
55
  end
56
56
 
57
+ it 'does not attempt to find a class from nil' do
58
+ box = stub :box, :item => nil
59
+
60
+ expect(presenter.new(box).item).to be_nil
61
+ end
62
+
57
63
  it 'presents the attributes with custom presenter' do
58
64
  box = stub :box, :other_item => stub
59
65
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: resubject
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -10,72 +10,72 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-01-13 00:00:00.000000000 Z
13
+ date: 2013-01-16 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
- type: :runtime
17
- version_requirements: !ruby/object:Gem::Requirement
18
- none: false
19
- requirements:
20
- - - ~>
21
- - !ruby/object:Gem::Version
22
- version: '3.2'
23
16
  name: activesupport
24
17
  prerelease: false
25
18
  requirement: !ruby/object:Gem::Requirement
26
- none: false
27
19
  requirements:
28
20
  - - ~>
29
21
  - !ruby/object:Gem::Version
30
22
  version: '3.2'
31
- - !ruby/object:Gem::Dependency
32
- type: :development
33
- version_requirements: !ruby/object:Gem::Requirement
34
23
  none: false
24
+ type: :runtime
25
+ version_requirements: !ruby/object:Gem::Requirement
35
26
  requirements:
36
- - - ! '>='
27
+ - - ~>
37
28
  - !ruby/object:Gem::Version
38
- version: '0'
29
+ version: '3.2'
30
+ none: false
31
+ - !ruby/object:Gem::Dependency
39
32
  name: rake
40
33
  prerelease: false
41
34
  requirement: !ruby/object:Gem::Requirement
42
- none: false
43
35
  requirements:
44
36
  - - ! '>='
45
37
  - !ruby/object:Gem::Version
46
38
  version: '0'
47
- - !ruby/object:Gem::Dependency
39
+ none: false
48
40
  type: :development
49
41
  version_requirements: !ruby/object:Gem::Requirement
50
- none: false
51
42
  requirements:
52
- - - ~>
43
+ - - ! '>='
53
44
  - !ruby/object:Gem::Version
54
- version: 2.12.0
45
+ version: '0'
46
+ none: false
47
+ - !ruby/object:Gem::Dependency
55
48
  name: rspec
56
49
  prerelease: false
57
50
  requirement: !ruby/object:Gem::Requirement
58
- none: false
59
51
  requirements:
60
52
  - - ~>
61
53
  - !ruby/object:Gem::Version
62
54
  version: 2.12.0
63
- - !ruby/object:Gem::Dependency
55
+ none: false
64
56
  type: :development
65
57
  version_requirements: !ruby/object:Gem::Requirement
66
- none: false
67
58
  requirements:
68
59
  - - ~>
69
60
  - !ruby/object:Gem::Version
70
- version: 0.8.3
61
+ version: 2.12.0
62
+ none: false
63
+ - !ruby/object:Gem::Dependency
71
64
  name: yard
72
65
  prerelease: false
73
66
  requirement: !ruby/object:Gem::Requirement
67
+ requirements:
68
+ - - ~>
69
+ - !ruby/object:Gem::Version
70
+ version: 0.8.3
74
71
  none: false
72
+ type: :development
73
+ version_requirements: !ruby/object:Gem::Requirement
75
74
  requirements:
76
75
  - - ~>
77
76
  - !ruby/object:Gem::Version
78
77
  version: 0.8.3
78
+ none: false
79
79
  description: Uber simple presenters
80
80
  email:
81
81
  - felipe@applicake.com
@@ -117,23 +117,17 @@ rdoc_options: []
117
117
  require_paths:
118
118
  - lib
119
119
  required_ruby_version: !ruby/object:Gem::Requirement
120
- none: false
121
120
  requirements:
122
121
  - - ! '>='
123
122
  - !ruby/object:Gem::Version
124
- segments:
125
- - 0
126
123
  version: '0'
127
- hash: 1859410703920262887
128
- required_rubygems_version: !ruby/object:Gem::Requirement
129
124
  none: false
125
+ required_rubygems_version: !ruby/object:Gem::Requirement
130
126
  requirements:
131
127
  - - ! '>='
132
128
  - !ruby/object:Gem::Version
133
- segments:
134
- - 0
135
129
  version: '0'
136
- hash: 1859410703920262887
130
+ none: false
137
131
  requirements: []
138
132
  rubyforge_project:
139
133
  rubygems_version: 1.8.24