drillbit 2.7.0 → 2.8.0

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
  SHA1:
3
- metadata.gz: 04148bb5142b9ebae181f0df4b525fe3e8f3b10d
4
- data.tar.gz: b6d1b458eac0fbee1f82e4d97126e8508cd87611
3
+ metadata.gz: fec9e9fdc03cb3d4b5ec5977ba97e7732979d35e
4
+ data.tar.gz: 1eb9aeaa0634e5d47e6a6c80e95fbc2124e08900
5
5
  SHA512:
6
- metadata.gz: 27c3ce833d7b7a4e1702fbef09fa934fc41436dcb98fae84b585c64fbe06a2a9b36423436a50b10a702bfb1066d289515ec02884913c18f3bc5dcc79f22e70fc
7
- data.tar.gz: 00ff0dc854ec766993494a467c32700f459afdd64a4a8c8a11613c51a1d21ebc4753dc47e191fbbb8f6c813b8d669f70ae638ae9aea57890bb0290cef2f3d471
6
+ metadata.gz: 86d163daf5b5523fa2d156f093a8ea257591e15ae155138a6c6b147fb9e34eb8c11d3cfb136481f8cc0f40c932a456c7514caae7ad5c64e6effe92191e733eb0
7
+ data.tar.gz: 00471ebf723e9042d801d66e2dfa27847bb7a11b3314a57c391d99402cfdc3b0486652555b466ea55fa80ad8803765f642cbdc1fc702a7fe7984028c64a9cba1
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -101,7 +101,7 @@ module AuthorizableResource
101
101
  call
102
102
  end
103
103
 
104
- # rubocop:disable Metrics/AbcSize
104
+ # rubocop:disable Metrics/AbcSize, Metrics/PerceivedComplexity
105
105
  def authorized_attributes
106
106
  @authorized_attributes ||= begin
107
107
  attributes = authorized_params.
@@ -114,11 +114,20 @@ module AuthorizableResource
114
114
  fetch(:data, {}).
115
115
  fetch(:relationships, authorized_params.class.new).
116
116
  each_pair do |name, relationship|
117
-
118
117
  if relationship[:data].is_a?(Array)
119
- attribute = "#{Drillbit::Utilities::String.singularize(name)}_ids".to_sym
118
+ if (relationship[:data][0] || {})[:attributes]
119
+ relationships["#{name}_attributes"] = relationship[:data].map do |datum|
120
+ attrs = datum[:attributes].dup
121
+
122
+ attrs.delete(:__id__)
123
+
124
+ attrs
125
+ end
126
+ else
127
+ attribute = "#{Drillbit::Utilities::String.singularize(name)}_ids".to_sym
120
128
 
121
- relationships[attribute] = relationship[:data].map { |datum| datum[:id] }
129
+ relationships[attribute] = relationship[:data].map { |datum| datum[:id] }
130
+ end
122
131
  elsif relationship[:data].nil? || relationship[:data].is_a?(Hash)
123
132
  attribute = name.to_sym
124
133
 
@@ -131,7 +140,7 @@ module AuthorizableResource
131
140
  end
132
141
  end
133
142
  end
134
- # rubocop:enable Style/EmptyLinesAroundBlockBody, Metrics/AbcSize
143
+ # rubocop:enable Metrics/AbcSize, Metrics/PerceivedComplexity
135
144
 
136
145
  def authorized_resource
137
146
  return nil if RESOURCE_COLLECTION_ACTIONS.include?(action_name)
@@ -51,19 +51,37 @@ class Resource < Authorizers::Parameters
51
51
  end
52
52
  end
53
53
 
54
- def add_authorized_relationship(name)
55
- param = params.
56
- fetch(:data, {}).
57
- fetch(:relationships, {}).
58
- fetch(name, {}).
59
- fetch(:data, nil)
54
+ # rubocop:disable Metrics/AbcSize
55
+ def add_authorized_relationship(name, embedded_attributes: {})
56
+ param = params.
57
+ fetch(:data, {}).
58
+ fetch(:relationships, {}).
59
+ fetch(name, {}).
60
+ fetch(:data, nil)
61
+ first = params.
62
+ fetch(:data, {}).
63
+ fetch(:relationships, {}).
64
+ fetch(name, {}).
65
+ fetch(:data, []).
66
+ first || {}
67
+ embedded = first.fetch(:attributes, nil)
60
68
 
61
69
  if param.nil?
62
70
  authorized_params[6][:data][2][:relationships][name] = [:data]
71
+ elsif embedded
72
+ authorized_params[6][:data][2][:relationships][name] = {
73
+ data: [
74
+ :type,
75
+ {
76
+ attributes: %i{__id__} + embedded_attributes,
77
+ },
78
+ ],
79
+ }
63
80
  else
64
81
  authorized_params[6][:data][2][:relationships][name] = { data: %i{type id} }
65
82
  end
66
83
  end
84
+ # rubocop:enable Metrics/AbcSize
67
85
 
68
86
  def add_authorized_relationships(*names)
69
87
  names.each do |name|
@@ -59,7 +59,16 @@ class ParameterParser
59
59
  return parameters unless parameters.is_a? Hash
60
60
 
61
61
  parameters.each_with_object({}) do |(key, value), hash|
62
- value = underscore_parameters(value) if value.is_a? Hash
62
+ value = case value
63
+ when Hash
64
+ underscore_parameters(value)
65
+ when Array
66
+ value.map do |item|
67
+ underscore_parameters(item)
68
+ end
69
+ else
70
+ value
71
+ end
63
72
 
64
73
  hash[Drillbit::Utilities::String.underscore(key)] = value
65
74
  end
@@ -19,6 +19,7 @@ class String
19
19
  [/^(m|l)ice$/i, '\1ouse'],
20
20
  [/(x|ch|ss|sh)es$/i, '\1'],
21
21
  [/(m)ovies$/i, '\1ovie'],
22
+ [/(child)ren$/i, '\1'],
22
23
  [/(s)eries$/i, '\1eries'],
23
24
  [/([^aeiouy]|qu)ies$/i, '\1y'],
24
25
  [/([lr])ves$/i, '\1f'],
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Drillbit
3
- VERSION = '2.7.0'
3
+ VERSION = '2.8.0'
4
4
  end
@@ -96,7 +96,15 @@ describe ParameterParser do
96
96
  "quad": {
97
97
  "another-level": "whoa inception"
98
98
  }
99
- }
99
+ },
100
+ "quint": [
101
+ {
102
+ "quint-it-quit": "mc-dipple"
103
+ },
104
+ {
105
+ "quint-it-quit": "big-maccle"
106
+ }
107
+ ]
100
108
  }
101
109
  HEREDOC
102
110
  }
@@ -112,6 +120,14 @@ describe ParameterParser do
112
120
  'another_level' => 'whoa inception',
113
121
  },
114
122
  },
123
+ 'quint' => [
124
+ {
125
+ 'quint_it_quit' => 'mc-dipple',
126
+ },
127
+ {
128
+ 'quint_it_quit' => 'big-maccle',
129
+ },
130
+ ],
115
131
  )
116
132
  end
117
133
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: drillbit
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.7.0
4
+ version: 2.8.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - thegranddesign
@@ -31,7 +31,7 @@ cert_chain:
31
31
  zRIv8lqQM8QFT76rzP5SBCERwN+ltKAFbQ5/FwmZNGWYnmCP3RZMQiRnbh+9H9lh
32
32
  mlbwaYZTjgsXq6cy8N38EecewgBbZYS1IYJraE/M
33
33
  -----END CERTIFICATE-----
34
- date: 2016-10-23 00:00:00.000000000 Z
34
+ date: 2016-10-28 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: erratum
metadata.gz.sig CHANGED
Binary file