the_garage 2.4.2 → 2.6.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/README.md +13 -1
- data/app/assets/javascripts/garage/docs/console.js.coffee +2 -10
- data/app/views/layouts/garage/application.html.haml +2 -2
- data/lib/garage/config.rb +5 -3
- data/lib/garage/docs/config.rb +12 -1
- data/lib/garage/hypermedia_responder.rb +3 -1
- data/lib/garage/paginating_responder.rb +1 -1
- data/lib/garage/representer.rb +3 -1
- data/lib/garage/resource_casting_responder.rb +1 -1
- data/lib/garage/strategy/auth_server.rb +2 -0
- data/lib/garage/tracer.rb +2 -0
- data/lib/garage/version.rb +1 -1
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 22866c2b96913a0808dc58ee3c6616a1fa190bdd632d5cbcf23ba0781b5012fc
|
4
|
+
data.tar.gz: c05332be7ec143fe6aec9b52d9e982be382e45db5c1433c67127a69c692add79
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9525bff41a05c514895634c65db08f5644b7c32e2e812f7935df9c7cb68b384d96e21e4bf8ccccc9dbc5561a85d889bd160ff679e9c5e2685a1b07f8c30ed874
|
7
|
+
data.tar.gz: dd942e114ef1fe840e0a145a3530dbe924970012d66fa7198dacb0409cc1447f36b6111bbb14fdde71ddee5341d76c8a87f4944e8ab3e7a8957ed8513043014a
|
data/README.md
CHANGED
@@ -52,7 +52,7 @@ In your controller classes:
|
|
52
52
|
```ruby
|
53
53
|
class ApplicationController < ActionController::Base
|
54
54
|
include Garage::ControllerHelper
|
55
|
-
|
55
|
+
|
56
56
|
# ...
|
57
57
|
end
|
58
58
|
|
@@ -65,6 +65,18 @@ class EmployeesController < ApplicationController
|
|
65
65
|
end
|
66
66
|
```
|
67
67
|
|
68
|
+
Resources are rendered with [respond_with (responders gem)](https://github.com/heartcombo/responders).
|
69
|
+
Additional options can be passed to respond_with by implementing `respond_with_resources_options` (index action)
|
70
|
+
and `respond_with_resource_options` (show, update destroy actions).
|
71
|
+
|
72
|
+
Available options
|
73
|
+
* `:paginate` - (Boolean) Enable pagination when `true`. Paginates with the `per_page` and `page` params
|
74
|
+
* `:per_page` - (Integer) value for default number of resources per page when paginating
|
75
|
+
* `:max_per_page` - (Integer) Maximum resources per page, irrespective of requested per_page
|
76
|
+
* `:hard_limit` - (Integer) Limit of retrievable records when paginating. Also hides total records.
|
77
|
+
* `:distinct_by` - (Symbol) Specify a property to count by for total page count
|
78
|
+
* `:to_resource_options` - (Hash) Options to pass as argument to `to_resource(options)`
|
79
|
+
|
68
80
|
## Create decorator for your AR models
|
69
81
|
With not small application, you may add a presentation layer to build API responses.
|
70
82
|
Define a decorator class with `Resource` suffix and define `#to_resource` in
|
@@ -9,14 +9,6 @@ jQuery ()->
|
|
9
9
|
$.colorbox.close()
|
10
10
|
ev.preventDefault()
|
11
11
|
|
12
|
-
buildAuthorizedUrl = (base, location, token) ->
|
13
|
-
url = base + location
|
14
|
-
if url.indexOf('?') > 0
|
15
|
-
url += '&'
|
16
|
-
else
|
17
|
-
url += '?'
|
18
|
-
url + 'access_token=' + token
|
19
|
-
|
20
12
|
addNewParamField = (container) ->
|
21
13
|
nextId = "parameter-" + $('.parameter', container).length
|
22
14
|
copy = $('.template .parameter').clone().attr('id', nextId)
|
@@ -52,11 +44,11 @@ jQuery ()->
|
|
52
44
|
$('#api-headers').text ''
|
53
45
|
$('#api-response').text ''
|
54
46
|
|
55
|
-
url = buildAuthorizedUrl $('#base').val(), $('#location').val(), $('#access_token').val()
|
56
47
|
console.log buildData($('.parameters'))
|
57
48
|
$.ajax
|
58
49
|
type: $('#method').val(),
|
59
|
-
url:
|
50
|
+
url: $('#base').val() + $('#location').val(),
|
51
|
+
headers: {'Authorization': 'Bearer ' + $('#access_token').val()},
|
60
52
|
cache: false,
|
61
53
|
data: buildData($('.parameters')),
|
62
54
|
dataType: 'json',
|
@@ -6,7 +6,7 @@
|
|
6
6
|
= csrf_meta_tags
|
7
7
|
= stylesheet_link_tag "garage/application", :media => "all"
|
8
8
|
= javascript_include_tag "garage/application"
|
9
|
-
= favicon_link_tag "favicon.ico"
|
9
|
+
= favicon_link_tag "favicon.ico", skip_pipeline: true
|
10
10
|
|
11
11
|
%body{ class: action_classes }
|
12
12
|
.navbar.navbar-default.navbar-static-top
|
@@ -19,7 +19,7 @@
|
|
19
19
|
%li= link_to "Console", console_resources_path
|
20
20
|
%ul.nav.navbar-nav.navbar-right
|
21
21
|
- if _current_user
|
22
|
-
%li= link_to "Signout",
|
22
|
+
%li= link_to "Signout", Garage.configuration.docs.signout_path, method: Garage.configuration.docs.signout_request_method
|
23
23
|
|
24
24
|
.main
|
25
25
|
.container
|
data/lib/garage/config.rb
CHANGED
@@ -49,11 +49,13 @@ module Garage
|
|
49
49
|
end
|
50
50
|
|
51
51
|
def cast_resource
|
52
|
-
@cast_resource ||= proc { |resource|
|
52
|
+
@cast_resource ||= proc { |resource, options|
|
53
|
+
options ||= {}
|
54
|
+
to_resource_args = [options[:to_resource_options]].compact
|
53
55
|
if resource.respond_to?(:map) && resource.respond_to?(:to_a)
|
54
|
-
resource.map(
|
56
|
+
resource.map { |r| r.to_resource(*to_resource_args) }
|
55
57
|
else
|
56
|
-
resource.to_resource
|
58
|
+
resource.to_resource(*to_resource_args)
|
57
59
|
end
|
58
60
|
}
|
59
61
|
end
|
data/lib/garage/docs/config.rb
CHANGED
@@ -3,7 +3,8 @@ module Garage
|
|
3
3
|
class Config
|
4
4
|
attr_accessor :document_root, :current_user_method, :authenticate,
|
5
5
|
:console_app_uid, :console_app_secret, :remote_server,
|
6
|
-
:docs_authorization_method, :docs_cache_enabled
|
6
|
+
:docs_authorization_method, :docs_cache_enabled,
|
7
|
+
:signout_path, :signout_request_method
|
7
8
|
|
8
9
|
def initialize
|
9
10
|
reset
|
@@ -17,6 +18,8 @@ module Garage
|
|
17
18
|
@remote_server = Proc.new {|request| "#{request.protocol}#{request.host_with_port}" }
|
18
19
|
@docs_authorization_method = nil
|
19
20
|
@docs_cache_enabled = true
|
21
|
+
@signout_path = '/signout'
|
22
|
+
@signout_request_method = :post
|
20
23
|
end
|
21
24
|
|
22
25
|
class Builder
|
@@ -55,6 +58,14 @@ module Garage
|
|
55
58
|
def docs_authorization_method(&block)
|
56
59
|
@config.docs_authorization_method = block
|
57
60
|
end
|
61
|
+
|
62
|
+
def signout_path=(value)
|
63
|
+
@config.signout_path = value
|
64
|
+
end
|
65
|
+
|
66
|
+
def signout_request_method=(value)
|
67
|
+
@config.signout_request_method = value.to_sym
|
68
|
+
end
|
58
69
|
end
|
59
70
|
end
|
60
71
|
end
|
@@ -24,7 +24,9 @@ module Garage
|
|
24
24
|
# `#resource_identifier` or `#id`.
|
25
25
|
def encode_to_hash(resource, *args)
|
26
26
|
if id = get_resource_identifier(resource)
|
27
|
-
|
27
|
+
options = args[0] || {}
|
28
|
+
selector = options[:selector] || controller.field_selector
|
29
|
+
cache_key = "#{resource.class.name}:#{id}:#{selector.canonical}"
|
28
30
|
cache[cache_key] ||= _encode_to_hash(resource, *args)
|
29
31
|
else
|
30
32
|
_encode_to_hash(resource, *args)
|
data/lib/garage/representer.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'active_support/time_with_zone'
|
2
|
+
|
1
3
|
module Garage::Representer
|
2
4
|
attr_accessor :params, :representer_attrs, :partial, :selector
|
3
5
|
|
@@ -51,7 +53,7 @@ module Garage::Representer
|
|
51
53
|
self.class
|
52
54
|
end
|
53
55
|
|
54
|
-
def to_resource
|
56
|
+
def to_resource(options = {})
|
55
57
|
self
|
56
58
|
end
|
57
59
|
|
@@ -89,6 +89,8 @@ module Garage
|
|
89
89
|
'Resource-Owner-Id' => @request.headers['Resource-Owner-Id'],
|
90
90
|
'Scopes' => @request.headers['Scopes'],
|
91
91
|
'User-Agent' => USER_AGENT,
|
92
|
+
# ActionDispatch::Request#request_id is only available in Rails 5.0 or later.
|
93
|
+
'X-Request-Id' => @request.uuid,
|
92
94
|
}.reject {|_, v| v.nil? }
|
93
95
|
end
|
94
96
|
|
data/lib/garage/tracer.rb
CHANGED
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.
|
4
|
+
version: 2.6.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tatsuhiko Miyagawa
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-03-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -270,8 +270,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
270
270
|
- !ruby/object:Gem::Version
|
271
271
|
version: '0'
|
272
272
|
requirements: []
|
273
|
-
|
274
|
-
rubygems_version: 2.5.2
|
273
|
+
rubygems_version: 3.1.4
|
275
274
|
signing_key:
|
276
275
|
specification_version: 4
|
277
276
|
summary: Garage Platform Engine
|