gris 0.4.5 → 0.4.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7b4abfeb569455ac1557220759fed00d91b12698
4
- data.tar.gz: 5a07d55604ba7d0f070a03e3d1066796ceab5f60
3
+ metadata.gz: 034350c7d90aff8466b08aff40fb6e9dafe967c7
4
+ data.tar.gz: 7c9390ef0aeea7537d8da9d0688a930cf9aa0150
5
5
  SHA512:
6
- metadata.gz: df3b86ca754667587d31fe5d70cb079c890009f0c31ee8588425e12e058bea9514e9848326476d582856e9f312d235df6e380ad7e32672a7e70f47d8685335e3
7
- data.tar.gz: 57159e0bec4873868f9437f49c14694720775730af8210b623f4866a3b53ba5dce81349c68fae28f95ac12cd57b7ee467941f864acaea2f19f8dd52080f268e0
6
+ metadata.gz: 606f7d968a885ff8ea1c3665169aabd2de08ea75c4b72ce19f57b5098c72a4087cf5536e8e3daba233abc5b6d9afa5050601daafbe67651639b5c82ade73bcfa
7
+ data.tar.gz: 97ceee9239f360daf0d4ba61a3a8677549626667b48ac0f0ef51f040759458210dcbe550539ea368fe6f76d246c58e5c5946b2d42dc08c339ad85cf84b9f9663
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- gris (0.4.5)
4
+ gris (0.4.6)
5
5
  activesupport (~> 4.2, >= 4.2.0)
6
6
  chronic (~> 0.10.0)
7
7
  dalli (~> 2.7)
@@ -21,8 +21,8 @@ require 'gris/grape_extensions/error_helpers'
21
21
  require 'gris/identity'
22
22
  require 'gris/middleware/health'
23
23
  require 'gris/output_formatters/paginated_presenter'
24
- require 'gris/output_formatters/root_presenter'
25
24
  require 'gris/output_formatters/presenter'
25
+ require 'gris/output_formatters/presenter_link_helpers'
26
26
  require 'gris/setup'
27
27
  require 'gris/version'
28
28
 
@@ -1,5 +1,5 @@
1
1
  module RootPresenter
2
- include Gris::RootPresenter
2
+ include Gris::Presenter
3
3
 
4
4
  link :self do
5
5
  Gris::Identity.base_url
@@ -9,6 +9,7 @@ module Gris
9
9
  include Roar::JSON::HAL
10
10
  include Roar::Hypermedia
11
11
  include Grape::Roar::Representer
12
+ include Gris::PresenterLinkHelpers
12
13
 
13
14
  private
14
15
 
@@ -0,0 +1,41 @@
1
+ module Gris
2
+ module PresenterLinkHelpers
3
+ def self.included(base)
4
+ base.class_eval do
5
+ def self.resource_links(name, args = [], resource_uri_template = '/{id}')
6
+ args += %w(page size)
7
+ endpoint_link(
8
+ name.to_s.pluralize,
9
+ template_options: args, templated: true
10
+ )
11
+ endpoint_link(
12
+ name,
13
+ namespace: name.to_s.pluralize,
14
+ uri_template: resource_uri_template,
15
+ templated: true
16
+ )
17
+ end
18
+
19
+ def self.endpoint_link(name, options = {})
20
+ namespace = options[:namespace] || name
21
+ template_options = options[:template_options] || []
22
+ uri_template = options[:uri_template] || format_template_options(template_options)
23
+ link name do
24
+ link = {
25
+ href: "#{Gris::Identity.base_url}/#{namespace}#{uri_template}"
26
+ }
27
+ link[:templated] = true if !!options[:templated] || !template_options.blank?
28
+ link
29
+ end
30
+ end
31
+
32
+ private
33
+
34
+ def self.format_template_options(template_options = [])
35
+ return unless template_options.any?
36
+ "{?#{template_options.join(',')}}"
37
+ end
38
+ end
39
+ end
40
+ end
41
+ end
@@ -1,5 +1,5 @@
1
1
  module Gris
2
- VERSION = '0.4.5'
2
+ VERSION = '0.4.6'
3
3
 
4
4
  class Version
5
5
  class << self
@@ -98,8 +98,8 @@ describe Gris::Generators::ScaffoldGenerator do
98
98
  expect(root_presenter_file).to match(/module RootPresenter/)
99
99
  end
100
100
 
101
- it 'includes Gris::RootPresenter' do
102
- expect(RootPresenter).to include(Gris::RootPresenter)
101
+ it 'includes Gris::Presenter' do
102
+ expect(RootPresenter).to include(Gris::Presenter)
103
103
  end
104
104
 
105
105
  it 'includes link to self' do
@@ -2,27 +2,31 @@ require 'spec_helper'
2
2
  require 'gris'
3
3
  require 'rack/test'
4
4
 
5
- describe Gris::RootPresenter do
5
+ describe Gris::PresenterLinkHelpers do
6
6
  include Rack::Test::Methods
7
7
 
8
- module RootPresenter
9
- include Gris::RootPresenter
8
+ module MyRootPresenter
9
+ include Gris::Presenter
10
+
11
+ resource_links :printmaker, [:account_id], '/{id}?account_id={account_id}'
10
12
  resource_links :painter, [:sort]
11
- endpoint_link :painting, [:account_id]
12
13
  resource_links :sculptor
14
+
15
+ endpoint_link :painting, template_options: [:account_id, :user_id]
13
16
  endpoint_link :sculpture
17
+ endpoint_link :self, namespace: 'drawings', uri_template: '/{id}'
14
18
  end
15
19
 
16
- class ApplicationEndpoint < Grape::API
20
+ class MyApplicationEndpoint < Grape::API
17
21
  format :json
18
22
  formatter :json, Grape::Formatter::Roar
19
23
  get do
20
- present self, with: RootPresenter
24
+ present self, with: MyRootPresenter
21
25
  end
22
26
  end
23
27
 
24
28
  def app
25
- ApplicationEndpoint.new
29
+ MyApplicationEndpoint.new
26
30
  end
27
31
 
28
32
  before do
@@ -30,6 +34,10 @@ describe Gris::RootPresenter do
30
34
  @result = Hashie::Mash.new JSON.parse(last_response.body)
31
35
  end
32
36
 
37
+ it 'includes Gris::PresenterLinkHelpers' do
38
+ expect(RootPresenter).to include(Gris::PresenterLinkHelpers)
39
+ end
40
+
33
41
  it 'returns uri template for resource_links with additional arguments' do
34
42
  expect(@result['_links']['painters']['href']).to eq "#{Gris::Identity.base_url}/painters{?sort,page,size}"
35
43
  expect(@result['_links']['painters']['templated']).to eq true
@@ -37,6 +45,13 @@ describe Gris::RootPresenter do
37
45
  expect(@result['_links']['painter']['templated']).to eq true
38
46
  end
39
47
 
48
+ it 'returns uri template for resource_links with resource_uri_template' do
49
+ expect(@result['_links']['printmakers']['href']).to eq "#{Gris::Identity.base_url}/printmakers{?account_id,page,size}"
50
+ expect(@result['_links']['printmakers']['templated']).to eq true
51
+ expect(@result['_links']['printmaker']['href']).to eq "#{Gris::Identity.base_url}/printmakers/{id}?account_id={account_id}"
52
+ expect(@result['_links']['printmaker']['templated']).to eq true
53
+ end
54
+
40
55
  it 'returns uri template for resource_links without additional arguments' do
41
56
  expect(@result['_links']['sculptors']['href']).to eq "#{Gris::Identity.base_url}/sculptors{?page,size}"
42
57
  expect(@result['_links']['sculptors']['templated']).to eq true
@@ -44,8 +59,8 @@ describe Gris::RootPresenter do
44
59
  expect(@result['_links']['sculptor']['templated']).to eq true
45
60
  end
46
61
 
47
- it 'returns uri template for endpoint_link with additional arguments' do
48
- expect(@result['_links']['painting']['href']).to eq "#{Gris::Identity.base_url}/painting{?account_id}"
62
+ it 'returns uri template for endpoint_link with template_options' do
63
+ expect(@result['_links']['painting']['href']).to eq "#{Gris::Identity.base_url}/painting{?account_id,user_id}"
49
64
  expect(@result['_links']['painting']['templated']).to eq true
50
65
  end
51
66
 
@@ -53,4 +68,9 @@ describe Gris::RootPresenter do
53
68
  expect(@result['_links']['sculpture']['href']).to eq "#{Gris::Identity.base_url}/sculpture"
54
69
  expect(@result['_links']['sculpture']['templated']).to be_nil
55
70
  end
71
+
72
+ it 'returns uri template for endpoint_link with namespace and uri_template options' do
73
+ expect(@result['_links']['self']['href']).to eq "#{Gris::Identity.base_url}/drawings/{id}"
74
+ expect(@result['_links']['self']['templated']).to be_nil
75
+ end
56
76
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gris
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.4.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dylan Fareed
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-08-20 00:00:00.000000000 Z
11
+ date: 2015-08-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: thor
@@ -376,7 +376,7 @@ files:
376
376
  - lib/gris/middleware/health.rb
377
377
  - lib/gris/output_formatters/paginated_presenter.rb
378
378
  - lib/gris/output_formatters/presenter.rb
379
- - lib/gris/output_formatters/root_presenter.rb
379
+ - lib/gris/output_formatters/presenter_link_helpers.rb
380
380
  - lib/gris/rspec_extensions/active_record_shared_connection.rb
381
381
  - lib/gris/rspec_extensions/response_helpers.rb
382
382
  - lib/gris/setup.rb
@@ -396,7 +396,7 @@ files:
396
396
  - spec/identity_spec.rb
397
397
  - spec/integration/application_error_response_spec.rb
398
398
  - spec/integration/token_authentication_spec.rb
399
- - spec/output_formatters/root_presenter_spec.rb
399
+ - spec/output_formatters/presenter_link_helpers_spec.rb
400
400
  - spec/secrets_spec.rb
401
401
  - spec/spec_helper.rb
402
402
  - spec/support/caching_helper.rb
@@ -445,7 +445,7 @@ test_files:
445
445
  - spec/identity_spec.rb
446
446
  - spec/integration/application_error_response_spec.rb
447
447
  - spec/integration/token_authentication_spec.rb
448
- - spec/output_formatters/root_presenter_spec.rb
448
+ - spec/output_formatters/presenter_link_helpers_spec.rb
449
449
  - spec/secrets_spec.rb
450
450
  - spec/spec_helper.rb
451
451
  - spec/support/caching_helper.rb
@@ -1,43 +0,0 @@
1
- module Gris
2
- module RootPresenter
3
- def self.included(base)
4
- base.class_eval do
5
- include Gris::Presenter
6
-
7
- def self.resource_links(name, args = [])
8
- args += %w(page size)
9
- link name.to_s.pluralize do
10
- link = {
11
- href: "#{Gris::Identity.base_url}/#{name.to_s.pluralize}#{format_args(args)}",
12
- templated: true
13
- }
14
- link
15
- end
16
- link name do
17
- {
18
- href: "#{Gris::Identity.base_url}/#{name.to_s.pluralize}/{id}",
19
- templated: true
20
- }
21
- end
22
- end
23
-
24
- def self.endpoint_link(name, args = [])
25
- link name do
26
- link = {
27
- href: "#{Gris::Identity.base_url}/#{name}#{format_args(args)}"
28
- }
29
- link[:templated] = true unless args.blank?
30
- link
31
- end
32
- end
33
-
34
- private
35
-
36
- def format_args(args = [])
37
- return unless args.any?
38
- "{?#{args.join(',')}}"
39
- end
40
- end
41
- end
42
- end
43
- end