geckorate 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +22 -0
- data/README.md +15 -3
- data/lib/geckorate.rb +6 -3
- data/lib/geckorate/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc524377d735e5b78b0253e499c1f59b4c0f74e7127823408cf3fe94949202b7
|
4
|
+
data.tar.gz: 0a9d6083dca72be52d659f2e3c408bd44dc8efcc944b4a92ca1627fdb5a72bcb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: eba4d418daa842a83eed3d4dd9dda7abedeb458a8d25d7930a8748a05e1318f0bb7f4ce4cf10d908d93761e2493843f772ac967b5d31334609c53197967d2306
|
7
|
+
data.tar.gz: e4039af2d54cdb94abb210f59202f5230579bf98a1a726586721d12c5752d99052c72c0096128e9065c4b6cb31e37113c5b3a4bedab83efcc5c39cb61eff4206
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
geckorate (0.1.1)
|
5
|
+
|
6
|
+
GEM
|
7
|
+
remote: https://rubygems.org/
|
8
|
+
specs:
|
9
|
+
minitest (5.11.3)
|
10
|
+
rake (10.5.0)
|
11
|
+
|
12
|
+
PLATFORMS
|
13
|
+
ruby
|
14
|
+
|
15
|
+
DEPENDENCIES
|
16
|
+
bundler (~> 1.16)
|
17
|
+
geckorate!
|
18
|
+
minitest (~> 5.0)
|
19
|
+
rake (~> 10.0)
|
20
|
+
|
21
|
+
BUNDLED WITH
|
22
|
+
1.16.2
|
data/README.md
CHANGED
@@ -22,8 +22,20 @@ Or install it yourself as:
|
|
22
22
|
|
23
23
|
### A Rails example
|
24
24
|
|
25
|
-
|
25
|
+
First, you need to add `app/decorators` to your app load path:
|
26
|
+
```ruby
|
27
|
+
# config/application.rb
|
28
|
+
|
29
|
+
module MyApp
|
30
|
+
class Application < Rails::Application
|
31
|
+
...
|
32
|
+
config.autoload_paths << Rails.root.join('app/decorators')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
```
|
26
37
|
|
38
|
+
Now, define your decorator as such:
|
27
39
|
```ruby
|
28
40
|
# app/decorators/post_decorator.rb
|
29
41
|
|
@@ -32,12 +44,12 @@ class PostDecorator < Geckorate::Decorator
|
|
32
44
|
{
|
33
45
|
title: title,
|
34
46
|
username: user.name
|
35
|
-
}.
|
47
|
+
}.as_json
|
36
48
|
end
|
37
49
|
end
|
38
50
|
```
|
39
51
|
|
40
|
-
|
52
|
+
And initialize it in your controller and use it for your view:
|
41
53
|
```ruby
|
42
54
|
# app/controllers/posts_contrller.rb
|
43
55
|
|
data/lib/geckorate.rb
CHANGED
@@ -6,10 +6,13 @@ module Geckorate
|
|
6
6
|
|
7
7
|
class << self
|
8
8
|
def decorate_collection(collection)
|
9
|
+
return [] if collection.empty?
|
10
|
+
|
11
|
+
klass = collection.first.class
|
12
|
+
full_klass_name = klass.to_s.concat('Decorator')
|
13
|
+
decorator_klass = Class.const_get(full_klass_name)
|
14
|
+
|
9
15
|
collection.map do |item|
|
10
|
-
klass = item.class
|
11
|
-
full_klass_name = klass.to_s.concat('Decorator')
|
12
|
-
decorator_klass = Class.const_get(full_klass_name)
|
13
16
|
decorator_klass.new(item).decorate
|
14
17
|
end
|
15
18
|
end
|
data/lib/geckorate/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geckorate
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ahmed Saleh
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-
|
11
|
+
date: 2018-08-12 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -62,6 +62,7 @@ files:
|
|
62
62
|
- ".gitignore"
|
63
63
|
- ".travis.yml"
|
64
64
|
- Gemfile
|
65
|
+
- Gemfile.lock
|
65
66
|
- LICENSE.txt
|
66
67
|
- README.md
|
67
68
|
- Rakefile
|