code-ruby 5.2.1 → 5.2.3

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: 978d1a5cd5c7828f25ac0d619f50d68dcee1596a9fd3d92ac4e1ba684bfe2481
4
- data.tar.gz: 06c6cb5d2bf9e3b596d1524ea710dd3ec7f6c8abcd871f07c62f1eb291967c94
3
+ metadata.gz: ff9e2eb63fe68f38a6beb3082b3b625aebed51c35aa77c326d525f67f0fa2975
4
+ data.tar.gz: 164677f0a8bc720bfcba991b9dc95799f4737fc25e42bcd88de70fe6d0dd4fe1
5
5
  SHA512:
6
- metadata.gz: 9c314514dc4d2ca20ebd674fe158b90b1f2200008e9e56389fab38513d8b81a1f21f7bd2dbd85f3bf16fe0d376c6879737524bb7597070a413b767d0b43df5a4
7
- data.tar.gz: 6ad13fe0f05f93e56fece2befeaf33fb08a10c5f3d2a8186021d57a2e7d6bd7c246615690e78bf950ab25f5453ce9af3b4d43399f6b7e3ea543d7fef83daecf1
6
+ metadata.gz: f5fd63680c00619761715a35a294d0dbf03d0a8979f611c2e9e7cd76a2876c52215d10a0d1ddc0a2d63de7090836dad6d8f983faa976df148c3d71191b9cd609
7
+ data.tar.gz: 313a8c168da2e41951dddfe2365d0c058ff186f42f8128581b11f03a414ee17d81346f6aa4848697e5d5fbe76b69a2d5b384576acc83fbc13578d97b6e05d36f
data/VERSION CHANGED
@@ -1 +1 @@
1
- 5.2.1
1
+ 5.2.3
@@ -22,6 +22,7 @@ class Code
22
22
  SHARED_OPERATORS = %w[
23
23
  documentation
24
24
  present?
25
+ in?
25
26
  blank?
26
27
  presence
27
28
  presence_in
@@ -161,6 +162,9 @@ class Code
161
162
  when "==", "equal", "equal?"
162
163
  sig(args) { Object }
163
164
  code_equal(code_value)
165
+ when "in?"
166
+ sig(args) { Object::List | Object::Range | Object::String | Object::Dictionary }
167
+ code_in?(code_value)
164
168
  when "same_object?"
165
169
  sig(args) { Object }
166
170
  code_same_object?(code_value)
@@ -391,6 +395,15 @@ class Code
391
395
  Object::Boolean.new((self <=> code_other) <= 0)
392
396
  end
393
397
 
398
+ def code_in?(collection)
399
+ collection = collection.to_code
400
+ if collection.is_a?(Object::Dictionary)
401
+ collection.code_has_key?(self)
402
+ else
403
+ collection.code_include?(self)
404
+ end
405
+ end
406
+
394
407
  def code_exclamation_mark
395
408
  Object::Boolean.new(falsy?)
396
409
  end
data/lib/code/format.rb CHANGED
@@ -459,11 +459,12 @@ class Code
459
459
  extract_string_concatenation_parts(left_operation: operation)
460
460
  return format_string(merged_string, indent: indent) if merged_string
461
461
 
462
- expression = format_nested_statement(operation[:first], indent: indent)
462
+ first_operator = format_operator(Array(operation[:others]).first&.fetch(:operator, ""))
463
+ expression = format_boolean_operand(operation[:first], first_operator, indent: indent)
463
464
 
464
465
  Array(operation[:others]).each do |other|
465
- right = format_nested_statement(other[:statement], indent: indent)
466
466
  operator = format_operator(other[:operator])
467
+ right = format_boolean_operand(other[:statement], operator, indent: indent)
467
468
 
468
469
  expression =
469
470
  if compact_operator?(operator)
@@ -510,6 +511,21 @@ class Code
510
511
  expression
511
512
  end
512
513
 
514
+ def format_boolean_operand(statement, operator, indent:)
515
+ if BOOLEAN_WORD_OPERATORS.include?(operator) && statement.is_a?(Hash) &&
516
+ statement[:left_operation]
517
+ nested = Array(statement[:left_operation][:others])
518
+ if nested.any? do |other|
519
+ nested_operator = format_operator(other[:operator])
520
+ BOOLEAN_WORD_OPERATORS.include?(nested_operator) && nested_operator != operator
521
+ end
522
+ return format_group([statement], indent: indent)
523
+ end
524
+ end
525
+
526
+ format_nested_statement(statement, indent: indent)
527
+ end
528
+
513
529
  def format_compact_receiver(expression, indent:)
514
530
  return expression unless compact_receiver_needs_parentheses?(expression)
515
531
 
@@ -197,7 +197,8 @@ class Code
197
197
  not_extended: 510,
198
198
  network_authentication_required: 511
199
199
  }.freeze
200
- DEFAULT_TIMEOUT = 1.hour.to_f
200
+ DEFAULT_TIMEOUT = 30
201
+ DEFAULT_OPEN_TIMEOUT = 10
201
202
  MAX_HEADER_BYTES = 32.kilobytes
202
203
  HEADER_NAME = /\A[A-Za-z0-9!#$%&'*+\-.^_`|~]+\z/
203
204
  RESTRICTED_HEADERS = %w[
@@ -348,7 +349,7 @@ class Code
348
349
  redirects =
349
350
  (
350
351
  if options.code_get("redirects").nothing?
351
- 10
352
+ 0
352
353
  else
353
354
  options.code_get("redirects").raw
354
355
  end
@@ -410,7 +411,11 @@ class Code
410
411
  http.use_ssl = true if uri.scheme == "https"
411
412
  http.max_retries = max_retries
412
413
  default_timeout = http_timeout(timeout, DEFAULT_TIMEOUT)
413
- open_timeout_value = http_timeout(open_timeout, default_timeout)
414
+ open_timeout_value =
415
+ http_timeout(
416
+ open_timeout,
417
+ timeout.nothing? ? DEFAULT_OPEN_TIMEOUT : default_timeout
418
+ )
414
419
  read_timeout_value = http_timeout(read_timeout, default_timeout)
415
420
  write_timeout_value = http_timeout(write_timeout, default_timeout)
416
421
 
data/lib/code/object.rb CHANGED
@@ -17,6 +17,11 @@ class Code
17
17
  examples: %w[Object Object.new Object.documentation.description]
18
18
  }.freeze
19
19
  INSTANCE_FUNCTIONS = {
20
+ "in?" => {
21
+ name: "in?",
22
+ description: "checks whether a collection includes this value.",
23
+ examples: ["200.in?(200...300)", "300.in?(200...300)", ":ok.in?([:ok, :accepted])"]
24
+ },
20
25
  "documentation" => {
21
26
  name: "documentation",
22
27
  description: "returns documentation for the value's class.",
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 5.2.1
4
+ version: 5.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié