yaks 0.4.3 → 0.4.4

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: f8ee4f04ef31bd3c1e944ee723c910bf37dd97b8
4
- data.tar.gz: 93282ee4d7a30bdb826ccc81447d86db1de245f0
3
+ metadata.gz: e75dbaa5cc865ca07fb16ae3e4662f3983652d96
4
+ data.tar.gz: bedaee826c1ae525bf0aa5511c62ccb3c02a0738
5
5
  SHA512:
6
- metadata.gz: d09019c49799077e500badde0c259fa41d06f2fdbfe3ec3c7c7cf71625ce786d2eb682b2b449edc8a683b8a24a20234cd3ea16716697154a58fcd88c6a6773a9
7
- data.tar.gz: b0107900f0d00a2b30ab7d6cd701b84a59e3155961a653847b863d5cc0a569c0ff24640769b78826afad31fa6b5667cf3cf294961de82f3b1c6fbd8301f8c460
6
+ metadata.gz: 8f43aa2b03a6beb9f37009d3540ac8a75623e8dd3fb2b634785be696b81e20a3e7918cb3aef5eac86c63df49390f3ffd806c8a83596beff94e6dfb53793eba3d
7
+ data.tar.gz: 326578cce03f31740ceb6e927d431b8a42eefc0f79d8c65e0255bcd4475b952a6b0393eaf5ff11fcc5ae15f738bd7983ee767bd5964148cebccd9f8d68f50547
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  ### Development
2
- [full changelog](http://github.com/plexus/yaks/compare/v0.4.2...master)
2
+ [full changelog](http://github.com/plexus/yaks/compare/v0.4.3...master)
3
+
4
+ Mapping a non-empty collection will try to infer the type, and hence rel of the nested items, based on the first object in the collection. This is only relevant for formats like HAL that don't have a top-level collection representation, and only matters when mapping a collection at the top level, not when mapping a collection from an association.
5
+
6
+ ### 0.4.3
3
7
 
4
8
  * when specifying a rel_template, instead of allowing for {src} and {dest} fields, now a single {rel} field is expected, which corresponds more with typical usage.
5
9
 
@@ -1,5 +1,8 @@
1
1
  module Yaks
2
2
 
3
+ # These are displayed in a post-install message when installing the
4
+ # gem to aid upgraiding
5
+
3
6
  BreakingChanges = {
4
7
  '0.4.3' => %q~
5
8
 
@@ -19,4 +22,6 @@ documentation.
19
22
  ~
20
23
  }
21
24
 
25
+ BreakingChanges['0.4.4'] = BreakingChanges['0.4.3']
26
+
22
27
  end
@@ -38,6 +38,8 @@ module Yaks
38
38
  def collection_type
39
39
  if item_mapper = context[:item_mapper]
40
40
  item_mapper.config.type || policy.derive_type_from_mapper_class(item_mapper)
41
+ else
42
+ policy.derive_type_from_collection(collection)
41
43
  end
42
44
  end
43
45
 
data/lib/yaks/config.rb CHANGED
@@ -35,10 +35,10 @@ module Yaks
35
35
 
36
36
  # @param [Hash] opts
37
37
  # @param [Hash] env
38
- # @return [Yaks::Format::CollectionJson, Yaks::Format::Hal, Yaks::Format::JsonApi]
38
+ # @return [Class]
39
39
  def format_class(opts, env)
40
- accept = Rack::Accept::Charset.new(env['HTTP_ACCEPT'])
41
- mime_type = accept.best_of(Format.mime_types.values)
40
+ accept = Rack::Accept::MediaType.new(env['HTTP_ACCEPT'])
41
+ mime_type = accept.best_of([nil] + Format.mime_types.values)
42
42
  return Format.by_mime_type(mime_type) if mime_type
43
43
  Format.by_name(opts.fetch(:format) { @default_format })
44
44
  end
@@ -54,6 +54,14 @@ module Yaks
54
54
  # @param [Yaks::Mapper::Association] association
55
55
  # @return [Class] of subclass Yaks::Mapper
56
56
  # @raise [NameError]
57
+ def derive_type_from_collection(collection)
58
+ if collection.any?
59
+ derive_type_from_mapper_class(
60
+ derive_mapper_from_object(collection.first)
61
+ )
62
+ end
63
+ end
64
+
57
65
  def derive_mapper_from_association(association)
58
66
  @options[:namespace].const_get("#{camelize(association.singular_name)}Mapper")
59
67
  end
data/lib/yaks/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Yaks
2
- VERSION = '0.4.3'
2
+ VERSION = '0.4.4'
3
3
  end
@@ -58,14 +58,14 @@ RSpec.describe Yaks::CollectionMapper do
58
58
 
59
59
  it 'should infer the item mapper' do
60
60
  expect(mapper.call(collection)).to eql Yaks::CollectionResource.new(
61
- type: nil,
61
+ type: 'pet',
62
62
  links: [],
63
63
  attributes: {},
64
64
  members: [
65
65
  Yaks::Resource.new(type: 'pet', attributes: {:id => 2, :species => "dog", :name => "boingboing"}),
66
66
  Yaks::Resource.new(type: 'pet', attributes: {:id => 3, :species => "cat", :name => "wassup"})
67
67
  ],
68
- collection_rel: 'collection'
68
+ collection_rel: 'rel:pets'
69
69
  )
70
70
  end
71
71
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaks
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.3
4
+ version: 0.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Arne Brasseur
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-25 00:00:00.000000000 Z
11
+ date: 2014-08-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: inflection