the_garage 2.0.3 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +29 -0
- data/lib/garage/config.rb +1 -1
- data/lib/garage/restful_actions.rb +18 -3
- data/lib/garage/strategy/access_token.rb +2 -1
- data/lib/garage/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e6f0a02d10dc0502a581d667dc02746962f7a23a
|
4
|
+
data.tar.gz: 7141e3b4235a0f2767e1d01635fff8bf58af542a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: cb32724f1086c7f9609624f40d1db6155e9202e79bf6eb22589d02cb2a48c2ae4c2298b95fbf68ff9b50676b555d34337196186f59f529285f577fcc9322f966
|
7
|
+
data.tar.gz: 2455ad6edb9abd271c9286a8a070d9beaca25e526ae5c2bc523c8f889cb422ddd6bd3e88e7a675514fb26d82dbfb0c03411383e10c1ab64ba6d31a33f9dc5056
|
data/README.md
CHANGED
@@ -26,6 +26,7 @@ In your Rails model class:
|
|
26
26
|
```ruby
|
27
27
|
class Employee < ActiveRecord::Base
|
28
28
|
include Garage::Representer
|
29
|
+
include Garage::Authorizable
|
29
30
|
|
30
31
|
belongs_to :division
|
31
32
|
has_many :projects
|
@@ -58,6 +59,34 @@ class EmployeesController < ApplicationController
|
|
58
59
|
end
|
59
60
|
```
|
60
61
|
|
62
|
+
## Create decorator for your AR models
|
63
|
+
With not small application, you may add a presentation layer to build API responses.
|
64
|
+
Define a decorator class with `Resource` suffix and define `#to_resource` in
|
65
|
+
your AR model.
|
66
|
+
|
67
|
+
```ruby
|
68
|
+
class User < ActiveRecord::Base
|
69
|
+
def to_resource
|
70
|
+
UserResource.new(self)
|
71
|
+
end
|
72
|
+
end
|
73
|
+
|
74
|
+
class UserResource
|
75
|
+
include Garage::Representer
|
76
|
+
include Garage::Authorizable
|
77
|
+
|
78
|
+
property :id
|
79
|
+
property :name
|
80
|
+
property :email
|
81
|
+
|
82
|
+
delegate :id, :name, :email, to: :@model
|
83
|
+
|
84
|
+
def initialize(model)
|
85
|
+
@model = model
|
86
|
+
end
|
87
|
+
end
|
88
|
+
```
|
89
|
+
|
61
90
|
## Advanced Configurations
|
62
91
|
|
63
92
|
In `config/initializers/garage.rb`:
|
data/lib/garage/config.rb
CHANGED
@@ -32,7 +32,22 @@ module Garage
|
|
32
32
|
end
|
33
33
|
|
34
34
|
def resource_class
|
35
|
-
@resource_class ||=
|
35
|
+
@resource_class ||= default_resource_class
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def default_resource_class
|
41
|
+
class_name = name.sub(/Controller\z/, '').demodulize.singularize
|
42
|
+
begin
|
43
|
+
return "#{class_name}Resource".constantize
|
44
|
+
rescue NameError
|
45
|
+
begin
|
46
|
+
return class_name.constantize
|
47
|
+
rescue NameError
|
48
|
+
raise "Garage needs `#{class_name}Resource` or `#{class_name}` for resource class of #{name} but neither was found. If you want use an alternative class for the resource class, specify the resource class by `.resource_class=` in your controller."
|
49
|
+
end
|
50
|
+
end
|
36
51
|
end
|
37
52
|
end
|
38
53
|
|
@@ -45,7 +60,7 @@ module Garage
|
|
45
60
|
|
46
61
|
# Public: Get the resource
|
47
62
|
# Renders `@resource` with options specified with `respond_with_resource_options`
|
48
|
-
#
|
63
|
+
# Requires `:read` permission on `@resource`
|
49
64
|
def show
|
50
65
|
respond_with @resource, respond_with_resource_options
|
51
66
|
end
|
@@ -173,7 +188,7 @@ module Garage
|
|
173
188
|
elsif @resources
|
174
189
|
MetaResource.new(self.class.resource_class)
|
175
190
|
else
|
176
|
-
@resource
|
191
|
+
Garage.configuration.cast_resource.call(@resource)
|
177
192
|
end
|
178
193
|
end
|
179
194
|
|
@@ -1,9 +1,10 @@
|
|
1
1
|
module Garage
|
2
2
|
module Strategy
|
3
3
|
class AccessToken
|
4
|
-
attr_reader :scope, :token, :token_type
|
4
|
+
attr_reader :scope, :token, :token_type, :raw_response
|
5
5
|
|
6
6
|
def initialize(attrs)
|
7
|
+
@raw_response = attrs
|
7
8
|
@scope, @token, @token_type = attrs[:scope], attrs[:token], attrs[:token_type]
|
8
9
|
@application_id, @resource_owner_id = attrs[:application_id], attrs[:resource_owner_id]
|
9
10
|
@expired_at, @revoked_at = attrs[:expired_at], attrs[:revoked_at]
|
data/lib/garage/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: the_garage
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0
|
4
|
+
version: 2.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tatsuhiko Miyagawa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-05-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -269,7 +269,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
269
269
|
version: '0'
|
270
270
|
requirements: []
|
271
271
|
rubyforge_project:
|
272
|
-
rubygems_version: 2.
|
272
|
+
rubygems_version: 2.4.8
|
273
273
|
signing_key:
|
274
274
|
specification_version: 4
|
275
275
|
summary: Garage Platform Engine
|