graphiti-activegraph 0.1.4 → 0.1.9

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
  SHA256:
3
- metadata.gz: 414cf4ca5fa4c6027a87a9af43c47041ffee42b746ab148b29ffc2dc452fcda9
4
- data.tar.gz: 952da258c8b891c1165e26a13ac6c4c2a8377842a5c353d8a1d329d91b2f0c26
3
+ metadata.gz: f6f5689742540eacd7c8d5af6c94d69deca502eaf16b1e5d4c69c4e6bb34ad88
4
+ data.tar.gz: 8f0cdad94dc592a5496ac839abea4727422cd1b09a2dd5fe8df908a2a3422106
5
5
  SHA512:
6
- metadata.gz: 50e809c41a2ccbdade72af95a4391102fb204ede9a0477149fa4810112c379d301f8807046d5a44362cc6a68c4b22c5932b2f1b45478b63a9f2e8afb1df66c16
7
- data.tar.gz: 7bd4274635d96ccdd65fb2d041efb12a1df07042d8a207218af1d13c91c4e8beb067c2bffecc20c9f5e0ceeccc9cf965d14f30fa14e36eefbfc23a752947ab90
6
+ metadata.gz: 9bde7647cac6007c4378c427c494c3d67a3d838794189c82f347c89ce1a3916c18de66a39aee01f7b3fd1ec65130d956ef3733ce460084cc64731c4ff3127cfe
7
+ data.tar.gz: b563699ee2c31d298c10ac0fe70a63100f75b196c24fddc2abc44f0225f5087267ff6e8ff6fddd508ea6fbf06eded19a85b4f1decc2e5f9dc1c744c670d14fd4
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --require spec_helper
data/.travis.yml ADDED
@@ -0,0 +1,10 @@
1
+ ---
2
+ dist: xenial
3
+ language: ruby
4
+ jdk:
5
+ - openjdk11
6
+ cache: bundler
7
+ rvm:
8
+ - 2.7.1
9
+ - jruby-9.2.13.0
10
+ script: 'bundle exec rspec'
data/CHANGELOG.md ADDED
@@ -0,0 +1,15 @@
1
+ ## Unreleased
2
+
3
+ -
4
+
5
+ ## 0.1.8 (09-06-2021)
6
+
7
+ Features:
8
+
9
+ - Added support for polymorphic relationship.
10
+
11
+ <!-- ### [version (DD-MM-YYYY)](diff_link) -->
12
+ <!-- Breaking changes:-->
13
+ <!-- Features:-->
14
+ <!-- Fixes:-->
15
+ <!-- Misc:-->
data/Gemfile CHANGED
@@ -9,4 +9,5 @@ group :test do
9
9
  gem "appraisal"
10
10
  gem "guard"
11
11
  gem "guard-rspec"
12
+ gem "rspec"
12
13
  end
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2020 Hardik Joshi
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
@@ -30,4 +30,5 @@ Gem::Specification.new do |spec|
30
30
  spec.add_development_dependency "activemodel", ">= 4.1"
31
31
  spec.add_development_dependency "graphiti_spec_helpers", "1.0.beta.4"
32
32
  spec.add_development_dependency "standard"
33
+ spec.add_development_dependency "rspec", "~> 3.9.0"
33
34
  end
@@ -4,7 +4,9 @@ module Graphiti::ActiveGraph
4
4
  def self.sideloading_classes
5
5
  {
6
6
  has_many: Graphiti::ActiveGraph::Adapters::ActiveGraph::HasManySideload,
7
- has_one: Graphiti::ActiveGraph::Adapters::ActiveGraph::HasOneSideload
7
+ has_one: Graphiti::ActiveGraph::Adapters::ActiveGraph::HasOneSideload,
8
+ polymorphic_belongs_to: Graphiti::ActiveGraph::Adapters::ActiveGraph::PolymorphicBelongsTo,
9
+ belongs_to: Graphiti::ActiveGraph::Adapters::ActiveGraph::HasOneSideload,
8
10
  }
9
11
  end
10
12
 
@@ -15,13 +17,17 @@ module Graphiti::ActiveGraph
15
17
  def assign_attributes(model_instance, attributes)
16
18
  model_instance.before_assign_resource_attr if model_instance.respond_to?(:before_assign_resource_attr)
17
19
 
18
- attributes.each_pair do |k, v|
19
- model_instance.send(:"#{k}=", v) if model_instance.respond_to?(:"#{k}=")
20
- end
20
+ # currently there is no possible way to assign association on activegraph without triggering save
21
+ # https://github.com/neo4jrb/activegraph/issues/1445
22
+ # using "=" operator bypasses validations and callbacks in case of associations
23
+ # once above issue is fixed, we can change the below code to assign instead of update
24
+
25
+ model_instance.update(attributes)
21
26
  end
22
27
 
23
- def paginate(scope, current_page, per_page)
24
- scope.skip((current_page - 1) * per_page).limit(per_page)
28
+ def paginate(scope, current_page, per_page, offset)
29
+ offset ||= (current_page - 1) * per_page
30
+ scope.skip(offset).limit(per_page)
25
31
  end
26
32
 
27
33
  def transaction(_model_class)
@@ -43,7 +49,7 @@ module Graphiti::ActiveGraph
43
49
  end
44
50
 
45
51
  def save(model_instance)
46
- model_instance.save
52
+ model_instance.save if model_instance.changed?
47
53
  model_instance
48
54
  end
49
55
 
@@ -0,0 +1,15 @@
1
+ class Graphiti::ActiveGraph::Adapters::ActiveGraph::PolymorphicBelongsTo < Graphiti::Sideload::PolymorphicBelongsTo
2
+ include Graphiti::ActiveGraph::Adapters::ActiveGraph::Sideload
3
+
4
+ def default_base_scope
5
+ resource_class.model.all
6
+ end
7
+
8
+ def infer_foreign_key
9
+ association_name.to_sym
10
+ end
11
+
12
+ def default_value_when_empty
13
+ nil
14
+ end
15
+ end
@@ -25,6 +25,9 @@ module Graphiti
25
25
  runner = ::Graphiti::Runner.new(self, params)
26
26
  runner.proxy(nil, raise_on_missing: false, preloaded: obj_arr)
27
27
  end
28
+
29
+ def guard_nil_id!(params)
30
+ end
28
31
  end
29
32
 
30
33
  module ResourceInstanceMethods
@@ -57,7 +57,7 @@ module Graphiti::ActiveGraph
57
57
  original = Graphiti.context[:namespace]
58
58
  begin
59
59
  Graphiti.context[:namespace] = action
60
- ::Graphiti::RequestValidator.new(@resource, @payload.params).validate!
60
+ ::Graphiti::RequestValidator.new(@resource, @payload.params, action).validate!
61
61
  validator = persist {
62
62
  @resource.persist_with_relationships \
63
63
  @payload.meta(action: action),
@@ -6,7 +6,7 @@ module Graphiti::ActiveGraph
6
6
  @query = query
7
7
  @action = action
8
8
 
9
- validator = ::Graphiti::RequestValidator.new(jsonapi_resource, params)
9
+ validator = ::Graphiti::RequestValidator.new(jsonapi_resource, params, action)
10
10
 
11
11
  validator.validate! unless params[:skip_render_val]
12
12
 
@@ -1,23 +1,6 @@
1
1
  module Graphiti::ActiveGraph
2
2
  module SideloadResolve
3
3
  def resolve_sideloads(parents)
4
- @query.sideloads.each_pair do |name, q|
5
- sideload = @resource.class.sideload(name)
6
- next if sideload.nil? || sideload.shared_remote?
7
-
8
- if sideload.assign_each_proc
9
- Array.wrap(parents).each do |parent|
10
- children = sideload.assign_each_proc.call(parent) || sideload.default_value_when_empty
11
-
12
- # currently there is no possible way to assign association on activegraph without triggering save
13
- # https://github.com/neo4jrb/activegraph/issues/1445
14
- # as a workaround we are using instance variable here to store and retrive associations
15
- # once above issue is fixed use that fix to assign the association here
16
- # and also remove 1) this code and 2) SerializerRelationship#data_proc
17
- parent.instance_variable_set("@graphiti_render_#{name}", { data: children })
18
- end
19
- end
20
- end
21
4
  end
22
5
  end
23
6
  end
@@ -6,11 +6,10 @@ module Graphiti::ActiveGraph
6
6
  ->(_) {
7
7
  # use custom assigned sideload if it is specified via "assign_each_proc"
8
8
  # otherwise retrieve sideload using normal getter on parent object
9
- custom_assigned_sideload = @object.instance_variable_get("@graphiti_render_#{sideload_ref.association_name}")
10
- records = if custom_assigned_sideload.blank?
11
- @object.public_send(sideload_ref.association_name)
9
+ records = if custom_proc = sideload_ref.assign_each_proc
10
+ custom_proc.call(@object)
12
11
  else
13
- custom_assigned_sideload[:data]
12
+ @object.public_send(sideload_ref.association_name)
14
13
  end
15
14
 
16
15
  if records
@@ -1,5 +1,5 @@
1
1
  module Graphiti
2
2
  module ActiveGraph
3
- VERSION = '0.1.4'
3
+ VERSION = '0.1.9'
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: graphiti-activegraph
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.1.9
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hardik Joshi
8
- autorequire:
8
+ autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2020-10-01 00:00:00.000000000 Z
11
+ date: 2021-06-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: graphiti
@@ -164,7 +164,21 @@ dependencies:
164
164
  - - ">="
165
165
  - !ruby/object:Gem::Version
166
166
  version: '0'
167
- description:
167
+ - !ruby/object:Gem::Dependency
168
+ name: rspec
169
+ requirement: !ruby/object:Gem::Requirement
170
+ requirements:
171
+ - - "~>"
172
+ - !ruby/object:Gem::Version
173
+ version: 3.9.0
174
+ type: :development
175
+ prerelease: false
176
+ version_requirements: !ruby/object:Gem::Requirement
177
+ requirements:
178
+ - - "~>"
179
+ - !ruby/object:Gem::Version
180
+ version: 3.9.0
181
+ description:
168
182
  email:
169
183
  - hardikjoshi1991@gmail.com
170
184
  executables: []
@@ -172,12 +186,17 @@ extensions: []
172
186
  extra_rdoc_files: []
173
187
  files:
174
188
  - ".gitignore"
189
+ - ".rspec"
190
+ - ".travis.yml"
191
+ - CHANGELOG.md
175
192
  - Gemfile
193
+ - LICENSE.txt
176
194
  - graphiti-activegraph.gemspec
177
195
  - lib/graphiti-activegraph.rb
178
196
  - lib/graphiti/active_graph/adapters/active_graph.rb
179
197
  - lib/graphiti/active_graph/adapters/active_graph/has_many_sideload.rb
180
198
  - lib/graphiti/active_graph/adapters/active_graph/has_one_sideload.rb
199
+ - lib/graphiti/active_graph/adapters/active_graph/polymorphic_belongs_to.rb
181
200
  - lib/graphiti/active_graph/adapters/active_graph/sideload.rb
182
201
  - lib/graphiti/active_graph/deserializer.rb
183
202
  - lib/graphiti/active_graph/query.rb
@@ -196,7 +215,7 @@ homepage: https://github.com/mrhardikjoshi/graphiti-activegraph
196
215
  licenses:
197
216
  - MIT
198
217
  metadata: {}
199
- post_install_message:
218
+ post_install_message:
200
219
  rdoc_options: []
201
220
  require_paths:
202
221
  - lib
@@ -211,9 +230,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
211
230
  - !ruby/object:Gem::Version
212
231
  version: '0'
213
232
  requirements: []
214
- rubyforge_project:
215
- rubygems_version: 2.7.6
216
- signing_key:
233
+ rubygems_version: 3.2.3
234
+ signing_key:
217
235
  specification_version: 4
218
236
  summary: Easily build jsonapi.org-compatible APIs for GraphDB
219
237
  test_files: []