code-ruby 1.9.7 → 1.9.8

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: 6333e864ab7337464252aefef70ff9d3bd5adbfa56a6824f26800a19e5edc776
4
- data.tar.gz: 6556133a0bf11f1651f693d9af6edce9781f2c5b90a842fb46dbd0a45061034d
3
+ metadata.gz: 56fcf3ffc17f9740302bc6bd52c6aeb204eb3799883920fa35d7140829070464
4
+ data.tar.gz: 6e8b2521a80535fbf094771f4c105c56f6ccaef4d492dfbec9b0d51d099ab875
5
5
  SHA512:
6
- metadata.gz: a4e8152a05e0f67801282b08d1ebc4a2ed8ebbb346d15cdb976f4e201a0358658922d7f457faf6b7bfe5d9e65f7d135a3b97741dcdc8ce10706c302e0e19fa8d
7
- data.tar.gz: f24a4f62f8eac88f50c6627f07969deeb92a3a0e95d5f4b77769aa78b28f27136c13b573db5fb46a1737064af2be2eeedc62f3a0a16ebcf28ec24bce3674dcff
6
+ metadata.gz: fccf82958c319089713c3e00ec779f06adb23f315bff2fd4e2af5bac36b74cf91dbff74c7a5cd7d807cb4353e043e689b372fc4f3302d7e806e48a7c6d021c0b
7
+ data.tar.gz: 8424f8d97d597e00c3390ace61a8038fc151415f7a87573912be0cd43f342686a2d6dac70a775a86a7033f8cd40197376e1e1a6d7eb654f1c842180f2804904e
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- code-ruby (1.9.7)
4
+ code-ruby (1.9.8)
5
5
  activesupport
6
6
  base64
7
7
  bigdecimal
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.9.7
1
+ 1.9.8
data/lib/code/format.rb CHANGED
@@ -220,30 +220,35 @@ class Code
220
220
  components.flat_map do |component|
221
221
  value = component[:value].to_s
222
222
  if component[:type] == :code
223
- [value]
223
+ [{ value: value, splittable: false }]
224
224
  else
225
- value.split(/(\s+)/)
225
+ value
226
+ .split(/(\s+)/)
227
+ .reject(&:empty?)
228
+ .map { |unit| { value: unit, splittable: true } }
226
229
  end
227
- end.reject(&:empty?)
230
+ end
228
231
 
229
232
  chunks = [""]
230
233
  units.each do |unit|
231
- if unit.length > limit
234
+ value = unit[:value]
235
+
236
+ if unit[:splittable] && value.length > limit
232
237
  if chunks.last.empty?
233
- segments = unit.scan(/.{1,#{limit}}/m)
238
+ segments = value.scan(/.{1,#{limit}}/m)
234
239
  chunks[-1] = segments.shift.to_s
235
240
  segments.each { |segment| chunks << segment }
236
241
  else
237
- chunks << unit
242
+ chunks << value
238
243
  end
239
244
  next
240
245
  end
241
246
 
242
247
  current = chunks.last
243
- candidate = "#{current}#{unit}"
248
+ candidate = "#{current}#{value}"
244
249
  if !current.empty? && candidate.length > limit
245
250
  chunks[-1] = current
246
- chunks << unit
251
+ chunks << value
247
252
  else
248
253
  chunks[-1] = candidate
249
254
  end
@@ -60,7 +60,7 @@ class Code
60
60
  code_value
61
61
  else
62
62
  receiver.code_fetch(raw.last).call(
63
- **args,
63
+ **args.merge(context: args.fetch(:context, context)),
64
64
  operator: assignment_operator.chop,
65
65
  arguments: [code_value]
66
66
  )
@@ -30,6 +30,10 @@ RSpec.describe Code::Format do
30
30
  [
31
31
  "Http.post(\"https://api.openai.com/v1/chat/completions\", headers: { authorization: \"Bearer {open_ai_api_key}\", \"content-type\": \"application/json\" }, body: { model: model, messages: [{ role: \"system\", content: \"hello\" }, { role: \"user\", content: \"world\" }] }.to_json)",
32
32
  "Http.post(\n \"https://api.openai.com/v1/chat/completions\",\n headers: {\n authorization: \"Bearer {open_ai_api_key}\",\n \"content-type\": \"application/json\"\n },\n body: {\n model: model,\n messages: [\n { role: :system, content: :hello },\n { role: :user, content: :world }\n ]\n }.to_json\n)"
33
+ ],
34
+ [
35
+ "proxy_url = (url) => { \"{proxy_base_url}?{{ url: url, disposition: proxy_inline_disposition }.to_query}\" }",
36
+ "proxy_url = (url) => {\n \"{proxy_base_url}?\"\n + \"{{\n url: url,\n disposition: proxy_inline_disposition\n }.to_query}\"\n}"
33
37
  ]
34
38
  ].each do |input, expected|
35
39
  it "formats #{input.inspect}" do
@@ -0,0 +1,34 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "spec_helper"
4
+
5
+ RSpec.describe Code::Object::IdentifierList do
6
+ it "keeps context for ||= assignments in nested context receivers" do
7
+ code_context = Code::Object::Context.new
8
+ code_identifier = Code::Object::String.new("value")
9
+ code_key = Code::Object::String.new("key")
10
+
11
+ code_context.code_set(
12
+ code_identifier,
13
+ Code::Object::Dictionary.new(code_key => Code::Object::Dictionary.new(a: 1))
14
+ )
15
+
16
+ identifier_list = described_class.new([code_identifier, code_key])
17
+
18
+ expect do
19
+ identifier_list.send(
20
+ :assign_in_context,
21
+ context: code_context,
22
+ assignment_operator: "||=",
23
+ code_value: Code::Object::Dictionary.new(b: 2),
24
+ arguments: Code::Object::List.new([Code::Object::Dictionary.new(b: 2)]),
25
+ operator: "||=",
26
+ error: StringIO.new,
27
+ input: StringIO.new,
28
+ object: Code::Object::Global.new,
29
+ output: StringIO.new,
30
+ source: ""
31
+ )
32
+ end.not_to raise_error
33
+ end
34
+ end
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: 1.9.7
4
+ version: 1.9.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié
@@ -346,6 +346,7 @@ files:
346
346
  - spec/code/object/dictionary_spec.rb
347
347
  - spec/code/object/function_spec.rb
348
348
  - spec/code/object/http_spec.rb
349
+ - spec/code/object/identifier_list_spec.rb
349
350
  - spec/code/object/integer_spec.rb
350
351
  - spec/code/object/list_spec.rb
351
352
  - spec/code/object/nothing_spec.rb