github-ds 0.2.1 → 0.2.2

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: e3dda4d4ed9f093a4e3d098f5701f804bde5fc55
4
- data.tar.gz: ee1f88f94fcd6986913b9c4ee1dc85269b8bb108
3
+ metadata.gz: 71f03b79bb5da02405c55e147147550eede9a120
4
+ data.tar.gz: 69c8978ef97b5d7a45e005cbbdf371ce601c68bc
5
5
  SHA512:
6
- metadata.gz: dcff9123a791a1ca4e81f2db9faef112331712070cf5920465c4bcd46c42eabc36b48626f80eeff886dd8791e98e0d6611be9b94b7f20ff179b17fe585ee2f9d
7
- data.tar.gz: a30eed58460e4f4e9430f12fe41f6ab1537eb1f3b07a33d990606cb62b8e19dedd079ac210da68105ff8f30dec56b91e2f5ebd9213606882dcf6b32e31067014
6
+ metadata.gz: 4d7c7c75907e73190497e58bdda8a9729a334e7aa05f6482c57ea1f0a48ed0db9871728604f7160e23d02e0d641d581241113d3f0bb85b90959c877b2fa84b44
7
+ data.tar.gz: 600871b7b135f7d0544e74e05921e97b1e6c292046b14306bbbe68155c3c8df7bb3a42a2abe18769db41c011787c82dfd1cd3d3411b3fd10ab8b55f92b413971
@@ -1,5 +1,15 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.2.2
4
+
5
+ Additions
6
+
7
+ * `GitHub::KV` accepts `SQL::Literal` as valid values https://github.com/github/github-ds/pull/21/commits/c11d4e3154dd3435d509a3356f46d0a2981d7234
8
+
9
+ Fixes
10
+
11
+ * Value length validation takes into account that strings can be made of multi-byte characters https://github.com/github/github-ds/pull/21/commits/5156f95ef04b1ecf2ce90929c5752b2e61d39566
12
+
3
13
  ## 0.2.1
4
14
 
5
15
  Additions
@@ -34,7 +34,7 @@ rescue
34
34
  adapter: "mysql2",
35
35
  username: "root",
36
36
  })
37
- ActiveRecord::Base.connection.execute("CREATE DATABASE `github_ds_test`")
37
+ ActiveRecord::Base.connection.execute("CREATE DATABASE IF NOT EXISTS `github_ds_test`")
38
38
  attempts += 1
39
39
  retry
40
40
  end
@@ -1,5 +1,5 @@
1
1
  module GitHub
2
2
  module DS
3
- VERSION = "0.2.1"
3
+ VERSION = "0.2.2"
4
4
  end
5
5
  end
@@ -271,14 +271,18 @@ module GitHub
271
271
  end
272
272
 
273
273
  private
274
- def validate_key(key)
275
- raise TypeError, "key must be a String in #{self.class.name}, but was #{key.class}" unless key.is_a?(String)
274
+ def validate_key(key, error_message: nil)
275
+ unless key.is_a?(String)
276
+ raise TypeError, error_message || "key must be a String in #{self.class.name}, but was #{key.class}"
277
+ end
276
278
 
277
279
  validate_key_length(key)
278
280
  end
279
281
 
280
- def validate_value(value)
281
- raise TypeError, "value must be a String in #{self.class.name}, but was #{value.class}" unless value.is_a?(String)
282
+ def validate_value(value, error_message: nil)
283
+ unless value.is_a?(String) || value.is_a?(GitHub::SQL::Literal)
284
+ raise TypeError, error_message || "value must be a String in #{self.class.name} or SQL::Literal, but was #{value.class}"
285
+ end
282
286
 
283
287
  validate_value_length(value)
284
288
  end
@@ -299,20 +303,12 @@ module GitHub
299
303
 
300
304
  def validate_key_value_hash(kvs)
301
305
  unless kvs.is_a?(Hash)
302
- raise TypeError, "kvs must be a {String => String} in #{self.class.name}, but was #{key.class}"
306
+ raise TypeError, "kvs must be a {String => String} in #{self.class.name}, but was #{kvs.class}"
303
307
  end
304
308
 
305
309
  kvs.each do |key, value|
306
- unless key.is_a?(String)
307
- raise TypeError, "kvs must be a {String => String} in #{self.class.name}, but also saw at least one key of type #{key.class}"
308
- end
309
-
310
- unless value.is_a?(String)
311
- raise TypeError, "kvs must be a {String => String} in #{self.class.name}, but also saw at least one value of type #{value.class}"
312
- end
313
-
314
- validate_key_length(key)
315
- validate_value_length(value)
310
+ validate_key(key, error_message: "kvs must be a {String => [String | SQL::Literal]} in #{self.class.name}, but also saw at least one key of type #{key.class}")
311
+ validate_value(value, error_message: "kvs must be a {String => [String | SQL::Literal]} in #{self.class.name}, but also saw at least one value of type #{value.class}")
316
312
  end
317
313
  end
318
314
 
@@ -323,7 +319,7 @@ module GitHub
323
319
  end
324
320
 
325
321
  def validate_value_length(value)
326
- if value.length > MAX_VALUE_LENGTH
322
+ if value.bytesize > MAX_VALUE_LENGTH
327
323
  raise ValueLengthError, "value of length #{value.length} exceeds maximum value length of #{MAX_VALUE_LENGTH}"
328
324
  end
329
325
  end
@@ -44,6 +44,10 @@ module GitHub
44
44
  def inspect
45
45
  "<#{self.class.name} #{value}>"
46
46
  end
47
+
48
+ def bytesize
49
+ value.bytesize
50
+ end
47
51
  end
48
52
 
49
53
  # Internal: a list of arrays of values for insertion into SQL.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: github-ds
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - GitHub Open Source
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: exe
11
11
  cert_chain: []
12
- date: 2017-07-14 00:00:00.000000000 Z
12
+ date: 2017-09-14 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: activerecord