geckorate 0.1.0 → 0.1.1

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 3b4a0eb4dd2abcd1c8e09b079521270efa61374f07bbacf748fff6b8b53a0efe
4
- data.tar.gz: 13240fe99a8bf10d132ff5c99053fe21e301a608559f5c074ab3a1538a258eb4
3
+ metadata.gz: fc524377d735e5b78b0253e499c1f59b4c0f74e7127823408cf3fe94949202b7
4
+ data.tar.gz: 0a9d6083dca72be52d659f2e3c408bd44dc8efcc944b4a92ca1627fdb5a72bcb
5
5
  SHA512:
6
- metadata.gz: 36631b16505625736a025546b8f6965c528a710f40be461b41627838eb97778bf2229ad50ca2ce8a94b6b3730fc83fad4062db808f8802f99644820609d32227
7
- data.tar.gz: adeeb69a7ab6c6c7d687b83aa4d67fa4bcda7e5e1bc22f758fbf6346dc6f0dac291bd617860294890b53611e7f4e7ba3b3f1ea0f23cc0b6a9086dce4ffbe100d
6
+ metadata.gz: eba4d418daa842a83eed3d4dd9dda7abedeb458a8d25d7930a8748a05e1318f0bb7f4ce4cf10d908d93761e2493843f772ac967b5d31334609c53197967d2306
7
+ data.tar.gz: e4039af2d54cdb94abb210f59202f5230579bf98a1a726586721d12c5752d99052c72c0096128e9065c4b6cb31e37113c5b3a4bedab83efcc5c39cb61eff4206
@@ -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
- Define your decorator as such:
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
- }.to_json
47
+ }.as_json
36
48
  end
37
49
  end
38
50
  ```
39
51
 
40
- and initialize it in your controller and use it for your view:
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
 
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Geckorate
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
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.0
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-06-22 00:00:00.000000000 Z
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