the_garage 2.4.0 → 2.5.0

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
- SHA1:
3
- metadata.gz: df6a793861e979f1a7849b0d6ef3ef5764757980
4
- data.tar.gz: df87e84d9f87372c8c2061d4aafabd6849d89b52
2
+ SHA256:
3
+ metadata.gz: 8a8b827892d32f5517d67991bfc76a4832eba4f3aa5b1c1d1cd1f76141bc3422
4
+ data.tar.gz: fce58bbb7be2ef82e68416650419d88e3bf10205c011806660081a594cf29d6a
5
5
  SHA512:
6
- metadata.gz: 996522903af5c5b250cb7a99f41a8ed095a23c17b36076cd8bf34409b16d02b4f5ec6196b357238b1726452d8ceba415b481d4f2f56abbc7c19997972a557c97
7
- data.tar.gz: c96ace465cac6ade9d7b477ab3c58b457b660e709067490213154f5b017392ca717b87980dd7058ada25ede679ad2de6c2d17ab43b20dbaf9259264c58e5b6a6
6
+ metadata.gz: d691e438110eabee1b14a9f011067f67f4cf5119f248843d6c4d8d3f44125e7f7a76f0b56d12cac53770238425c6a2d5f62c4321e8273264ce4306e6f943c0e8
7
+ data.tar.gz: d408e49c73f46d1fcda1d3d8f9a61a76b8a7e6411172bf4eace5c38c4572be838e4c0f65e1f8dea5006949532b741fc19de4600d72fccde4a49dc8bc7468f810
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
@@ -197,7 +209,7 @@ Currently, we support following tracers:
197
209
 
198
210
  ```ruby
199
211
  # e.g. aws-xray tracer
200
- require 'aws/xray'
212
+ require 'aws/xray/hooks/net_http'
201
213
  Garage::Tracer::AwsXrayTracer.service = 'your-auth-server-name'
202
214
  Garage.configuration.tracer = Garage::Tracer::AwsXrayTracer
203
215
  ```
@@ -0,0 +1,2 @@
1
+ //= link_directory ../javascripts .js
2
+ //= link_directory ../stylesheets .css
@@ -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", "/signout", method: :post
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
@@ -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(&:to_resource)
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
@@ -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
- cache_key = "#{resource.class.name}:#{id}"
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)
@@ -51,7 +51,7 @@ module Garage::Representer
51
51
  self.class
52
52
  end
53
53
 
54
- def to_resource
54
+ def to_resource(options = {})
55
55
  self
56
56
  end
57
57
 
@@ -6,7 +6,7 @@ module Garage::ResourceCastingResponder
6
6
 
7
7
  def display(resource, given_options={})
8
8
  if @caster
9
- resource = @caster.call(resource)
9
+ resource = @caster.call(resource, @options)
10
10
  end
11
11
  super(resource, given_options)
12
12
  end
@@ -1,3 +1,5 @@
1
+ require 'forwardable'
2
+
1
3
  module Garage
2
4
  module Tracer
3
5
  extend self
@@ -45,44 +47,17 @@ module Garage
45
47
  end
46
48
 
47
49
  def self.start(&block)
48
- if Aws::Xray::Context.started?
49
- Aws::Xray::Context.current.child_trace(remote: true, name: service) do |sub|
50
- yield new(sub)
51
- end
52
- else
53
- yield NullTracer.new
54
- end
55
- end
56
-
57
- def initialize(sub_segment)
58
- @sub = sub_segment
50
+ yield new
59
51
  end
60
52
 
61
53
  def inject_trace_context(header)
62
- header.merge('X-Amzn-Trace-Id' => @sub.generate_trace.to_header_value)
54
+ header.merge('X-Aws-Xray-Name' => self.class.service)
63
55
  end
64
56
 
65
57
  def record_http_request(method, url, user_agent)
66
- request = Aws::Xray::Request.build(method: method.to_s.upcase, url: url, user_agent: user_agent)
67
- @sub.set_http_request(request)
68
58
  end
69
59
 
70
60
  def record_http_response(status, content_length)
71
- @sub.set_http_response(status, content_length || 0)
72
-
73
- case status
74
- when 499
75
- cause = Aws::Xray::Cause.new(stack: caller, message: 'Got 499', type: 'http_request_error')
76
- @sub.set_error(error: true, throttle: true, cause: cause)
77
- when 400..498
78
- cause = Aws::Xray::Cause.new(stack: caller, message: 'Got 4xx', type: 'http_request_error')
79
- @sub.set_error(error: true, cause: cause)
80
- when 500..599
81
- cause = Aws::Xray::Cause.new(stack: caller, message: 'Got 5xx', type: 'http_request_error')
82
- @sub.set_error(fault: true, remote: true, cause: cause)
83
- else
84
- # pass
85
- end
86
61
  end
87
62
  end
88
63
  end
@@ -1,3 +1,3 @@
1
1
  module Garage
2
- VERSION = '2.4.0'
2
+ VERSION = '2.5.0'
3
3
  end
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.0
4
+ version: 2.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tatsuhiko Miyagawa
8
- autorequire:
8
+ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-07 00:00:00.000000000 Z
11
+ date: 2020-06-25 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -188,6 +188,7 @@ files:
188
188
  - MIT-LICENSE
189
189
  - README.md
190
190
  - Rakefile
191
+ - app/assets/config/manifest.js
191
192
  - app/assets/javascripts/garage/application.js
192
193
  - app/assets/javascripts/garage/docs/console.js.coffee
193
194
  - app/assets/javascripts/garage/docs/jquery.colorbox.js
@@ -255,7 +256,7 @@ homepage: https://github.com/cookpad/garage
255
256
  licenses:
256
257
  - MIT
257
258
  metadata: {}
258
- post_install_message:
259
+ post_install_message:
259
260
  rdoc_options: []
260
261
  require_paths:
261
262
  - lib
@@ -270,9 +271,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
270
271
  - !ruby/object:Gem::Version
271
272
  version: '0'
272
273
  requirements: []
273
- rubyforge_project:
274
- rubygems_version: 2.6.11
275
- signing_key:
274
+ rubygems_version: 3.1.2
275
+ signing_key:
276
276
  specification_version: 4
277
277
  summary: Garage Platform Engine
278
278
  test_files: []