drillbit 2.3.1 → 2.4.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: fc9fd8dac14b792d3bf485777b8e8623aa418d77
4
- data.tar.gz: 1f3fc94e276177ffd648a49b96f16ecc8f7a502b
3
+ metadata.gz: d29c3be0431dc83e7edb1c1cf2d0844b93ea086a
4
+ data.tar.gz: c5e5a28648fc56cd51731f5b698da2756bed6b86
5
5
  SHA512:
6
- metadata.gz: 9a68c37c4649c12bc286758b2c8e9c3f4ab389fab3224c5fafd0d3fd05fd5b5b92d414068c8eb80b29c61ed061ce6c463f0af3db9ca2c62a818464bb85515d7d
7
- data.tar.gz: 19dc7ef9360ea973b5fb53791a57cafe250bb2deb93b4a351acbd747690d8a64ab4598b6def32dbf5f1f65c8e07994b811e31e0d210358fbcec4c39b7c902ce8
6
+ metadata.gz: 2b471ef7bf9d5854779359cbe78a23c024fd2410abdc7a141c93796a084ebeec30c9fe05c3d9a0d05e8ef39b364d02d3ba4bf66253c7bee8009573f594246bcb
7
+ data.tar.gz: 81300a8c464efc2c6323319b2da243870f17b2f3acc17490c3bfe9b33d60d14c54c15d421f16d51ad7ab89ca0f61541dff161a69d6a032b4056ada9cc8d8b97c
checksums.yaml.gz.sig CHANGED
Binary file
data.tar.gz.sig CHANGED
Binary file
@@ -98,11 +98,37 @@ module AuthorizableResource
98
98
  call
99
99
  end
100
100
 
101
+ # rubocop:disable Style/EmptyLinesAroundBlockBody, Metrics/AbcSize
101
102
  def authorized_attributes
102
- @authorized_attributes ||= authorized_params.
103
- fetch(:data, {}).
104
- fetch(:attributes, {})
103
+ @authorized_attributes ||= begin
104
+ attributes = authorized_params.
105
+ fetch(:data, {}).
106
+ fetch(:attributes, authorized_params.class.new)
107
+
108
+ relationships = authorized_params.class.new
109
+
110
+ authorized_params.
111
+ fetch(:data, {}).
112
+ fetch(:relationships, authorized_params.class.new).
113
+ each_pair do |name, relationship|
114
+
115
+ if relationship[:data].is_a?(Array)
116
+ attribute = "#{Drillbit::Utilities::String.singularize(name)}_ids".to_sym
117
+
118
+ relationships[attribute] = relationship[:data].map { |datum| datum[:id] }
119
+ elsif relationship[:data].nil? || relationship[:data].is_a?(Hash)
120
+ attribute = name.to_sym
121
+
122
+ relationships[attribute] = relationship[:data][:id]
123
+ end
124
+ end
125
+
126
+ ActiveSupport::Deprecation.silence do
127
+ attributes.merge(relationships)
128
+ end
129
+ end
105
130
  end
131
+ # rubocop:enable Style/EmptyLinesAroundBlockBody, Metrics/AbcSize
106
132
 
107
133
  def authorized_resource
108
134
  return nil if RESOURCE_COLLECTION_ACTIONS.include?(action_name)
@@ -21,9 +21,7 @@ class Resource < Authorizers::Parameters
21
21
  attributes: [
22
22
  {},
23
23
  ],
24
- relationships: [
25
- {},
26
- ],
24
+ relationships: {},
27
25
  },
28
26
  ],
29
27
  ]
@@ -52,12 +50,13 @@ class Resource < Authorizers::Parameters
52
50
  param = params.
53
51
  fetch(:data, {}).
54
52
  fetch(:relationships, {}).
55
- fetch(name, nil)
53
+ fetch(name, {}).
54
+ fetch(:data, nil)
56
55
 
57
- if param.class == Array
58
- authorized_params[1][:data][2][:relationships][0][name] = []
56
+ if param.nil?
57
+ authorized_params[1][:data][2][:relationships][name] = [:data]
59
58
  else
60
- authorized_params[1][:data][2][:relationships] << name
59
+ authorized_params[1][:data][2][:relationships][name] = { data: %i{type id} }
61
60
  end
62
61
  end
63
62
 
@@ -2,6 +2,7 @@
2
2
  require 'json'
3
3
  require 'stringio'
4
4
  require 'drillbit/responses/invalid_request_body'
5
+ require 'drillbit/utilities/string'
5
6
 
6
7
  module Drillbit
7
8
  module Middleware
@@ -15,9 +16,12 @@ class ParameterParser
15
16
 
16
17
  if env['CONTENT_LENGTH'].to_i > 0 && env['CONTENT_TYPE'] =~ /json/
17
18
  if env['rack.input']
18
- env['rack.input'] = StringIO.new(underscore_request_parameters(env['rack.input']))
19
+ underscored_input = underscore_request_parameters(env['rack.input'])
20
+ env['rack.input'] = StringIO.new(underscored_input)
21
+ env['CONTENT_LENGTH'] = underscored_input.bytesize
19
22
  elsif env['RACK_INPUT']
20
- env['RACK_INPUT'] = underscore_request_parameters(env['RACK_INPUT'])
23
+ env['RACK_INPUT'] = underscore_request_parameters(env['RACK_INPUT'])
24
+ env['CONTENT_LENGTH'] = env['RACK_INPUT'].bytesize
21
25
  end
22
26
  end
23
27
 
@@ -39,7 +43,10 @@ class ParameterParser
39
43
  return query_string unless query_string.respond_to? :gsub
40
44
 
41
45
  query_string.gsub(/(?<=\A|&|\?)[^=&]+/) do |match|
42
- match.tr('-', '_')
46
+ unescaped = CGI.unescape(match)
47
+ underscored = Drillbit::Utilities::String.underscore(unescaped)
48
+
49
+ CGI.escape(underscored)
43
50
  end
44
51
  end
45
52
 
@@ -49,7 +56,7 @@ class ParameterParser
49
56
  parameters.each_with_object({}) do |(key, value), hash|
50
57
  value = underscore_parameters(value) if value.is_a? Hash
51
58
 
52
- hash[key.tr('-', '_')] = value
59
+ hash[Drillbit::Utilities::String.underscore(key)] = value
53
60
  end
54
61
  end
55
62
  end
@@ -2,6 +2,38 @@
2
2
  module Drillbit
3
3
  module Utilities
4
4
  class String
5
+ # rubocop:disable Metrics/LineLength
6
+ SINGULARIZATION_RULES = [
7
+ [/(database)s$/i, '\1'],
8
+ [/(quiz)zes$/i, '\1'],
9
+ [/(matr)ices$/i, '\1ix'],
10
+ [/(vert|ind)ices$/i, '\1ex'],
11
+ [/^(ox)en/i, '\1'],
12
+ [/(alias|status)(es)?$/i, '\1'],
13
+ [/(octop|vir)(us|i)$/i, '\1us'],
14
+ [/^(a)x[ie]s$/i, '\1xis'],
15
+ [/(cris|test)(is|es)$/i, '\1is'],
16
+ [/(shoe)s$/i, '\1'],
17
+ [/(o)es$/i, '\1'],
18
+ [/(bus)(es)?$/i, '\1'],
19
+ [/^(m|l)ice$/i, '\1ouse'],
20
+ [/(x|ch|ss|sh)es$/i, '\1'],
21
+ [/(m)ovies$/i, '\1ovie'],
22
+ [/(s)eries$/i, '\1eries'],
23
+ [/([^aeiouy]|qu)ies$/i, '\1y'],
24
+ [/([lr])ves$/i, '\1f'],
25
+ [/(tive)s$/i, '\1'],
26
+ [/(hive)s$/i, '\1'],
27
+ [/([^f])ves$/i, '\1fe'],
28
+ [/(^analy)(sis|ses)$/i, '\1sis'],
29
+ [/((a)naly|(b)a|(d)iagno|(p)arenthe|(p)rogno|(s)ynop|(t)he)(sis|ses)$/i, '\1sis'],
30
+ [/([ti])a$/i, '\1um'],
31
+ [/(n)ews$/i, '\1ews'],
32
+ [/(ss)$/i, '\1'],
33
+ [/s$/i, ''],
34
+ ].freeze
35
+ # rubocop:enable Metrics/LineLength
36
+
5
37
  def self.underscore(other)
6
38
  word = other.to_s.gsub('::', '/')
7
39
  word.gsub!(/(?:([A-Za-z\d])|^)(?=\b|[^a-z])/) do
@@ -13,6 +45,16 @@ class String
13
45
  word.downcase!
14
46
  word
15
47
  end
48
+
49
+ def self.singularize(word)
50
+ result = word.to_s.dup
51
+
52
+ SINGULARIZATION_RULES.each do |(rule, replacement)|
53
+ break if result.sub!(rule, replacement)
54
+ end
55
+
56
+ result
57
+ end
16
58
  end
17
59
  end
18
60
  end
@@ -1,4 +1,4 @@
1
1
  # frozen_string_literal: true
2
2
  module Drillbit
3
- VERSION = '2.3.1'
3
+ VERSION = '2.4.0'
4
4
  end
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.3.1
4
+ version: 2.4.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-08-14 00:00:00.000000000 Z
34
+ date: 2016-09-07 00:00:00.000000000 Z
35
35
  dependencies:
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: erratum
metadata.gz.sig CHANGED
Binary file