fields-serializer 0.8.5 → 0.9.0

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: f5ad36fe87b1931ab4b094ef8ccfaedc0451589e
4
- data.tar.gz: 6002ec9b7d4f188f467eb7f083b00f9ea538fdb5
3
+ metadata.gz: 348aaf9bdec62afafbd167fd030af41252db410c
4
+ data.tar.gz: 6510cbd3b125a24afb71b84692a706dc6829f1b6
5
5
  SHA512:
6
- metadata.gz: 0ea2ae96a6ae5549847b715f9a1a2eafd6c9b3eb8eb523d7ae422d82f73fff31d189e708517b504f764749cad1e02e0e153d15c3c52c0454e8090bb11bf9aff3
7
- data.tar.gz: 50ac78b67b3a791fe03bfbda3c633b979dd91b99dacb011ba390b01c1a8cb895514fcebc42e47a2601d02978338e16970964025e7731d636964075058cfbd4fd
6
+ metadata.gz: 61990d7a0253325bce54249af00df9fc6d42d2daf84b53c1b9cbde5c5786a254e166fed4088a52f6f3e2b9acf8f183f9bec487bb687847e9eee8a39ae7a7d7ca
7
+ data.tar.gz: bcfa76eb2cf5791f003764063f0d8a6854392711239c4c3a55092b12a18b88382149fe3ab4138d06485db80a726de7be8852be562fdbc1c7171c522ec6ab1929
data/Gemfile CHANGED
@@ -1,6 +1,6 @@
1
1
  source "https://rubygems.org"
2
2
 
3
- git_source(:github) {|repo_name| "https://github.com/#{repo_name}" }
3
+ git_source(:github) { |repo_name| "https://github.com/#{repo_name}" }
4
4
 
5
5
  # Specify your gem's dependencies in fields-serializer.gemspec
6
6
  gemspec
@@ -6,8 +6,8 @@ require "fields/serializer/version"
6
6
  Gem::Specification.new do |spec|
7
7
  spec.name = "fields-serializer"
8
8
  spec.version = Fields::Serializer::VERSION
9
- spec.authors = ["Stuart Chinery", "Miguel Montalbo", "Lorenzo Tello"]
10
- spec.email = ["stuart.chinery@gmail.com, mmontalbo@zonedigital.com, ltello8a@gmail.com"]
9
+ spec.authors = ["Lorenzo Tello"]
10
+ spec.email = ["ltello8a@gmail.com"]
11
11
 
12
12
  spec.summary = "Extensions to ActiveRecord and ActionController to serialize a subset of model fields"
13
13
  spec.description = "Extensions to ActiveRecord and ActionController to serialize a subset of model fields"
@@ -21,13 +21,13 @@ Gem::Specification.new do |spec|
21
21
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
22
22
  spec.require_paths = ["lib"]
23
23
 
24
- spec.add_development_dependency "bundler", "~> 1.16"
25
- spec.add_development_dependency "rake", "~> 10.0"
26
- spec.add_development_dependency "rspec", "~> 3.6"
27
- spec.add_development_dependency "factory_girl", "~> 4.8"
28
- spec.add_development_dependency "byebug", "~> 5.0"
24
+ spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.6"
27
+ spec.add_development_dependency "factory_bot", "~> 4.8"
28
+ spec.add_development_dependency "byebug", "~> 5.0"
29
29
  spec.add_development_dependency "simplecov"
30
30
 
31
- spec.add_runtime_dependency "rails", "~> 5.0"
31
+ spec.add_runtime_dependency "rails", "~> 5.0"
32
32
  spec.add_runtime_dependency "active_model_serializers", "~> 0.10"
33
33
  end
@@ -1,6 +1,6 @@
1
- require 'active_support'
2
- require 'active_support/core_ext'
3
- require 'active_support/concern'
1
+ require "active_support"
2
+ require "active_support/core_ext"
3
+ require "active_support/concern"
4
4
  require "fields/serializer/version"
5
5
  require "fields/serializer/active_record"
6
6
  require "fields/serializer/action_controller"
@@ -8,7 +8,6 @@ require "fields/serializer/fields_tree"
8
8
 
9
9
  module Fields
10
10
  module Serializer
11
-
12
11
  ActiveSupport.on_load(:active_record) do
13
12
  include Fields::Serializer::ActiveRecord
14
13
  end
@@ -18,7 +18,7 @@ module Fields
18
18
  if fields.present?
19
19
  if optimize_query
20
20
  includes = model_class.fields_to_includes(fields)
21
- query = query.includes(*includes) if includes
21
+ query = query.includes(*Array.wrap(includes)) if includes
22
22
  end
23
23
  options.merge!(each_serializer: model_class.fields_serializer(fields), include: "**")
24
24
  end
@@ -1,6 +1,6 @@
1
- require 'active_record'
1
+ require "active_record"
2
2
  require "active_model_serializers"
3
- require_relative 'active_record/errors'
3
+ require_relative "active_record/errors"
4
4
 
5
5
  module Fields
6
6
  module Serializer
@@ -11,7 +11,7 @@ module Fields
11
11
  class_methods do
12
12
  # If key is an association of a given model class
13
13
  def association?(key)
14
- reflections.keys.include?(key.to_s)
14
+ reflections.key?(key.to_s)
15
15
  end
16
16
 
17
17
  # Convert a list of fields (json_api notation) in a list of associations to be
@@ -1,4 +1,4 @@
1
- require 'active_record'
1
+ require "active_record"
2
2
  require "active_model_serializers"
3
3
 
4
4
  module Fields
@@ -13,12 +13,12 @@ module Fields
13
13
  @fields = []
14
14
  @associations = {}
15
15
  end
16
-
16
+
17
17
  # Self if any fields or associations. Nil otherwise
18
18
  def presence
19
19
  self if fields.present? || associations.present?
20
20
  end
21
-
21
+
22
22
  # Adds a new field (json api notation) to the tree structure:
23
23
  #
24
24
  # user_tree.notation
@@ -33,7 +33,7 @@ module Fields
33
33
  rest.present? ? add_association!(parent, rest) : add_field!(parent)
34
34
  self
35
35
  end
36
-
36
+
37
37
  # Return the tree structure in Rails includes notation including both associations and fields
38
38
  #
39
39
  # user_tree.notation
@@ -64,13 +64,13 @@ module Fields
64
64
  end.presence
65
65
  Array.wrap(to_includes).one? ? to_includes.first : to_includes
66
66
  end
67
-
67
+
68
68
  def to_s
69
69
  notation.to_s
70
70
  end
71
-
71
+
72
72
  private
73
-
73
+
74
74
  def add_association!(parent, rest)
75
75
  existing_association?(parent) ? merge_association!(parent, rest) : append_association!(parent, rest)
76
76
  end
@@ -100,19 +100,19 @@ module Fields
100
100
  end
101
101
 
102
102
  def association?(value)
103
- klass.reflections.keys.include?(value)
103
+ klass.reflections.key?(value)
104
104
  end
105
-
105
+
106
106
  def associations_to_notation
107
107
  associations.inject({}) do |result, (k, v)|
108
108
  result.merge!(k => v.notation)
109
109
  end
110
110
  end
111
-
111
+
112
112
  def existing_association?(value)
113
113
  !!associations[value]
114
114
  end
115
-
115
+
116
116
  def existing_field?(value)
117
117
  fields.include?(value)
118
118
  end
@@ -1,5 +1,5 @@
1
1
  module Fields
2
2
  module Serializer
3
- VERSION = "0.8.5"
3
+ VERSION = "0.9.0"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,16 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: fields-serializer
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.5
4
+ version: 0.9.0
5
5
  platform: ruby
6
6
  authors:
7
- - Stuart Chinery
8
- - Miguel Montalbo
9
7
  - Lorenzo Tello
10
8
  autorequire:
11
9
  bindir: exe
12
10
  cert_chain: []
13
- date: 2018-04-13 00:00:00.000000000 Z
11
+ date: 2018-08-16 00:00:00.000000000 Z
14
12
  dependencies:
15
13
  - !ruby/object:Gem::Dependency
16
14
  name: bundler
@@ -55,7 +53,7 @@ dependencies:
55
53
  - !ruby/object:Gem::Version
56
54
  version: '3.6'
57
55
  - !ruby/object:Gem::Dependency
58
- name: factory_girl
56
+ name: factory_bot
59
57
  requirement: !ruby/object:Gem::Requirement
60
58
  requirements:
61
59
  - - "~>"
@@ -127,7 +125,7 @@ dependencies:
127
125
  description: Extensions to ActiveRecord and ActionController to serialize a subset
128
126
  of model fields
129
127
  email:
130
- - stuart.chinery@gmail.com, mmontalbo@zonedigital.com, ltello8a@gmail.com
128
+ - ltello8a@gmail.com
131
129
  executables: []
132
130
  extensions: []
133
131
  extra_rdoc_files: []
@@ -168,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
168
166
  version: '0'
169
167
  requirements: []
170
168
  rubyforge_project:
171
- rubygems_version: 2.6.14
169
+ rubygems_version: 2.6.13
172
170
  signing_key:
173
171
  specification_version: 4
174
172
  summary: Extensions to ActiveRecord and ActionController to serialize a subset of