code-ruby 1.5.7 → 1.6.1

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.
@@ -52,7 +52,7 @@ class Code
52
52
  end
53
53
 
54
54
  def right_statement
55
- OrKeyword
55
+ Statement
56
56
  end
57
57
 
58
58
  def operator
@@ -32,7 +32,7 @@ class Code
32
32
  end
33
33
 
34
34
  def operator
35
- (exclamation_mark << equal << equal) | (equal << equal << equal) |
35
+ (exclamation_mark << equal << equal) | (equal << equal << equal) |
36
36
  (equal << equal) | (lesser << equal << greater) |
37
37
  (exclamation_mark << equal) | (equal << tilde) | (tilde << equal) |
38
38
  (exclamation_mark << tilde)
@@ -51,6 +51,10 @@ class Code
51
51
  str("elsif")
52
52
  end
53
53
 
54
+ def elsunless_keyword
55
+ str("elsunless")
56
+ end
57
+
54
58
  def else_keyword
55
59
  str("else")
56
60
  end
@@ -76,8 +80,9 @@ class Code
76
80
  statement.aka(:first_statement) << body.aka(:first_body) <<
77
81
  (
78
82
  (
79
- elsif_keyword.aka(:operator) << whitespace <<
80
- statement.aka(:statement) << body.aka(:body)
83
+ (elsif_keyword | elsunless_keyword).aka(
84
+ :operator
85
+ ) << whitespace << statement.aka(:statement) << body.aka(:body)
81
86
  ) |
82
87
  (
83
88
  else_keyword << whitespace <<
@@ -99,6 +99,38 @@ class Code
99
99
  str("else")
100
100
  end
101
101
 
102
+ def while_keyword
103
+ str("while")
104
+ end
105
+
106
+ def until_keyword
107
+ str("until")
108
+ end
109
+
110
+ def if_keyword
111
+ str("if")
112
+ end
113
+
114
+ def unless_keyword
115
+ str("unless")
116
+ end
117
+
118
+ def elsunless_keyword
119
+ str("elsunless")
120
+ end
121
+
122
+ def true_keyword
123
+ str("true")
124
+ end
125
+
126
+ def false_keyword
127
+ str("false")
128
+ end
129
+
130
+ def nothing_keyword
131
+ str("nothing")
132
+ end
133
+
102
134
  def exclamation_mark
103
135
  str("!")
104
136
  end
@@ -127,13 +159,16 @@ class Code
127
159
  exclamation_mark | question_mark
128
160
  end
129
161
 
162
+ def keyword
163
+ do_keyword | begin_keyword | end_keyword | while_keyword |
164
+ until_keyword | if_keyword | elsif_keyword | else_keyword |
165
+ unless_keyword | elsunless_keyword | true_keyword | false_keyword |
166
+ nothing_keyword
167
+ end
168
+
130
169
  def root
131
- (do_keyword << separator).absent << (
132
- begin_keyword << separator
133
- ).absent << (else_keyword << separator).absent <<
134
- (elsif_keyword << separator).absent <<
135
- (end_keyword << separator).absent <<
136
- special_characters.absent << character.repeat(1)
170
+ (keyword << separator).absent << special_characters.absent <<
171
+ character.repeat(1)
137
172
  end
138
173
  end
139
174
  end
data/lib/code.rb CHANGED
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  class Code
4
- GLOBALS = %i[context error input object output source object].freeze
4
+ GLOBALS = %i[context error input object output source].freeze
5
5
  DEFAULT_TIMEOUT = 0
6
6
 
7
7
  def initialize(
@@ -24,7 +24,6 @@ RSpec.describe Code::Object::Decimal do
24
24
  %w[-1.123.floor(2) -1.13],
25
25
  %w[1.1.round 1],
26
26
  %w[1.123.round(2) 1.12],
27
- %w[1.2.clone 1.2],
28
27
  %w[0.0.zero? true],
29
28
  %w[1.2.truncate 1],
30
29
  %w[1.234.truncate(2) 1.23],
@@ -3,77 +3,81 @@
3
3
  require "spec_helper"
4
4
 
5
5
  RSpec.describe Code::Object::Http do
6
- VERBS = %w[get head post put delete options trace patch].freeze
6
+ def self.verbs
7
+ %w[get head post put delete options trace patch]
8
+ end
7
9
 
8
- RESPONSE_CODES = {
9
- continue: 100,
10
- switching_protocols: 101,
11
- processing: 102,
12
- early_hints: 103,
13
- ok: 200,
14
- created: 201,
15
- accepted: 202,
16
- non_authoritative_information: 203,
17
- no_content: 204,
18
- reset_content: 205,
19
- partial_content: 206,
20
- multi_status: 207,
21
- already_reported: 208,
22
- im_used: 226,
23
- multiple_choices: 300,
24
- moved_permanently: 301,
25
- found: 302,
26
- see_other: 303,
27
- not_modified: 304,
28
- use_proxy: 305,
29
- reserved: 306,
30
- temporary_redirect: 307,
31
- permanent_redirect: 308,
32
- bad_request: 400,
33
- unauthorized: 401,
34
- payment_required: 402,
35
- forbidden: 403,
36
- not_found: 404,
37
- method_not_allowed: 405,
38
- not_acceptable: 406,
39
- proxy_authentication_required: 407,
40
- request_timeout: 408,
41
- conflict: 409,
42
- gone: 410,
43
- length_required: 411,
44
- precondition_failed: 412,
45
- request_entity_too_large: 413,
46
- request_uri_too_long: 414,
47
- unsupported_media_type: 415,
48
- requested_range_not_satisfiable: 416,
49
- expectation_failed: 417,
50
- misdirected_request: 421,
51
- unprocessable_entity: 422,
52
- locked: 423,
53
- failed_dependency: 424,
54
- too_early: 425,
55
- upgrade_required: 426,
56
- precondition_required: 428,
57
- too_many_requests: 429,
58
- request_header_fields_too_large: 431,
59
- unavailable_for_legal_reasons: 451,
60
- internal_server_error: 500,
61
- not_implemented: 501,
62
- bad_gateway: 502,
63
- service_unavailable: 503,
64
- gateway_timeout: 504,
65
- http_version_not_supported: 505,
66
- variant_also_negotiates: 506,
67
- insufficient_storage: 507,
68
- loop_detected: 508,
69
- bandwidth_limit_exceeded: 509,
70
- not_extended: 510,
71
- network_authentication_required: 511
72
- }.freeze
10
+ def self.response_codes
11
+ {
12
+ continue: 100,
13
+ switching_protocols: 101,
14
+ processing: 102,
15
+ early_hints: 103,
16
+ ok: 200,
17
+ created: 201,
18
+ accepted: 202,
19
+ non_authoritative_information: 203,
20
+ no_content: 204,
21
+ reset_content: 205,
22
+ partial_content: 206,
23
+ multi_status: 207,
24
+ already_reported: 208,
25
+ im_used: 226,
26
+ multiple_choices: 300,
27
+ moved_permanently: 301,
28
+ found: 302,
29
+ see_other: 303,
30
+ not_modified: 304,
31
+ use_proxy: 305,
32
+ reserved: 306,
33
+ temporary_redirect: 307,
34
+ permanent_redirect: 308,
35
+ bad_request: 400,
36
+ unauthorized: 401,
37
+ payment_required: 402,
38
+ forbidden: 403,
39
+ not_found: 404,
40
+ method_not_allowed: 405,
41
+ not_acceptable: 406,
42
+ proxy_authentication_required: 407,
43
+ request_timeout: 408,
44
+ conflict: 409,
45
+ gone: 410,
46
+ length_required: 411,
47
+ precondition_failed: 412,
48
+ request_entity_too_large: 413,
49
+ request_uri_too_long: 414,
50
+ unsupported_media_type: 415,
51
+ requested_range_not_satisfiable: 416,
52
+ expectation_failed: 417,
53
+ misdirected_request: 421,
54
+ unprocessable_entity: 422,
55
+ locked: 423,
56
+ failed_dependency: 424,
57
+ too_early: 425,
58
+ upgrade_required: 426,
59
+ precondition_required: 428,
60
+ too_many_requests: 429,
61
+ request_header_fields_too_large: 431,
62
+ unavailable_for_legal_reasons: 451,
63
+ internal_server_error: 500,
64
+ not_implemented: 501,
65
+ bad_gateway: 502,
66
+ service_unavailable: 503,
67
+ gateway_timeout: 504,
68
+ http_version_not_supported: 505,
69
+ variant_also_negotiates: 506,
70
+ insufficient_storage: 507,
71
+ loop_detected: 508,
72
+ bandwidth_limit_exceeded: 509,
73
+ not_extended: 510,
74
+ network_authentication_required: 511
75
+ }
76
+ end
73
77
 
74
- VERBS.each do |verb|
78
+ verbs.each do |verb|
75
79
  describe ".#{verb}" do
76
- RESPONSE_CODES.each do |status, code|
80
+ response_codes.each do |status, code|
77
81
  it "returns #{code} as code and #{status} as status" do
78
82
  expect(Code.evaluate(<<~INPUT)).to eq(Code.evaluate(<<~OUTPUT))
79
83
  response = Http.#{verb}("https://httpbin.org/status/#{code}")
@@ -24,7 +24,6 @@ RSpec.describe Code::Object::Integer do
24
24
  %w[1234.floor(-2) 1200],
25
25
  %w[1.round 1],
26
26
  %w[1234.round(-2) 1200],
27
- %w[1.clone 1],
28
27
  %w[0.zero? true],
29
28
  %w[1.truncate 1],
30
29
  %w[1234.truncate(-2) 1200],
@@ -8,8 +8,8 @@ RSpec.describe Code::Parser::IfModifier do
8
8
  ["1 if false", "nothing"],
9
9
  ["1 unless true", "nothing"],
10
10
  ["1 unless false", "1"],
11
- ["a = 0 a += 1 while a < 10 a", "10"],
12
- ["a = 0 a += 1 until a > 10 a", "11"]
11
+ ["a = 0 (a += 1) while a < 10 a", "10"],
12
+ ["a = 0 (a += 1) until a > 10 a", "11"]
13
13
  ].each do |input, expected|
14
14
  it "#{input} == #{expected}" do
15
15
  expect(Code.evaluate(input)).to eq(Code.evaluate(expected))
data/spec/code_spec.rb CHANGED
@@ -13,6 +13,7 @@ RSpec.describe Code do
13
13
  "Object.new !== Object.new"
14
14
  ] +
15
15
  %w[
16
+ :abc.size
16
17
  Date.new.change
17
18
  {}.zero?
18
19
  {}.any?
@@ -267,8 +268,8 @@ RSpec.describe Code do
267
268
  ["Class(true, 1)", "Boolean"],
268
269
  ["Class.new(Boolean, Time)", "Boolean"],
269
270
  ["Class.new(Time, Boolean)", "Time"],
270
- ["Date(2024, 3, 2).to_string", ":2024-03-02"],
271
- ["Date(2024,3, 2).to_string", ":2024-03-02"],
271
+ ['Date("2024-3-2").to_string', ":2024-03-02"],
272
+ ['Date("2024-3-2").to_string', ":2024-03-02"],
272
273
  ["Decimal(1, :2)", "100"],
273
274
  ["Decimal(:1, 2)", "100.0"],
274
275
  ["Decimal.new(1, :2)", "100"],
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: code-ruby
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.5.7
4
+ version: 1.6.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié
8
8
  bindir: bin
9
9
  cert_chain: []
10
- date: 2025-06-07 00:00:00.000000000 Z
10
+ date: 2025-06-21 00:00:00.000000000 Z
11
11
  dependencies:
12
12
  - !ruby/object:Gem::Dependency
13
13
  name: activesupport
@@ -223,6 +223,7 @@ files:
223
223
  - bin/rubocop
224
224
  - bin/test
225
225
  - code-ruby.gemspec
226
+ - docs/precedence.txt
226
227
  - lib/code-ruby.rb
227
228
  - lib/code.rb
228
229
  - lib/code/concerns.rb
@@ -275,6 +276,7 @@ files:
275
276
  - lib/code/object/json.rb
276
277
  - lib/code/object/list.rb
277
278
  - lib/code/object/nothing.rb
279
+ - lib/code/object/number.rb
278
280
  - lib/code/object/parameter.rb
279
281
  - lib/code/object/range.rb
280
282
  - lib/code/object/smtp.rb