json_api_ruby 0.4.5 → 0.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
2
  SHA1:
3
- metadata.gz: abc6919453aaa4d3a138d1c3d60f3217f4a9fced
4
- data.tar.gz: 18d4a95440819a2b62d0b85909967b36f0fb86d7
3
+ metadata.gz: d44fb07a8492daca10263befdbc625650a3c2eea
4
+ data.tar.gz: bb712bed6fa7af0c0bd54af3b7a8d9cee881d32c
5
5
  SHA512:
6
- metadata.gz: 4fa3216fcee3952ee4d6ba50098581797e45f0f57acfde49828bb3db0d768a8b1222bc7fb21acce805f02a8614121f4f6b53b8de9783e880032b1e4d8ede6f04
7
- data.tar.gz: e44c705fa51b77d595979d1ba3e6dd2ab4964a94afc38cb4df92ea4b7145ff742022106a4ef470ccdb47032d156bc301935947e7b22e91e6069801b787a06e79
6
+ metadata.gz: a5c0e735cf0650b19682845590bc206988c277af76ee99f9f8aef2f3dbd057e42441363a8f3ad51d68b062746d6e29f5e1b1cc3546ddfa7f68c21fa0b6cbfc64
7
+ data.tar.gz: 1e727eaab3ccc5b1b651caa5674b4072b2fb7da29487db244c784c42bf0eee0ac9acf3500873a055278af843cd2cde70ef124327fbe708e17fd51413030d1806
@@ -24,7 +24,11 @@ module JsonApi
24
24
 
25
25
  # Can be overridden in a subclass
26
26
  def type
27
- _model.class.to_s.underscore.pluralize
27
+ if self.class._type
28
+ self.class._type
29
+ else
30
+ @type ||= _model.class.to_s.underscore.pluralize
31
+ end
28
32
  end
29
33
 
30
34
  def use_links
@@ -3,6 +3,7 @@ module JsonApi
3
3
  module DSL
4
4
  attr :_id_field
5
5
  attr :_use_links
6
+ attr :_type
6
7
  attr :fields
7
8
  attr :relationships
8
9
 
@@ -30,6 +31,15 @@ module JsonApi
30
31
  @_id_field = key
31
32
  end
32
33
 
34
+ def type(type)
35
+ # allow falling back to default if we reallly want to
36
+ if type.blank?
37
+ @_type = nil
38
+ else
39
+ @_type = type.to_s
40
+ end
41
+ end
42
+
33
43
  def use_links(yesno)
34
44
  @_use_links = yesno
35
45
  end
@@ -1,3 +1,3 @@
1
1
  module JsonApi
2
- VERSION = '0.4.5'
2
+ VERSION = '0.5.0'
3
3
  end
@@ -1,10 +1,8 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  RSpec.describe JsonApi::Resource do
4
- subject(:serialized_person) do
5
- person = Person.new('Brad J. Armbruster', 'ace@airforce.mil')
6
- PersonResource.new(person).to_hash
7
- end
4
+ let(:person) { Person.new('Brad J. Armbruster', 'ace@airforce.mil') }
5
+ subject(:serialized_person) { PersonResource.new(person).to_hash }
8
6
 
9
7
  it 'is follows the JSON API spec' do
10
8
  expect(serialized_person).to be_valid_json_api
@@ -26,6 +24,15 @@ RSpec.describe JsonApi::Resource do
26
24
  expect(serialized_person).to have_attribute(:updated_at)
27
25
  end
28
26
 
27
+ describe 'overridding type' do
28
+ before { PersonResource.type(:persons) }
29
+ after { PersonResource.type(nil) }
30
+
31
+ it 'has "persons" as its type' do
32
+ expect(serialized_person['type']).to eq 'persons'
33
+ end
34
+ end
35
+
29
36
  describe 'relationships' do
30
37
  subject(:serialized_article) do
31
38
  article = Person.new('Anatoly Fyodorovich Krimov', 'red_star@kremlin.mil').articles.first
@@ -70,6 +70,7 @@ class Person
70
70
  end
71
71
 
72
72
  class PersonResource < JsonApi::Resource
73
+ type :people
73
74
  attribute :name
74
75
  attribute :email_address
75
76
  attribute :created_at
@@ -101,6 +102,7 @@ end
101
102
 
102
103
  class ArticleResource < JsonApi::Resource
103
104
  id_field :uuid
105
+ type :articles
104
106
  attributes :publish_date, :title, :short_description, :created_at, :updated_at
105
107
 
106
108
  has_one :author
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: json_api_ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.5
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Tracey Eubanks
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-05-10 00:00:00.000000000 Z
11
+ date: 2016-05-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport