pack_api 1.0.4 → 1.0.6

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: 91807c3325db138316580a060e86626a03f7ebc9a4025d673a8144d9faf768e8
4
- data.tar.gz: 22f935038e02720fd46351e96d7c379f40b25c4c930594e3f848b1440769cf8b
3
+ metadata.gz: 60e98dc35dc970a330d8389e332c79e0b88a0286260603f1a06607be9aeae8f8
4
+ data.tar.gz: 8f5293317ca533dfa471394a47967eb8a8d3af568e1d3f27fe544cd9251c304b
5
5
  SHA512:
6
- metadata.gz: 9c268b476a6c26f6832cb365ac01084309d4644f75a82cccde62223b70a19feda093971266bf620d20d97744e5e28ead4a9e72a778182c55c86b51dfb77f41d1
7
- data.tar.gz: 8d4376d38175ed100ed4aee1ed432f6812ecca77da984e202a91b7dd465d85c5f7bdcd5156830a9ce5510cf45417cab006aa3f84a6685a16ee472f413ada94f5
6
+ metadata.gz: ff0d306e37c0e1bd186cad1c71bfe992c41f22f9f2717aa4072b70734e4a1ad867af985e8732085eb1c8e2a3410ec9cc39a62496e62e26b5bf1816245b9cf79e
7
+ data.tar.gz: 339a131ff33b1e817d1c18b7ac1ca948a5bc3355837d90f4f9b7a8596da88a0452decacbf518d23f525f27a91cc44d8c23e100dcf1b5c6753cbdd0a409d8b7dd
@@ -35,7 +35,7 @@ module PackAPI::Mapping
35
35
 
36
36
  # prevent api_attributes from being used unless they are in the public type definition
37
37
  unless mappings.key?(api_attribute)
38
- raise ActiveModel::UnknownAttributeError.new(@model_type.name, api_attribute)
38
+ raise PackAPI::InternalError.new("unknown attribute '#{api_attribute}' for #{@model_type.name}.")
39
39
  end
40
40
 
41
41
  mappings[api_attribute]
@@ -68,6 +68,10 @@ module PackAPI::Mapping
68
68
  collection_associations.include?(model_attribute)
69
69
  end
70
70
 
71
+ def accepts_nested_attributes_for?(association_name)
72
+ model_type.nested_attributes_options.key?(association_name)
73
+ end
74
+
71
75
  def resource_associations
72
76
  @resource_associations ||= model_type.reflect_on_all_associations
73
77
  .reject(&:collection?)
@@ -81,7 +85,9 @@ module PackAPI::Mapping
81
85
  end
82
86
 
83
87
  def normalize_association_reference(api_attribute, model_attribute)
84
- if resource_association?(model_attribute)
88
+ if accepts_nested_attributes_for?(model_attribute)
89
+ api_attribute
90
+ elsif resource_association?(model_attribute)
85
91
  normalize_resource_association_reference(api_attribute)
86
92
  elsif collection_association?(model_attribute)
87
93
  normalize_collection_association_reference(api_attribute)
@@ -9,6 +9,7 @@ module PackAPI::Mapping
9
9
  super
10
10
  @optional_attributes_to_include = nil
11
11
  @model_attributes_of_interest = nil
12
+ @api_attributes_of_interest = nil
12
13
  end
13
14
 
14
15
  def execute
@@ -23,6 +24,10 @@ module PackAPI::Mapping
23
24
 
24
25
  protected
25
26
 
27
+ def api_attribute_names
28
+ api_attributes_of_interest || api_type.attribute_names
29
+ end
30
+
26
31
  def include_api_attribute?(api_attribute)
27
32
  !optional_api_attribute?(api_attribute) || include_optional_api_attribute?(api_attribute)
28
33
  end
@@ -31,6 +36,10 @@ module PackAPI::Mapping
31
36
  @model_attributes_of_interest ||= options[:model_attributes_of_interest]
32
37
  end
33
38
 
39
+ def api_attributes_of_interest
40
+ @api_attributes_of_interest ||= options[:api_attributes_of_interest]
41
+ end
42
+
34
43
  def optional_attributes_to_include
35
44
  @optional_attributes_to_include ||= options[:optional_attributes]
36
45
  end
@@ -40,6 +49,7 @@ module PackAPI::Mapping
40
49
  end
41
50
 
42
51
  def include_optional_api_attribute?(api_attribute_name)
52
+ return true if api_attributes_of_interest && api_attributes_of_interest.include?(api_attribute_name)
43
53
  return false if optional_attributes_to_include.nil?
44
54
  return false if optional_attributes_to_include.respond_to?(:exclude?) &&
45
55
  optional_attributes_to_include.exclude?(api_attribute_name)
@@ -48,7 +58,7 @@ module PackAPI::Mapping
48
58
  end
49
59
 
50
60
  def include_model_attribute?(model_attribute)
51
- return true if model_attributes_of_interest.blank?
61
+ return true if model_attributes_of_interest.nil?
52
62
 
53
63
  model_attributes_of_interest.include?(model_attribute)
54
64
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module PackAPI
4
- VERSION = "1.0.4"
4
+ VERSION = "1.0.6"
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: pack_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 1.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Flytedesk