code-ruby 1.7.2 → 1.7.4

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: dd10d6e30e6104bd4502576334f3c8a4a7c35ccb96f9d88d8915bb750988b93c
4
+ data.tar.gz: ea0dd0d3511cc147ac64d67ddf152e30fba5e0bcc1b4f03e9cef5bfd3bdad206
5
5
  SHA512:
6
- metadata.gz: f68438e18649877cc651ed15d8ff70ab2232c3a12c5197e82919db711c22703c341868800f5f32aa49a61e45b72dae5320c514ae7adb8693b958cab5a1611baf
7
- data.tar.gz: d214dca53f89bf327c993bbca6680e1bf0d148e9d4ca02efa698ab789f10f91fb05edc5709a3ece84396872877beeab3fba9775b3c0f85f9b8b7d6ee86bb908d
6
+ metadata.gz: 48c33e339f68db73623f6bf43332f09b57454563903b9e9e8942a8d148d650e789b0b0e66ab9a7a0d68c340588ee896b3214891eab2785ee368c3caf3fc5bbec
7
+ data.tar.gz: 7f386fee01ca28936281aa5c4e7e34296107f39fcaa34d96ad2cd803a88a8215555d2cefe6027703d9a56be5ebb2dc6fe0afa97ef769b145b671200601d2851c
data/AGENTS.md ADDED
@@ -0,0 +1,43 @@
1
+ # Repository Guidelines
2
+
3
+ ## Project Structure & Module Organization
4
+
5
+ - `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`.
6
+ - `bin/` — Executables and tooling shims: `bin/code` (CLI), `bin/rspec`, `bin/rubocop`, `bin/bundle`, `bin/bundler-audit`.
7
+ - `spec/` — RSpec tests. Shared setup in `spec/spec_helper.rb` (WebMock + Sinatra test app). File names end with `_spec.rb`.
8
+ - `docs/` — Reference docs (e.g., operator precedence).
9
+ - Root — `Gemfile`, `code-ruby.gemspec`, `Rakefile` (RSpec default), `.rubocop.yml`, `VERSION`.
10
+
11
+ ## Build, Test, and Development Commands
12
+
13
+ - Install: `bundle install`
14
+ - Run all tests: `bundle exec rake` or `bin/rspec`
15
+ - Run one file/example: `bin/rspec spec/code_spec.rb:42`
16
+ - Lint: `bin/rubocop` (auto-fix: `bin/rubocop -A`)
17
+ - Security audit: `bin/bundler-audit update && bin/bundler-audit check`
18
+ - Build gem: `gem build code-ruby.gemspec`
19
+ - CLI examples: `bin/code -h`, `bin/code -p '1+2'`, `bin/code -t 2 'loop { }'`
20
+
21
+ ## Coding Style & Naming Conventions
22
+
23
+ - Ruby 3.4.5; 2-space indentation; keep `# frozen_string_literal: true`.
24
+ - Follow `.rubocop.yml`; prefer small, single-responsibility classes under `lib/code/...` reflecting their constants.
25
+ - File names: snake_case; tests mirror source paths under `spec/` with `_spec.rb` suffix.
26
+
27
+ ## Testing Guidelines
28
+
29
+ - Framework: RSpec. Network calls are disabled via WebMock; use the provided `FakeHttpBin` rack app for HTTP behavior.
30
+ - Add focused specs near the feature (e.g., parser under `spec/code/parser/*`, objects under `spec/code/object/*`).
31
+ - For language-level behaviors, extend `spec/code_spec.rb` with input → output examples.
32
+ - Ensure new behavior has at least one positive and one edge/failure case.
33
+
34
+ ## Commit & Pull Request Guidelines
35
+
36
+ - Commits: short, imperative subjects (e.g., "fix parser whitespace"). Version bumps (`VERSION`, `vX.Y.Z`) are handled by maintainers.
37
+ - PRs: include a clear description, reproduction or CLI examples, and links to issues. Update docs in `docs/` when grammar/precedence changes.
38
+ - Keep diffs minimal and focused; include tests and run `bin/rubocop` before submitting.
39
+
40
+ ## Security & Configuration Tips
41
+
42
+ - Tooling versions: see `.tool-versions`, `.ruby-version`, `.node-version`, `.npm-version`.
43
+ - Tests must not reach the network; rely on stubs/fixtures. Prefer timeouts (`-t/--timeout`) when evaluating untrusted input with `bin/code`.
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.4)
5
5
  activesupport
6
6
  base64
7
7
  bigdecimal
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.7.2
1
+ 1.7.4
@@ -20,9 +20,6 @@ class Code
20
20
  code_arguments = args.fetch(:arguments, []).to_code
21
21
 
22
22
  case code_operator.to_s
23
- when "link_to"
24
- sig(args) { [Object.maybe, Object.maybe] }
25
- code_link_to(*code_arguments.raw)
26
23
  when "escape"
27
24
  sig(args) { Object.maybe }
28
25
  code_escape(*code_arguments.raw)
@@ -31,17 +28,6 @@ class Code
31
28
  end
32
29
  end
33
30
 
34
- def self.code_link_to(text = nil, href = nil)
35
- code_text = text.to_code
36
- code_href = href.to_code
37
-
38
- String.new(<<~LINK.strip)
39
- <a
40
- href="#{CGI.escapeHTML(code_href.to_s)}"
41
- >#{CGI.escapeHTML(code_text.to_s)}</a>
42
- LINK
43
- end
44
-
45
31
  def self.code_escape(string = nil)
46
32
  code_string = string.to_code
47
33
 
@@ -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,28 @@ 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.positive?
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
+ { username: username, password: password, headers: headers },
215
+ redirects: redirects - 1
216
+ )
217
+ else
218
+ code_fetch("get", new_uri.to_s, redirects: redirects - 1)
219
+ end
220
+ else
221
+ status = STATUS_CODES.key(code) || :ok
222
+ Dictionary.new(code: code, status: status, body: response.body.to_s)
223
+ end
206
224
  end
207
225
  end
208
226
  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
 
data/lib/code-ruby.rb CHANGED
@@ -4,6 +4,7 @@ require "active_support/all"
4
4
  require "base64"
5
5
  require "bigdecimal"
6
6
  require "bigdecimal/util"
7
+ require "date"
7
8
  require "did_you_mean"
8
9
  require "json"
9
10
  require "language-ruby"
@@ -14,7 +15,6 @@ require "stringio"
14
15
  require "timeout"
15
16
  require "uri"
16
17
  require "zeitwerk"
17
- require "date"
18
18
 
19
19
  loader = Zeitwerk::Loader.for_gem(warn_on_extra_files: false)
20
20
  loader.ignore("#{__dir__}/code-ruby.rb")
data/spec/code_spec.rb CHANGED
@@ -137,9 +137,6 @@ RSpec.describe Code do
137
137
  IdentifierList.new
138
138
  IdentifierList.new([])
139
139
  Time.new(nothing).before?
140
- Html.link_to
141
- Html.link_to('/')
142
- Html.link_to('Home','/')
143
140
  Json.parse('1')
144
141
  Json.parse('[]')
145
142
  Json.parse('{}')
data/spec/spec_helper.rb CHANGED
@@ -7,7 +7,7 @@ require "webmock/rspec"
7
7
  class FakeHttpBin < Sinatra::Base
8
8
  set :host_authorization, { permitted_hosts: ["httpbin.org"] }
9
9
 
10
- %w[GET HEAD POST PUT DELETE CONNECT OPTIONS TRACE PATCH].each do |verb|
10
+ %w[GET HEAD POST PUT DELETE OPTIONS TRACE PATCH].each do |verb|
11
11
  route verb, "/status/:status" do
12
12
  status params[:status].to_i
13
13
  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.7.2
4
+ version: 1.7.4
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