active_decorator 0.5.1 → 0.5.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/active_decorator/decorator.rb +1 -1
- data/lib/active_decorator/version.rb +1 -1
- data/spec/fake_app/fake_app.rb +31 -0
- data/spec/features/controller_ivar_spec.rb +6 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a70c9cac44bcc2335cf9a3ce46f611bd7e13e59c
|
4
|
+
data.tar.gz: 1138c4793b86837ab88baa90119d41e88c26385c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 8c248e0ec8f5891d606a3d1f353263514b36f856d0f9d6aa605e7a984b4027f60044a03f0ec83f5655f5b9958a9338d69fc556d82bf6233e72daafcfd65d6a3d
|
7
|
+
data.tar.gz: 574698bc3d3f7f10deeb73ee1e5be0baa8edc52e5a0b6a7d70d4b99a80186cb010ef7bd3a19493cbaeb1234e35065b8aaf8a2bef7c7996637308adf30846fbd2
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# ActiveDecorator
|
1
|
+
# ActiveDecorator [](https://travis-ci.org/amatsuda/active_decorator) [](https://codeclimate.com/github/amatsuda/active_decorator)
|
2
2
|
|
3
3
|
A simple and Rubyish view helper for Rails 3 and Rails 4. Keep your helpers and views Object-Oriented!
|
4
4
|
|
@@ -18,7 +18,7 @@ module ActiveDecorator
|
|
18
18
|
decorate r
|
19
19
|
end
|
20
20
|
elsif defined?(ActiveRecord) && obj.is_a?(ActiveRecord::Relation) && !obj.respond_to?(:to_a_with_decorator)
|
21
|
-
class
|
21
|
+
obj.class.class_eval do
|
22
22
|
def to_a_with_decorator
|
23
23
|
to_a_without_decorator.tap do |arr|
|
24
24
|
ActiveDecorator::Decorator.instance.decorate arr
|
data/spec/fake_app/fake_app.rb
CHANGED
@@ -92,6 +92,8 @@ class AuthorsController < ApplicationController
|
|
92
92
|
# ActiveRecord 3.x
|
93
93
|
if params[:variable_type] == 'array'
|
94
94
|
@authors = Author.all
|
95
|
+
elsif params[:variable_type] == 'proxy'
|
96
|
+
@authors = RelationProxy.new(Author.scoped)
|
95
97
|
else
|
96
98
|
@authors = Author.scoped
|
97
99
|
end
|
@@ -99,6 +101,8 @@ class AuthorsController < ApplicationController
|
|
99
101
|
# ActiveRecord 4.x
|
100
102
|
if params[:variable_type] == 'array'
|
101
103
|
@authors = Author.all.to_a
|
104
|
+
elsif params[:variable_type] == 'proxy'
|
105
|
+
@authors = RelationProxy.new(Author.all)
|
102
106
|
else
|
103
107
|
@authors = Author.all
|
104
108
|
end
|
@@ -160,3 +164,30 @@ class CreateAllTables < ActiveRecord::Migration
|
|
160
164
|
create_table(:movies) {|t| t.string :name}
|
161
165
|
end
|
162
166
|
end
|
167
|
+
|
168
|
+
# Proxy for ActiveRecord::Relation
|
169
|
+
if RUBY_VERSION >= '1.9.0'
|
170
|
+
class RelationProxy < BasicObject
|
171
|
+
attr_accessor :ar_relation
|
172
|
+
|
173
|
+
def initialize(ar_relation)
|
174
|
+
@ar_relation = ar_relation
|
175
|
+
end
|
176
|
+
|
177
|
+
def method_missing(method, *args, &block)
|
178
|
+
@ar_relation.public_send(method, *args, &block)
|
179
|
+
end
|
180
|
+
end
|
181
|
+
else
|
182
|
+
class RelationProxy < Object
|
183
|
+
attr_accessor :ar_relation
|
184
|
+
|
185
|
+
def initialize(ar_relation)
|
186
|
+
@ar_relation = ar_relation
|
187
|
+
end
|
188
|
+
|
189
|
+
def method_missing(method, *args, &block)
|
190
|
+
@ar_relation.send(method, *args, &block)
|
191
|
+
end
|
192
|
+
end
|
193
|
+
end
|
@@ -30,6 +30,12 @@ feature 'decorating controller ivar' do
|
|
30
30
|
page.should have_content 'takahashim'.reverse
|
31
31
|
end
|
32
32
|
|
33
|
+
scenario "decorating models' proxy object in ivar" do
|
34
|
+
visit '/authors?variable_type=proxy'
|
35
|
+
page.should have_content 'takahashim'
|
36
|
+
page.should have_content 'takahashim'.reverse
|
37
|
+
end
|
38
|
+
|
33
39
|
scenario 'decorating model association proxy in ivar' do
|
34
40
|
visit "/authors/#{@matz.id}/books"
|
35
41
|
page.should have_content 'the world of code'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_decorator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.5.
|
4
|
+
version: 0.5.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Akira Matsuda
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-
|
11
|
+
date: 2015-05-28 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: A simple and Rubyish view helper for Rails 3
|
14
14
|
email:
|