activeadmin-poro-decorator 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +4 -0
- data/Gemfile.lock +41 -35
- data/README.md +13 -5
- data/Rakefile +3 -0
- data/lib/activeadmin-poro-decorator.rb +36 -15
- data/lib/activeadmin-poro-decorator/comment.rb +15 -0
- data/lib/activeadmin-poro-decorator/config.rb +5 -1
- data/lib/activeadmin-poro-decorator/version.rb +1 -1
- data/spec/integration/article_presenter_spec.rb +11 -0
- data/spec/support/dummy/app/presenters/article_presenter.rb +0 -13
- data/spec/support/dummy/config/activeadmin-poro-decorator.yml +2 -0
- metadata +8 -3
- data/lib/activeadmin-poro-decorator/activeadmin_comment.rb +0 -9
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7e9f07ed03e9c43c64bb5f99cced2353e68f123e
|
4
|
+
data.tar.gz: 82a8836d3d5d0e1fcc0329d44af87c74effb17be
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c6952ebdb187fd994eb6b5c0d7422e44d2671ccb5c8035786d571565711790bcce34adee7d903022847c57c069629bfb35a7c84624f8bf3e7ca672a0bc6766fd
|
7
|
+
data.tar.gz: a0adceaa7e05b0d6d27ee7f1c687940d9f8010e3996270710941a9cce90ad3345ce4dcbc7c4eb27ef0bc88d0cd80610a487b7ff75cf9737a5819143687c7141e
|
data/.travis.yml
ADDED
data/Gemfile.lock
CHANGED
@@ -1,68 +1,73 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
activeadmin-poro-decorator (0.
|
4
|
+
activeadmin-poro-decorator (0.2.0)
|
5
5
|
rails (>= 4.0.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
actionmailer (4.
|
11
|
-
actionpack (= 4.
|
10
|
+
actionmailer (4.1.8)
|
11
|
+
actionpack (= 4.1.8)
|
12
|
+
actionview (= 4.1.8)
|
12
13
|
mail (~> 2.5, >= 2.5.4)
|
13
|
-
actionpack (4.
|
14
|
-
|
15
|
-
|
16
|
-
erubis (~> 2.7.0)
|
14
|
+
actionpack (4.1.8)
|
15
|
+
actionview (= 4.1.8)
|
16
|
+
activesupport (= 4.1.8)
|
17
17
|
rack (~> 1.5.2)
|
18
18
|
rack-test (~> 0.6.2)
|
19
|
-
|
20
|
-
activesupport (= 4.
|
21
|
-
builder (~> 3.1
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
19
|
+
actionview (4.1.8)
|
20
|
+
activesupport (= 4.1.8)
|
21
|
+
builder (~> 3.1)
|
22
|
+
erubis (~> 2.7.0)
|
23
|
+
activemodel (4.1.8)
|
24
|
+
activesupport (= 4.1.8)
|
25
|
+
builder (~> 3.1)
|
26
|
+
activerecord (4.1.8)
|
27
|
+
activemodel (= 4.1.8)
|
28
|
+
activesupport (= 4.1.8)
|
29
|
+
arel (~> 5.0.0)
|
30
|
+
activesupport (4.1.8)
|
29
31
|
i18n (~> 0.6, >= 0.6.9)
|
30
|
-
|
31
|
-
|
32
|
+
json (~> 1.7, >= 1.7.7)
|
33
|
+
minitest (~> 5.1)
|
32
34
|
thread_safe (~> 0.1)
|
33
|
-
tzinfo (~>
|
34
|
-
arel (
|
35
|
-
builder (3.
|
35
|
+
tzinfo (~> 1.1)
|
36
|
+
arel (5.0.1.20140414130214)
|
37
|
+
builder (3.2.2)
|
36
38
|
coderay (1.1.0)
|
37
39
|
database_cleaner (0.9.1)
|
38
40
|
diff-lcs (1.2.5)
|
39
41
|
erubis (2.7.0)
|
40
42
|
hike (1.2.3)
|
41
43
|
i18n (0.7.0)
|
44
|
+
json (1.8.2)
|
42
45
|
mail (2.6.3)
|
43
46
|
mime-types (>= 1.16, < 3)
|
44
47
|
method_source (0.8.2)
|
45
48
|
mime-types (2.4.3)
|
46
|
-
minitest (
|
49
|
+
minitest (5.5.1)
|
47
50
|
multi_json (1.10.1)
|
48
51
|
pry (0.10.1)
|
49
52
|
coderay (~> 1.1.0)
|
50
53
|
method_source (~> 0.8.1)
|
51
54
|
slop (~> 3.4)
|
52
55
|
rack (1.5.2)
|
53
|
-
rack-test (0.6.
|
56
|
+
rack-test (0.6.3)
|
54
57
|
rack (>= 1.0)
|
55
|
-
rails (4.
|
56
|
-
actionmailer (= 4.
|
57
|
-
actionpack (= 4.
|
58
|
-
|
59
|
-
|
58
|
+
rails (4.1.8)
|
59
|
+
actionmailer (= 4.1.8)
|
60
|
+
actionpack (= 4.1.8)
|
61
|
+
actionview (= 4.1.8)
|
62
|
+
activemodel (= 4.1.8)
|
63
|
+
activerecord (= 4.1.8)
|
64
|
+
activesupport (= 4.1.8)
|
60
65
|
bundler (>= 1.3.0, < 2.0)
|
61
|
-
railties (= 4.
|
66
|
+
railties (= 4.1.8)
|
62
67
|
sprockets-rails (~> 2.0)
|
63
|
-
railties (4.
|
64
|
-
actionpack (= 4.
|
65
|
-
activesupport (= 4.
|
68
|
+
railties (4.1.8)
|
69
|
+
actionpack (= 4.1.8)
|
70
|
+
activesupport (= 4.1.8)
|
66
71
|
rake (>= 0.8.7)
|
67
72
|
thor (>= 0.18.1, < 2.0)
|
68
73
|
rake (10.3.2)
|
@@ -84,7 +89,7 @@ GEM
|
|
84
89
|
multi_json (~> 1.0)
|
85
90
|
rack (~> 1.0)
|
86
91
|
tilt (~> 1.1, != 1.3.0)
|
87
|
-
sprockets-rails (2.2.
|
92
|
+
sprockets-rails (2.2.4)
|
88
93
|
actionpack (>= 3.0)
|
89
94
|
activesupport (>= 3.0)
|
90
95
|
sprockets (>= 2.8, < 4.0)
|
@@ -92,7 +97,8 @@ GEM
|
|
92
97
|
thor (0.19.1)
|
93
98
|
thread_safe (0.3.4)
|
94
99
|
tilt (1.4.1)
|
95
|
-
tzinfo (
|
100
|
+
tzinfo (1.2.2)
|
101
|
+
thread_safe (~> 0.1)
|
96
102
|
|
97
103
|
PLATFORMS
|
98
104
|
ruby
|
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# Activeadmin Poro Decorator
|
2
2
|
|
3
|
+
![](https://travis-ci.org/kiote/activeadmin-poro-decorator.svg?branch=master)
|
4
|
+
|
3
5
|
Alternative for draper, if you need decorators at ActiveAdmin (and Rails).
|
4
6
|
Active Admin uses the Draper gem for [decorators](http://activeadmin.info/docs/11-decorators.html), but sometimes you don't need that.
|
5
7
|
For reasons you could read this article: http://thepugautomatic.com/2014/03/draper.
|
@@ -51,12 +53,13 @@ end
|
|
51
53
|
class PostDecorator < DelegateClass(Post)
|
52
54
|
include ActiveadminPoroDecorator
|
53
55
|
|
54
|
-
|
55
|
-
|
56
|
-
|
56
|
+
class << self
|
57
|
+
delegate :all, :arel_table, :find_by_sql, :columns, :connection,\
|
58
|
+
:unscoped, :table_name, :primary_key, to: Post
|
57
59
|
|
58
|
-
|
59
|
-
|
60
|
+
def model_name
|
61
|
+
ActiveModel::Name.new Post
|
62
|
+
end
|
60
63
|
end
|
61
64
|
|
62
65
|
def hello
|
@@ -71,6 +74,11 @@ end
|
|
71
74
|
|
72
75
|
For more examples have a look to [sample app](https://github.com/kiote/aa_plus_poro)
|
73
76
|
|
77
|
+
## Credits
|
78
|
+
![](http://d3a5orex94acl6.cloudfront.net/assets/logo-sprites-a6de3b3521c14ee436ca3207d83cdf90.png)
|
79
|
+
|
80
|
+
Activeadmin-poro-decorator is created with support of [Legelisten.no](http://www.legelisten.no/om-oss)
|
81
|
+
|
74
82
|
## Contributing
|
75
83
|
|
76
84
|
1. Fork it ( https://github.com/[my-github-username]/activeadmin-poro-decorator/fork )
|
data/Rakefile
CHANGED
@@ -1,17 +1,7 @@
|
|
1
1
|
require 'activeadmin-poro-decorator/version'
|
2
2
|
require 'activeadmin-poro-decorator/config'
|
3
|
-
require 'activeadmin-poro-decorator/railtie'
|
4
|
-
|
5
|
-
# monkey patch to make ActiveAdmin::Comment works with activeadmin_poro_decorator
|
6
|
-
module ActiveAdmin
|
7
|
-
class Comment < ActiveRecord::Base
|
8
|
-
# @returns [String] The name of the record to use for the polymorphic relationship
|
9
|
-
def self.resource_type(resource)
|
10
|
-
return resource.type if resource.respond_to?(:type)
|
11
|
-
ResourceController::Decorators.undecorate(resource).class.name.to_s
|
12
|
-
end
|
13
|
-
end
|
14
|
-
end
|
3
|
+
require 'activeadmin-poro-decorator/railtie'
|
4
|
+
require 'activeadmin-poro-decorator/comment'
|
15
5
|
|
16
6
|
module ActiveadminPoroDecorator
|
17
7
|
extend ActiveSupport::Concern
|
@@ -24,14 +14,44 @@ module ActiveadminPoroDecorator
|
|
24
14
|
delegate :url_helpers, to: "Rails.application.routes"
|
25
15
|
end
|
26
16
|
|
17
|
+
def decorated?
|
18
|
+
true
|
19
|
+
end
|
20
|
+
|
21
|
+
def model
|
22
|
+
self.class.model_name_const
|
23
|
+
end
|
24
|
+
|
27
25
|
module ClassMethods
|
26
|
+
def model_name_const
|
27
|
+
config = Config::Reader.new
|
28
|
+
self.to_s.gsub(config.param('modelname'), '').constantize
|
29
|
+
end
|
30
|
+
|
31
|
+
# obtain original model name
|
32
|
+
# ArticlePresenter -> Article
|
33
|
+
def model_name
|
34
|
+
ActiveModel::Name.new model_name_const.to_s.constantize
|
35
|
+
end
|
36
|
+
|
37
|
+
# we need to delegate all this methods to support active record interface
|
38
|
+
[:all, :arel_table, :find_by_sql, :columns, :connection,\
|
39
|
+
:unscoped, :table_name, :primary_key].each do |delegated_method|
|
40
|
+
define_method(delegated_method) do |*args|
|
41
|
+
model_name_const.send(delegated_method, *args)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def build_default_scope
|
46
|
+
model_name_const.send(:build_default_scope)
|
47
|
+
end
|
48
|
+
|
28
49
|
def decorate(*args)
|
29
50
|
collection_or_object = args[0]
|
30
51
|
if collection_or_object.respond_to?(:to_ary)
|
31
52
|
# assuming we have self.model_name method in decorator implementation
|
32
53
|
# suggested by @eyefodder
|
33
|
-
|
34
|
-
DecoratedEnumerableProxy.new(collection_or_object, class_name)
|
54
|
+
DecoratedEnumerableProxy.new(collection_or_object, model_name_const)
|
35
55
|
else
|
36
56
|
new(collection_or_object)
|
37
57
|
end
|
@@ -45,7 +65,8 @@ module ActiveadminPoroDecorator
|
|
45
65
|
class DecoratedEnumerableProxy < DelegateClass(ActiveRecord::Relation)
|
46
66
|
include Enumerable
|
47
67
|
|
48
|
-
delegate :as_json, :collect, :map, :each, :[], :all?, :include?,
|
68
|
+
delegate :as_json, :collect, :map, :each, :[], :all?, :include?, \
|
69
|
+
:first, :last, :shift, to: :decorated_collection
|
49
70
|
|
50
71
|
def initialize(collection, class_name)
|
51
72
|
super(collection)
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module ActiveAdmin
|
2
|
+
class Comment < ActiveRecord::Base
|
3
|
+
# @return [String] The name of the record to use for the polymorphic relationship
|
4
|
+
def self.resource_type(resource)
|
5
|
+
# original method has
|
6
|
+
# ResourceController::Decorators.undecorate(resource).class.base_class.name.to_s
|
7
|
+
# here, but somehow it didn't work
|
8
|
+
undecorated = ResourceController::Decorators.undecorate(resource)
|
9
|
+
if undecorated.to_s.include?(':')
|
10
|
+
undecorated = undecorated.class.to_s
|
11
|
+
end
|
12
|
+
undecorated.to_s
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -4,7 +4,11 @@ module ActiveadminPoroDecorator
|
|
4
4
|
module Config
|
5
5
|
class Reader
|
6
6
|
def initialize
|
7
|
-
@config =
|
7
|
+
@config = if ENV['RAILS_ENV'] == 'test'
|
8
|
+
YAML.load_file('spec/support/dummy/config/activeadmin-poro-decorator.yml')
|
9
|
+
else
|
10
|
+
YAML.load_file('config/activeadmin-poro-decorator.yml')
|
11
|
+
end
|
8
12
|
end
|
9
13
|
|
10
14
|
def param(name)
|
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe 'ArticlePresenter' do
|
4
|
+
it 'delegates :all to Article' do
|
5
|
+
expect(ArticlePresenter.all.class).to eq(Article::ActiveRecord_Relation)
|
6
|
+
end
|
7
|
+
|
8
|
+
it 'builds default scope' do
|
9
|
+
expect(ArticlePresenter.build_default_scope).to eq nil
|
10
|
+
end
|
11
|
+
end
|
@@ -2,19 +2,6 @@
|
|
2
2
|
class ArticlePresenter < DelegateClass(Article)
|
3
3
|
include ActiveadminPoroDecorator
|
4
4
|
|
5
|
-
class << self
|
6
|
-
delegate :all, :arel_table, :find_by_sql, :columns, :connection,\
|
7
|
-
:unscoped, :table_name, :primary_key, to: Article
|
8
|
-
|
9
|
-
def model_name
|
10
|
-
ActiveModel::Name.new Article
|
11
|
-
end
|
12
|
-
|
13
|
-
def build_default_scope
|
14
|
-
Article.send(:build_default_scope)
|
15
|
-
end
|
16
|
-
end
|
17
|
-
|
18
5
|
def hello
|
19
6
|
"Hello, #{title}"
|
20
7
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: activeadmin-poro-decorator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Krivich Ekaterina
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-01
|
11
|
+
date: 2015-02-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -117,6 +117,7 @@ extensions: []
|
|
117
117
|
extra_rdoc_files: []
|
118
118
|
files:
|
119
119
|
- ".gitignore"
|
120
|
+
- ".travis.yml"
|
120
121
|
- Gemfile
|
121
122
|
- Gemfile.lock
|
122
123
|
- LICENSE.txt
|
@@ -125,11 +126,12 @@ files:
|
|
125
126
|
- activeadmin-poro-decorator.gemspec
|
126
127
|
- activeadmin-poro-decorator.yml.example
|
127
128
|
- lib/activeadmin-poro-decorator.rb
|
128
|
-
- lib/activeadmin-poro-decorator/
|
129
|
+
- lib/activeadmin-poro-decorator/comment.rb
|
129
130
|
- lib/activeadmin-poro-decorator/config.rb
|
130
131
|
- lib/activeadmin-poro-decorator/railtie.rb
|
131
132
|
- lib/activeadmin-poro-decorator/version.rb
|
132
133
|
- lib/tasks/copy_config.rake
|
134
|
+
- spec/integration/article_presenter_spec.rb
|
133
135
|
- spec/integration/decorate_spec.rb
|
134
136
|
- spec/spec_helper.rb
|
135
137
|
- spec/support/dummy/Rakefile
|
@@ -139,6 +141,7 @@ files:
|
|
139
141
|
- spec/support/dummy/bin/rails
|
140
142
|
- spec/support/dummy/bin/rake
|
141
143
|
- spec/support/dummy/config.ru
|
144
|
+
- spec/support/dummy/config/activeadmin-poro-decorator.yml
|
142
145
|
- spec/support/dummy/config/application.rb
|
143
146
|
- spec/support/dummy/config/boot.rb
|
144
147
|
- spec/support/dummy/config/database.yml
|
@@ -171,6 +174,7 @@ signing_key:
|
|
171
174
|
specification_version: 4
|
172
175
|
summary: Plain Old Ruby Objects as Decorators for Active Admin
|
173
176
|
test_files:
|
177
|
+
- spec/integration/article_presenter_spec.rb
|
174
178
|
- spec/integration/decorate_spec.rb
|
175
179
|
- spec/spec_helper.rb
|
176
180
|
- spec/support/dummy/Rakefile
|
@@ -180,6 +184,7 @@ test_files:
|
|
180
184
|
- spec/support/dummy/bin/rails
|
181
185
|
- spec/support/dummy/bin/rake
|
182
186
|
- spec/support/dummy/config.ru
|
187
|
+
- spec/support/dummy/config/activeadmin-poro-decorator.yml
|
183
188
|
- spec/support/dummy/config/application.rb
|
184
189
|
- spec/support/dummy/config/boot.rb
|
185
190
|
- spec/support/dummy/config/database.yml
|
@@ -1,9 +0,0 @@
|
|
1
|
-
module ActiveAdmin
|
2
|
-
class Comment < ActiveRecord::Base
|
3
|
-
# @returns [String] The name of the record to use for the polymorphic relationship
|
4
|
-
def self.resource_type(resource)
|
5
|
-
return resource.type if resource.respond_to?(:type)
|
6
|
-
ResourceController::Decorators.undecorate(resource).class.name.to_s
|
7
|
-
end
|
8
|
-
end
|
9
|
-
end
|