graphiti 1.0.beta.22 → 1.0.beta.23

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: 8e5cc04af9bfdafe229a379fd1c5b3016cfc2e2f
4
- data.tar.gz: b45b8a34cd3e066c0861fb9bdf1dfb0cdb1d8a05
3
+ metadata.gz: 5164c4331d341b2fe6b4d9f52a585ea5786e9322
4
+ data.tar.gz: 99ff186f3f6a4664655df31218314b12eab85dcf
5
5
  SHA512:
6
- metadata.gz: 80ea382d0120b44c2d59ec559a17c98274bcad560a5f5863a5b62e33a813e36f247b9949f55a0b46c464bba31f67e4d079e69a33d7e69ee1eb74eca00dc8e91d
7
- data.tar.gz: fbfff29b988d97ba4b874cfa983e0d056dc9cd3a05209326665e35722b4f435470866316c6e844d9119373c154d92a10b5935d688c3b8d548aa1712a82f6a925
6
+ metadata.gz: ef17a7f6650df3b05dca832352c742869d220a197fae136c924cd2955fd74da03e378877638f57075a72f8090c03c1e5e905b96952dd9d8f1bac6749a1f7c5d9
7
+ data.tar.gz: 9479832a9998c6e24795f9040795239147659faaa6f25d6bedd1d1b5bf32c3c08d3f70d64b3ee708ecd8488b616abbf7ec9bbffb0289225d4e86713ab7fb7a43
data/.travis.yml CHANGED
@@ -1,14 +1,18 @@
1
1
  sudo: false
2
2
  language: ruby
3
3
  rvm:
4
- - 2.3
5
4
  - 2.4
6
5
  - 2.5
6
+ - 2.6
7
7
 
8
8
  script: "bundle exec rake"
9
9
 
10
10
  install: bundle install --retry=3 --jobs=3
11
11
 
12
+ #https://docs.travis-ci.com/user/languages/ruby/
13
+ before_install:
14
+ - gem install bundler -v '< 2'
15
+
12
16
  gemfile:
13
17
  - gemfiles/rails_4.gemfile
14
18
  - gemfiles/rails_5.gemfile
data/graphiti.gemspec CHANGED
@@ -27,7 +27,7 @@ Gem::Specification.new do |spec|
27
27
 
28
28
  spec.add_development_dependency "activerecord", ['>= 4.1', '< 6']
29
29
  spec.add_development_dependency "kaminari", '~> 0.17'
30
- spec.add_development_dependency "bundler", "~> 1.12"
30
+ spec.add_development_dependency "bundler"
31
31
  spec.add_development_dependency "rake", "~> 10.0"
32
32
  spec.add_development_dependency "sqlite3"
33
33
  spec.add_development_dependency "database_cleaner"
@@ -78,7 +78,10 @@ module Graphiti
78
78
  end
79
79
 
80
80
  def generate_route
81
- code = "resources :#{plural_route_name}"
81
+ # Rails 5.2 adds `plural_route_name`, fallback to `plural_table_name`
82
+ plural_name = self.try(:plural_route_name) || plural_table_name
83
+
84
+ code = "resources :#{plural_name}"
82
85
  code << %{, only: [#{actions.map { |a| ":#{a}" }.join(', ')}]} if actions.length < 5
83
86
  code << "\n"
84
87
  inject_into_file 'config/routes.rb', after: /ApplicationResource.*$\n/ do
@@ -28,7 +28,8 @@ module Graphiti
28
28
  self.debug_models = ENV.fetch('GRAPHITI_DEBUG_MODELS', false)
29
29
 
30
30
  if defined?(::Rails)
31
- @schema_path = "#{::Rails.root}/public/schema.json"
31
+ cfg = YAML.load_file("#{::Rails.root}/.graphiticfg.yml")
32
+ @schema_path = "#{::Rails.root}/public#{cfg['namespace']}/schema.json"
32
33
  self.debug = ::Rails.logger.level.zero?
33
34
  Graphiti.logger = ::Rails.logger
34
35
  end
@@ -162,8 +162,11 @@ class Graphiti::Util::Persistence
162
162
  iterate(except: [:polymorphic_belongs_to, :belongs_to]) do |x|
163
163
  yield x
164
164
 
165
- x[:object] = x[:sideload].resource
166
- .persist_with_relationships(x[:meta], x[:attributes], x[:relationships], caller_model)
165
+ if x[:sideload].writable?
166
+ x[:object] = x[:resource]
167
+ .persist_with_relationships(x[:meta], x[:attributes], x[:relationships], caller_model)
168
+ end
169
+
167
170
  processed << x
168
171
  end
169
172
  end
@@ -173,7 +176,7 @@ class Graphiti::Util::Persistence
173
176
  [].tap do |processed|
174
177
  iterate(only: [:polymorphic_belongs_to, :belongs_to]) do |x|
175
178
  if x[:sideload].writable?
176
- x[:object] = x[:sideload].resource
179
+ x[:object] = x[:resource]
177
180
  .persist_with_relationships(x[:meta], x[:attributes], x[:relationships])
178
181
  else
179
182
  raise Graphiti::Errors::UnwritableRelationship.new(@resource, x[:sideload])
@@ -45,12 +45,21 @@ module Graphiti
45
45
  def payload_for(sideload, relationship_payload)
46
46
  type = relationship_payload[:meta][:jsonapi_type].to_sym
47
47
 
48
- if sideload.resource.type != type && sideload.polymorphic_parent?
48
+ # For polymorphic *sideloads*, grab the correct child sideload
49
+ if sideload.resource.type != type && sideload.type == :polymorphic_belongs_to
49
50
  sideload = sideload.child_for_type(type)
50
51
  end
52
+
53
+ # For polymorphic *resources*, grab the correct child resource
54
+ resource = sideload.resource
55
+ if resource.type != type && resource.polymorphic?
56
+ resource = resource.class.resource_for_type(type).new
57
+ end
58
+
51
59
  relationship_payload[:meta][:method] ||= :update
52
60
 
53
61
  {
62
+ resource: resource,
54
63
  sideload: sideload,
55
64
  is_polymorphic: sideload.polymorphic_child?,
56
65
  primary_key: sideload.primary_key,
@@ -1,3 +1,3 @@
1
1
  module Graphiti
2
- VERSION = "1.0.beta.22"
2
+ VERSION = "1.0.beta.23"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphiti
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.beta.22
4
+ version: 1.0.beta.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - Lee Richmond
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2018-12-28 00:00:00.000000000 Z
11
+ date: 2019-01-06 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: jsonapi-serializable
@@ -124,16 +124,16 @@ dependencies:
124
124
  name: bundler
125
125
  requirement: !ruby/object:Gem::Requirement
126
126
  requirements:
127
- - - "~>"
127
+ - - ">="
128
128
  - !ruby/object:Gem::Version
129
- version: '1.12'
129
+ version: '0'
130
130
  type: :development
131
131
  prerelease: false
132
132
  version_requirements: !ruby/object:Gem::Requirement
133
133
  requirements:
134
- - - "~>"
134
+ - - ">="
135
135
  - !ruby/object:Gem::Version
136
- version: '1.12'
136
+ version: '0'
137
137
  - !ruby/object:Gem::Dependency
138
138
  name: rake
139
139
  requirement: !ruby/object:Gem::Requirement