active_decorator 0.5.1 → 0.5.2

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: 7ec9e246de4d4a482aec613131463383e11c6b65
4
- data.tar.gz: f3c66bc4714c7fe4f2332d82b3504b310dfdf8a6
3
+ metadata.gz: a70c9cac44bcc2335cf9a3ce46f611bd7e13e59c
4
+ data.tar.gz: 1138c4793b86837ab88baa90119d41e88c26385c
5
5
  SHA512:
6
- metadata.gz: b1a8711efe0ae4efe92b48a362f7a3d39d79ff734d16fa587817a7d53056aeafae90281669572a872b25f97464c4835d781fd5ba70e1c473868b224218048ffc
7
- data.tar.gz: 803072777c134ff503868e0f7909f866ddd87fad2e58151fcc65522d5a91e9372d543db71f496b7d2bf6117cd32279866013d47643ba3b9ac4a1decf67730bbc
6
+ metadata.gz: 8c248e0ec8f5891d606a3d1f353263514b36f856d0f9d6aa605e7a984b4027f60044a03f0ec83f5655f5b9958a9338d69fc556d82bf6233e72daafcfd65d6a3d
7
+ data.tar.gz: 574698bc3d3f7f10deeb73ee1e5be0baa8edc52e5a0b6a7d70d4b99a80186cb010ef7bd3a19493cbaeb1234e35065b8aaf8a2bef7c7996637308adf30846fbd2
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # ActiveDecorator
1
+ # ActiveDecorator [![Build Status](https://travis-ci.org/amatsuda/active_decorator.svg?branch=master)](https://travis-ci.org/amatsuda/active_decorator) [![Code Climate](https://codeclimate.com/github/amatsuda/active_decorator/badges/gpa.svg)](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 << obj
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
@@ -1,3 +1,3 @@
1
1
  module ActiveDecorator
2
- VERSION = '0.5.1'
2
+ VERSION = '0.5.2'
3
3
  end
@@ -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.1
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-02-28 00:00:00.000000000 Z
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: