postgres_ext-serializers 0.0.2 → 0.0.3

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: 61294d65edd43184592eb2ab0ca4e42c4690278a
4
- data.tar.gz: cfd8ede4cb32dc07585a17444f63d169feb2fe9d
3
+ metadata.gz: 7c65ff204b1d7c5941a9679535713be9f99b0c61
4
+ data.tar.gz: e38459d4a7b894d293ff5ed16b512576bc85b66c
5
5
  SHA512:
6
- metadata.gz: 0f509bce9cbdabc6d2bbce95f43e438ff52f8564133ed43adb9bad3b7f3a64f23d090c7870b411830f92593d3518ab2300b2e34a7b362b9a279c75641008934a
7
- data.tar.gz: 52c02264863554eb1b7be75a98f004916a702347cdfa7df6b4bff1354b25ae320e02f202f05de824e794976456ff95e0f84fb35b247749f99f6957ea67f1e5d2
6
+ metadata.gz: c3dd09d901a3c1d8108dd66ab79f173af229f6c29ffdb0d37d239074e0ca4984b1d57e4177feb2f0df0f6c0083b5d87dcae9a76fe981f1d6e71b78942058d2dc
7
+ data.tar.gz: ba691771d191a19c8766a573f4473e906cab143c32153ba59a3be6b7c0fb31855619127235bfa28124f15c72f6f39e6c0c1becd13a5fcf6dd1f469cd746c8215
@@ -1,5 +1,20 @@
1
1
  # CHANGELOG
2
2
 
3
+ ## 0.0.3 - 2014-09-01
4
+
5
+ ### Added
6
+ - Nothing.
7
+
8
+ ### Deprecated
9
+ - Nothing.
10
+
11
+ ### Removed
12
+ - Nothing.
13
+
14
+ ### Fixed
15
+ - Supports options `each_serializer` and `serializer` when specified in
16
+ the controller or in the serializers
17
+
3
18
  ## 0.0.2 - 2014-08-22
4
19
 
5
20
  ### Added
data/Gemfile CHANGED
@@ -5,4 +5,5 @@ gemspec
5
5
 
6
6
  unless ENV['CI'] || RUBY_PLATFORM =~ /java/
7
7
  gem 'byebug'
8
+ gem 'm'
8
9
  end
data/README.md CHANGED
@@ -8,8 +8,8 @@ Climate](https://codeclimate.com/github/dockyard/postgres_ext-serializers.png)](
8
8
  [![Gem
9
9
  Version](https://badge.fury.io/rb/postgres_ext-serializers.png)](http://badge.fury.io/rb/postgres_ext-serializers)
10
10
 
11
- # Note: Current release is Rails 4.0.x compatible
12
- There will be updates to postgres_ext coming soon to make it 4.1 compatible
11
+ # Note: Current release is AMS 0.8.x compatible
12
+ There will be updates coming to make it 0.9.x compatible
13
13
 
14
14
  ## Looking for help? ##
15
15
 
@@ -24,7 +24,7 @@ module PostgresExt::Serializers::ActiveModel
24
24
  private
25
25
 
26
26
  def _postgres_serializable_array
27
- _include_relation_in_root(object)
27
+ _include_relation_in_root(object, serializer: @options[:each_serializer])
28
28
 
29
29
  jsons_select_manager = _results_table_arel
30
30
  jsons_select_manager.with @_ctes
@@ -32,13 +32,22 @@ module PostgresExt::Serializers::ActiveModel
32
32
  object.klass.connection.select_value _visitor.accept(jsons_select_manager)
33
33
  end
34
34
 
35
- def _include_relation_in_root(relation, foreign_key_column = nil, constraining_table = nil)
35
+ def _include_relation_in_root(relation, *args)
36
+ local_options = args.extract_options!
37
+ foreign_key_column = args[0]
38
+ constraining_table = args[1]
39
+
36
40
  relation_query = relation.dup
37
41
  relation_query_arel = relation_query.arel_table
38
42
  @_embedded << relation.table_name
39
43
 
40
44
  klass = ActiveRecord::Relation === relation ? relation.klass : relation
41
- serializer_class = _serializer_class(klass)
45
+ if local_options[:serializer].present?
46
+ serializer_class = local_options[:serializer]
47
+ else
48
+ serializer_class = _serializer_class(klass)
49
+ end
50
+
42
51
  _serializer = serializer_class.new klass.new, options
43
52
 
44
53
  attributes = serializer_class._attributes
@@ -87,9 +96,11 @@ module PostgresExt::Serializers::ActiveModel
87
96
  end
88
97
 
89
98
  if association.embed_in_root? && !@_embedded.member?(key.to_s)
90
- _include_relation_in_root(association_reflection.klass,association_reflection.foreign_key,ids_table_arel)
99
+ _include_relation_in_root(association_reflection.klass, association_reflection.foreign_key, ids_table_arel,
100
+ serializer: association.target_serializer)
91
101
  end
92
102
  end
103
+
93
104
  arel = relation_query.arel.dup
94
105
 
95
106
  association_sql_tables.each do |assoc_hash|
@@ -1,5 +1,5 @@
1
1
  module PostgresExt
2
2
  module Serializers
3
- VERSION = '0.0.2'
3
+ VERSION = '0.0.3'
4
4
  end
5
5
  end
@@ -19,7 +19,7 @@ Gem::Specification.new do |spec|
19
19
  spec.require_paths = ["lib"]
20
20
 
21
21
  spec.add_runtime_dependency 'postgres_ext', '~> 2.1'
22
- spec.add_runtime_dependency 'active_model_serializers'
22
+ spec.add_runtime_dependency 'active_model_serializers', '~> 0.8.0'
23
23
 
24
24
  spec.add_development_dependency 'bundler', '~> 1.3'
25
25
  spec.add_development_dependency 'actionpack', '~> 4.0'
@@ -2,12 +2,29 @@ require 'test_helper'
2
2
 
3
3
 
4
4
  describe 'ArraySerializer patch' do
5
- let(:json_data) { ActiveModel::Serializer.build_json(controller, relation, {}).to_json }
5
+ let(:json_data) { ActiveModel::Serializer.build_json(controller, relation, options).to_json }
6
+
7
+ context 'specify serializer' do
8
+ let(:relation) { Note.all }
9
+ let(:controller) { NotesController.new }
10
+ let(:options) { { each_serializer: OtherNoteSerializer } }
11
+
12
+ before do
13
+ @note = Note.create content: 'Test', name: 'Title'
14
+ @tag = Tag.create name: 'My tag', note: @note
15
+ end
16
+
17
+ it 'generates the proper json output' do
18
+ json_expected = %{{"tags":[{"id":#{@tag.id},"name":"My tag"}],"notes":[{"id":#{@note.id},"name":"Title","tag_ids":[#{@tag.id}]}]}}
19
+ json_data.must_equal json_expected
20
+ end
21
+ end
6
22
 
7
23
  context 'computed value methods' do
8
24
  let(:relation) { Person.all }
9
25
  let(:controller) { PeopleController.new }
10
26
  let(:person) { Person.create first_name: 'Test', last_name: 'User' }
27
+ let(:options) { }
11
28
 
12
29
  it 'generates the proper json output for the serializer' do
13
30
  json_expected = %{{"people":[{"id":#{person.id},"full_name":"Test User","attendance_name":"User, Test"}]}}
@@ -50,11 +50,18 @@ class NoteSerializer < ActiveModel::Serializer
50
50
  embed :ids, include: true
51
51
  end
52
52
 
53
- class Tag < ActiveRecord::Base
54
- belongs_to :note
53
+ class ShortTagSerializer < ActiveModel::Serializer
54
+ attributes :id, :name
55
55
  end
56
56
 
57
+ class OtherNoteSerializer < ActiveModel::Serializer
58
+ attributes :id, :name
59
+ has_many :tags, serializer: ShortTagSerializer, embed: :ids, include: true
60
+ end
57
61
 
62
+ class Tag < ActiveRecord::Base
63
+ belongs_to :note
64
+ end
58
65
 
59
66
  class TagSerializer < ActiveModel::Serializer
60
67
  attributes :id, :name
@@ -62,6 +69,7 @@ class TagSerializer < ActiveModel::Serializer
62
69
  has_one :note
63
70
  end
64
71
 
72
+
65
73
  DatabaseCleaner.strategy = :deletion
66
74
 
67
75
  class Minitest::Spec
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: postgres_ext-serializers
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dan McClain
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-22 00:00:00.000000000 Z
11
+ date: 2014-09-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: postgres_ext
@@ -28,16 +28,16 @@ dependencies:
28
28
  name: active_model_serializers
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ">="
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '0'
33
+ version: 0.8.0
34
34
  type: :runtime
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ">="
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
- version: '0'
40
+ version: 0.8.0
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: bundler
43
43
  requirement: !ruby/object:Gem::Requirement