code-ruby 1.7.2 → 1.7.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: f879e8b670d3068cd05dad09a1830ad005c3696ef2d4da2778bb50724bbcf14c
4
- data.tar.gz: 7bfa1623deb05a6e91af6eff3b0dcba8c6ea29319ff1f96e7129b64286d38fe8
3
+ metadata.gz: 293ab4f43a6d428f474b7dae97573abe87b06a08e174253c5f8a14920996606c
4
+ data.tar.gz: 5f99a4352c5ea189931fc9d161becd8e7033d6e274d6d56a594a611c9b5878bd
5
5
  SHA512:
6
- metadata.gz: f68438e18649877cc651ed15d8ff70ab2232c3a12c5197e82919db711c22703c341868800f5f32aa49a61e45b72dae5320c514ae7adb8693b958cab5a1611baf
7
- data.tar.gz: d214dca53f89bf327c993bbca6680e1bf0d148e9d4ca02efa698ab789f10f91fb05edc5709a3ece84396872877beeab3fba9775b3c0f85f9b8b7d6ee86bb908d
6
+ metadata.gz: 79e973b9e34dd7c38a3de09cfd60fc66c9df908fedf86528bd44227cecc080119539f69d45fdfecf174e6f4e48781da5b9d2e477a6ed1256a7985fea92da4bde
7
+ data.tar.gz: 1be497dead54131c9c3c72787dd336c1220c6be21a01ed137f3a8cf953928cd9a6962302b3ecd10e67cc2dfbf51715acfa033aefd35fdd80bd4aab84c9792b36
data/AGENTS.md ADDED
@@ -0,0 +1,38 @@
1
+ # Repository Guidelines
2
+
3
+ ## Project Structure & Module Organization
4
+ - `lib/` — Core source. Classes live under the `Code` namespace and mirror paths (e.g., `lib/code/object/http.rb` → `Code::Object::Http`). Entry files: `lib/code.rb`, `lib/code-ruby.rb`.
5
+ - `bin/` — Executables and tooling shims: `bin/code` (CLI), `bin/rspec`, `bin/rubocop`, `bin/bundle`, `bin/bundler-audit`.
6
+ - `spec/` — RSpec tests. Shared setup in `spec/spec_helper.rb` (WebMock + Sinatra test app). File names end with `_spec.rb`.
7
+ - `docs/` — Reference docs (e.g., operator precedence).
8
+ - Root — `Gemfile`, `code-ruby.gemspec`, `Rakefile` (RSpec default), `.rubocop.yml`, `VERSION`.
9
+
10
+ ## Build, Test, and Development Commands
11
+ - Install: `bundle install`
12
+ - Run all tests: `bundle exec rake` or `bin/rspec`
13
+ - Run one file/example: `bin/rspec spec/code_spec.rb:42`
14
+ - Lint: `bin/rubocop` (auto-fix: `bin/rubocop -A`)
15
+ - Security audit: `bin/bundler-audit update && bin/bundler-audit check`
16
+ - Build gem: `gem build code-ruby.gemspec`
17
+ - CLI examples: `bin/code -h`, `bin/code -p '1+2'`, `bin/code -t 2 'loop { }'`
18
+
19
+ ## Coding Style & Naming Conventions
20
+ - Ruby 3.4.5; 2-space indentation; keep `# frozen_string_literal: true`.
21
+ - Follow `.rubocop.yml`; prefer small, single-responsibility classes under `lib/code/...` reflecting their constants.
22
+ - File names: snake_case; tests mirror source paths under `spec/` with `_spec.rb` suffix.
23
+
24
+ ## Testing Guidelines
25
+ - Framework: RSpec. Network calls are disabled via WebMock; use the provided `FakeHttpBin` rack app for HTTP behavior.
26
+ - Add focused specs near the feature (e.g., parser under `spec/code/parser/*`, objects under `spec/code/object/*`).
27
+ - For language-level behaviors, extend `spec/code_spec.rb` with input → output examples.
28
+ - Ensure new behavior has at least one positive and one edge/failure case.
29
+
30
+ ## Commit & Pull Request Guidelines
31
+ - Commits: short, imperative subjects (e.g., "fix parser whitespace"). Version bumps (`VERSION`, `vX.Y.Z`) are handled by maintainers.
32
+ - PRs: include a clear description, reproduction or CLI examples, and links to issues. Update docs in `docs/` when grammar/precedence changes.
33
+ - Keep diffs minimal and focused; include tests and run `bin/rubocop` before submitting.
34
+
35
+ ## Security & Configuration Tips
36
+ - Tooling versions: see `.tool-versions`, `.ruby-version`, `.node-version`, `.npm-version`.
37
+ - Tests must not reach the network; rely on stubs/fixtures. Prefer timeouts (`-t/--timeout`) when evaluating untrusted input with `bin/code`.
38
+
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- code-ruby (1.7.2)
4
+ code-ruby (1.7.3)
5
5
  activesupport
6
6
  base64
7
7
  bigdecimal
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.7.2
1
+ 1.7.3
@@ -150,9 +150,9 @@ class Code
150
150
  code_fetch("patch", ...)
151
151
  end
152
152
 
153
- def self.code_fetch(*arguments)
153
+ def self.code_fetch(*arguments, redirects: 10)
154
154
  verb = arguments.first.to_code.to_s.downcase
155
- url = arguments.second.to_code.to_s
155
+ original_url = arguments.second.to_code.to_s
156
156
  options = arguments.third.to_code
157
157
  options = Dictionary.new if options.nothing?
158
158
  username = options.code_get("username").to_s
@@ -162,17 +162,19 @@ class Code
162
162
  data = options.code_get("data").raw || {}
163
163
  query = options.code_get("query").raw || {}
164
164
  query = query.to_a.flatten.map(&:to_s).each_slice(2).to_h.to_query
165
+
166
+ url = original_url
165
167
  url = "#{url}?#{query}" if query.present?
166
- uri = ::URI.parse(url)
167
- http = ::Net::HTTP.new(uri.host, uri.port)
168
- http.use_ssl = true if uri.scheme == "https"
169
168
 
170
169
  if username.present? || password.present?
171
- headers[
172
- "Authorization"
173
- ] = "Basic #{::Base64.strict_encode64("#{username}:#{password}")}"
170
+ authorization = ::Base64.strict_encode64("#{username}:#{password}")
171
+ headers["Authorization"] = "Basic #{authorization}"
174
172
  end
175
173
 
174
+ uri = ::URI.parse(url)
175
+ http = ::Net::HTTP.new(uri.host, uri.port)
176
+ http.use_ssl = true if uri.scheme == "https"
177
+
176
178
  request_class =
177
179
  case verb
178
180
  when "head"
@@ -197,12 +199,32 @@ class Code
197
199
  headers.each { |key, value| request[key.to_s] = value.to_s }
198
200
  request.body = body if body.present?
199
201
  request.set_form_data(**data.as_json) if data.present?
200
-
201
202
  response = http.request(request)
202
- code = response.code.to_i
203
- status = STATUS_CODES.key(code) || :ok
204
203
 
205
- Dictionary.new(code: code, status: status, body: response.body.to_s)
204
+ code = response.code.to_i
205
+ location = response["location"].to_s
206
+
207
+ if (300..399).cover?(code) && location.present? && redirects > 0
208
+ new_uri = ::URI.join(uri, location)
209
+
210
+ if new_uri.host == uri.host
211
+ code_fetch(
212
+ "get",
213
+ new_uri.to_s,
214
+ {
215
+ username: username,
216
+ password: password,
217
+ headers: headers
218
+ },
219
+ redirects: redirects - 1
220
+ )
221
+ else
222
+ code_fetch("get", new_uri.to_s, redirects: redirects - 1)
223
+ end
224
+ else
225
+ status = STATUS_CODES.key(code) || :ok
226
+ Dictionary.new(code: code, status: status, body: response.body.to_s)
227
+ end
206
228
  end
207
229
  end
208
230
  end
data/lib/code/type/sig.rb CHANGED
@@ -67,7 +67,11 @@ class Code
67
67
 
68
68
  def max_actual_arguments
69
69
  actual_arguments.sum do |argument|
70
- argument.is_an?(Object::Dictionary) ? [1, argument.code_size.raw].max : 1
70
+ if argument.is_an?(Object::Dictionary)
71
+ [1, argument.code_size.raw].max
72
+ else
73
+ 1
74
+ end
71
75
  end
72
76
  end
73
77
 
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.7.2
4
+ version: 1.7.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Dorian Marié
@@ -208,6 +208,7 @@ files:
208
208
  - ".rubocop.yml"
209
209
  - ".ruby-version"
210
210
  - ".tool-versions"
211
+ - AGENTS.md
211
212
  - Gemfile
212
213
  - Gemfile.lock
213
214
  - LICENSE