pg_serializable 1.3.0 → 1.3.1

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
  SHA256:
3
- metadata.gz: 648a712ad1604caafa1ce54620bde306d99f38fba5b3897b707bce2302ac15de
4
- data.tar.gz: 00e8956c9bc8c41bb967e3340cf6a51b642a06061dd9d736e586696c7662a438
3
+ metadata.gz: bdecd8f20e4e15821e6f0e57e93b45f8747d384792aa62326be2305987de1683
4
+ data.tar.gz: 36f0d9ff9a67f5496c30c0abc80b0d8cccce635799e4d5732bd24c6fdf8eefc1
5
5
  SHA512:
6
- metadata.gz: fd39bd3c82b9732015cad9776b36c45e828fb890e2104c739ad250ee9ecf7aa913d6b328c358286f3f99e315d2b3bb8d63284ff3b679dfe0d0b89e079eaed019
7
- data.tar.gz: fa604b60406ff47e4b1b7795f85481c1c10626ca9de59b221e94ba2bd20e70a9e75566ea464e184afbd03557ac916f240f84374326269f4b7de84926cd4a49b2
6
+ metadata.gz: 06a979406f2f30aba2438166fa1d4dcc5ddb2a2acf5820585bbc3029d7b978dfce32db0c8ad3d800509e12d3abd8a5b0e3f3f53f53ea2c48483160be74fd33dd
7
+ data.tar.gz: 343113e081a52d110cfd695b7b483be7a7748b52bd8317667eeff2bc82fc563b7a7bd2be967a40acd68039d5173037ab8de52371aa069610661a1f4d2ee2af5e
data/Gemfile.lock CHANGED
@@ -1,32 +1,43 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- pg_serializable (1.0.0)
4
+ pg_serializable (1.3.1)
5
5
  activerecord (~> 5.2)
6
6
  activesupport (~> 5.2)
7
7
  oj (~> 3.6)
8
+ pg (>= 1.1)
8
9
 
9
10
  GEM
10
11
  remote: https://rubygems.org/
11
12
  specs:
12
- activemodel (5.2.1)
13
- activesupport (= 5.2.1)
14
- activerecord (5.2.1)
15
- activemodel (= 5.2.1)
16
- activesupport (= 5.2.1)
13
+ activemodel (5.2.3)
14
+ activesupport (= 5.2.3)
15
+ activerecord (5.2.3)
16
+ activemodel (= 5.2.3)
17
+ activesupport (= 5.2.3)
17
18
  arel (>= 9.0)
18
- activesupport (5.2.1)
19
+ activesupport (5.2.3)
19
20
  concurrent-ruby (~> 1.0, >= 1.0.2)
20
21
  i18n (>= 0.7, < 2)
21
22
  minitest (~> 5.1)
22
23
  tzinfo (~> 1.1)
23
24
  arel (9.0.0)
24
- concurrent-ruby (1.0.5)
25
+ coderay (1.1.2)
26
+ concurrent-ruby (1.1.5)
27
+ database_cleaner (1.7.0)
25
28
  diff-lcs (1.3)
26
- i18n (1.1.1)
29
+ factory_bot (5.0.2)
30
+ activesupport (>= 4.2.0)
31
+ ffaker (2.11.0)
32
+ i18n (1.6.0)
27
33
  concurrent-ruby (~> 1.0)
34
+ method_source (0.9.2)
28
35
  minitest (5.11.3)
29
- oj (3.6.11)
36
+ oj (3.7.12)
37
+ pg (1.1.4)
38
+ pry (0.12.2)
39
+ coderay (~> 1.1.0)
40
+ method_source (~> 0.9.0)
30
41
  rake (10.5.0)
31
42
  rspec (3.8.0)
32
43
  rspec-core (~> 3.8.0)
@@ -37,6 +48,9 @@ GEM
37
48
  rspec-expectations (3.8.2)
38
49
  diff-lcs (>= 1.2.0, < 2.0)
39
50
  rspec-support (~> 3.8.0)
51
+ rspec-its (1.3.0)
52
+ rspec-core (>= 3.0.0)
53
+ rspec-expectations (>= 3.0.0)
40
54
  rspec-mocks (3.8.0)
41
55
  diff-lcs (>= 1.2.0, < 2.0)
42
56
  rspec-support (~> 3.8.0)
@@ -50,9 +64,14 @@ PLATFORMS
50
64
 
51
65
  DEPENDENCIES
52
66
  bundler (~> 1.16)
67
+ database_cleaner
68
+ factory_bot
69
+ ffaker
53
70
  pg_serializable!
71
+ pry
54
72
  rake (~> 10.0)
55
73
  rspec (~> 3.0)
74
+ rspec-its
56
75
 
57
76
  BUNDLED WITH
58
77
  1.16.5
data/README.md CHANGED
@@ -596,9 +596,9 @@ Response:
596
596
  ]
597
597
  ```
598
598
 
599
- ## Development
599
+ ## Without Rails
600
600
 
601
- TODO
601
+ Rails isn't a dependency of this gem. However, setting it up to work without Rails takes some work. The `specs/support` folder has the initialization code needed to run the gem with just `ActiveSupport` and `ActiveRecord`.
602
602
 
603
603
  ## License
604
604
 
@@ -1,5 +1,6 @@
1
1
  require 'oj'
2
2
  require 'active_support/concern'
3
+ require 'active_support/core_ext/module/delegation'
3
4
  require 'pg_serializable/errors'
4
5
  require 'pg_serializable/visitable'
5
6
  require 'pg_serializable/nodes'
@@ -7,8 +8,6 @@ require 'pg_serializable/trait_manager'
7
8
  require 'pg_serializable/trait'
8
9
  require 'pg_serializable/visitors'
9
10
 
10
- Oj.mimic_JSON()
11
-
12
11
  module ActiveRecord
13
12
  class Relation
14
13
  include PgSerializable::Visitable
@@ -1,3 +1,3 @@
1
1
  module PgSerializable
2
- VERSION = "1.3.0"
2
+ VERSION = "1.3.1"
3
3
  end
@@ -45,7 +45,8 @@ module PgSerializable
45
45
  return visit_enum(subject, table_alias: table_alias) if subject.enum?
46
46
  table_alias ||= alias_tracker
47
47
  key = "\'#{subject.label}\'"
48
- val = "\"#{table_alias}\".\"#{subject.prc ? subject.prc.call(column_name) : subject.column_name}\""
48
+ column_name = "\"#{table_alias}\".\"#{subject.column_name}\""
49
+ val = subject.prc ? subject.prc.call(column_name) : column_name
49
50
  "#{key}, #{val}"
50
51
  end
51
52
 
@@ -87,13 +88,15 @@ module PgSerializable
87
88
 
88
89
  def visit_has_many_through(subject, table_alias:, **kwargs)
89
90
  current_alias = next_alias!
90
-
91
91
  association = subject.association
92
92
  through = association.through_reflection
93
93
  source = association.source_reflection
94
94
  join_name = source.collection? ? through.plural_name.to_sym : through.name
95
+ # needs work
95
96
  where_clause = begin
96
- if through.belongs_to?
97
+ if source.belongs_to?
98
+ "#{table_alias}.#{through.join_foreign_key}=#{through.table_name}.#{through.join_primary_key}"
99
+ elsif through.belongs_to?
97
100
  "#{table_alias}.#{through.join_foreign_key}=#{through.table_name}.#{subject.foreign_key}"
98
101
  else
99
102
  "#{through.table_name}.#{through.join_foreign_key}=#{table_alias}.#{subject.foreign_key}"
@@ -56,6 +56,7 @@ module PgSerializable
56
56
  case subject
57
57
  when trait? then subject.attribute_nodes.each { |node| check_for_cycles(node) }
58
58
  when association?
59
+ return if subject.association.nil? # skip if association isn't loaded yet, it'll get caught later
59
60
  if subject.target == @root_klass
60
61
  raise PgSerializable::AssociationError.new("class #{@root_klass} contains a cycle in nested association #{subject.klass}")
61
62
  end
@@ -14,17 +14,6 @@ Gem::Specification.new do |spec|
14
14
  spec.homepage = "https://github.com/matthewjf/pg_serializable"
15
15
  spec.license = "MIT"
16
16
 
17
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
18
- # to allow pushing to a single host or delete this section to allow pushing to any host.
19
- # if spec.respond_to?(:metadata)
20
- # spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
21
- # else
22
- # raise "RubyGems 2.0 or newer is required to protect against " \
23
- # "public gem pushes."
24
- # end
25
-
26
- # Specify which files should be added to the gem when it is released.
27
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
28
17
  spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
29
18
  `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
30
19
  end
@@ -33,10 +22,15 @@ Gem::Specification.new do |spec|
33
22
  spec.require_paths = ["lib"]
34
23
 
35
24
  spec.add_development_dependency "bundler", "~> 1.16"
25
+ spec.add_development_dependency "database_cleaner"
26
+ spec.add_development_dependency "factory_bot"
27
+ spec.add_development_dependency "ffaker"
28
+ spec.add_development_dependency "pry"
36
29
  spec.add_development_dependency "rake", "~> 10.0"
37
30
  spec.add_development_dependency "rspec", "~> 3.0"
38
31
 
39
32
  spec.add_runtime_dependency "activesupport", "~> 5.2"
40
33
  spec.add_runtime_dependency "activerecord", "~> 5.2"
34
+ spec.add_runtime_dependency "pg", ">= 1.1"
41
35
  spec.add_runtime_dependency "oj", "~> 3.6"
42
36
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pg_serializable
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.0
4
+ version: 1.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - matthewjf
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-04-16 00:00:00.000000000 Z
11
+ date: 2019-05-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -24,6 +24,62 @@ dependencies:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.16'
27
+ - !ruby/object:Gem::Dependency
28
+ name: database_cleaner
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: factory_bot
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: '0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ - !ruby/object:Gem::Dependency
56
+ name: ffaker
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: '0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: pry
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '0'
27
83
  - !ruby/object:Gem::Dependency
28
84
  name: rake
29
85
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +136,20 @@ dependencies:
80
136
  - - "~>"
81
137
  - !ruby/object:Gem::Version
82
138
  version: '5.2'
139
+ - !ruby/object:Gem::Dependency
140
+ name: pg
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '1.1'
146
+ type: :runtime
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '1.1'
83
153
  - !ruby/object:Gem::Dependency
84
154
  name: oj
85
155
  requirement: !ruby/object:Gem::Requirement