iknow_view_models 3.4.3 → 3.4.4

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: 3560a98616dd2f0548ac7e663827e68d86fa9991969ac6ee49633a0090e7d628
4
- data.tar.gz: deec44e5132f91dfc1deef0dd889ee20c1b01c6d5d7791d356f1e9dc99ec1c8a
3
+ metadata.gz: 2845e303fc1acc67f0241e30586c39276f08720a824104f71416a5b9d63a8989
4
+ data.tar.gz: ae89dde77c602debb67793bc36a120739c6692802e227d1835f972b0d72f542f
5
5
  SHA512:
6
- metadata.gz: 5af2b38b2e8fb8805480bd665ea24e7ad4b489951c8b72660e502a053a945798f18269b60991eb416ab6959fc46e4831a911a15005810b57e288e2eeaaf37fd5
7
- data.tar.gz: 5a73108237e3ffae5751f50a6e693e8fd737a4d1936f087095138ec2db47cbd7ec852f81e6ef881f794a38d67ba85429825b2393a850c149f363121f321adf30
6
+ metadata.gz: 808e3772112084fb81efeb7b0229ec461d4318b2f74460e01e94cd4c57c197b6c10b1fe6b0c02f0efa995d9b27209d08de8a98ed2991b270387cdc2b7a6520b4
7
+ data.tar.gz: 6ffed3458c0a92ddc8a49580073bbc6827eed7be49b1c605ed7708fc995185c825df57d583fd27305d45b4425b806faf0655a81a3eb7be5f9f64cdec9d09dedc
@@ -8,7 +8,7 @@ Gem::Specification.new do |spec|
8
8
  spec.name = 'iknow_view_models'
9
9
  spec.version = IknowViewModels::VERSION
10
10
  spec.authors = ['iKnow Team']
11
- spec.email = ['edge@iknow.jp']
11
+ spec.email = ['systems@iknow.jp']
12
12
  spec.summary = 'ViewModels provide a means of encapsulating a collection of related data and specifying its JSON serialization.'
13
13
  spec.description = ''
14
14
  spec.homepage = 'https://github.com/iknow/cerego_view_models'
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module IknowViewModels
4
- VERSION = '3.4.3'
4
+ VERSION = '3.4.4'
5
5
  end
@@ -395,10 +395,10 @@ module ViewModel::ActiveRecord::AssociationManipulation
395
395
  def check_association_type!(association_data, type)
396
396
  if type && !association_data.accepts?(type)
397
397
  raise ViewModel::SerializationError.new(
398
- "Type error: association '#{direct_reflection.name}' can't refer to viewmodel #{type.view_name}")
398
+ "Type error: association '#{association_data.association_name}' can't refer to viewmodel #{type.view_name}")
399
399
  elsif association_data.polymorphic? && !type
400
400
  raise ViewModel::SerializationError.new(
401
- "Need to specify target viewmodel type for polymorphic association '#{direct_reflection.name}'")
401
+ "Need to specify target viewmodel type for polymorphic association '#{association_data.association_name}'")
402
402
  end
403
403
  end
404
404
  end
@@ -52,22 +52,23 @@ class ViewModel::ActiveRecord::Cloner
52
52
  new_associated = associated
53
53
  else
54
54
  # Otherwise descend into the child, and attach the result
55
- vm_class =
56
- case
57
- when association_data.through?
58
- # descend into the synthetic join table viewmodel
59
- association_data.direct_viewmodel
60
- when association_data.collection?
61
- association_data.viewmodel_class
62
- else
63
- association_data.viewmodel_class_for_model!(associated.class)
64
- end
55
+ build_vm = ->(model) do
56
+ vm_class =
57
+ if association_data.through?
58
+ # descend into the synthetic join table viewmodel
59
+ association_data.direct_viewmodel
60
+ else
61
+ association_data.viewmodel_class_for_model!(model.class)
62
+ end
63
+
64
+ vm_class.new(model)
65
+ end
65
66
 
66
67
  new_associated =
67
68
  if ViewModel::Utils.array_like?(associated)
68
- associated.map { |m| clone(vm_class.new(m)) }.compact
69
+ associated.map { |m| clone(build_vm.(m)) }.compact
69
70
  else
70
- clone(vm_class.new(associated))
71
+ clone(build_vm.(associated))
71
72
  end
72
73
  end
73
74
  end
@@ -75,8 +75,13 @@ module ViewModel::Controller
75
75
  protected
76
76
 
77
77
  def parse_viewmodel_updates
78
- update_hash = _extract_update_data(params.fetch(:data))
79
- refs = _extract_param_hash(params.fetch(:references, {}))
78
+ data_param = params.fetch(:data) do
79
+ raise ViewModel::Error.new(status: 400, detail: "Missing 'data' parameter")
80
+ end
81
+ refs_param = params.fetch(:references, {})
82
+
83
+ update_hash = _extract_update_data(data_param)
84
+ refs = _extract_param_hash(refs_param)
80
85
 
81
86
  return update_hash, refs
82
87
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iknow_view_models
3
3
  version: !ruby/object:Gem::Version
4
- version: 3.4.3
4
+ version: 3.4.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - iKnow Team
@@ -362,7 +362,7 @@ dependencies:
362
362
  version: '0'
363
363
  description: ''
364
364
  email:
365
- - edge@iknow.jp
365
+ - systems@iknow.jp
366
366
  executables: []
367
367
  extensions: []
368
368
  extra_rdoc_files: []