code-ruby 1.7.3 → 1.7.5
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 +4 -4
- data/AGENTS.md +6 -1
- data/Gemfile.lock +1 -1
- data/VERSION +1 -1
- data/lib/code/object/html.rb +0 -14
- data/lib/code/object/http.rb +8 -7
- data/lib/code-ruby.rb +1 -1
- data/lib/code.rb +4 -0
- data/spec/code_spec.rb +0 -3
- data/spec/spec_helper.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 3ecaa184268c66ccd57ebe14f443232fd458859cdf3f398dddc7bad4f9d99536
|
|
4
|
+
data.tar.gz: 53943ff49b7644e75b9ba86676a18034adf2d84a2241b39665da7f7c755891f2
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 91f87ae929470703d61c6f66870c9570423ebe85b340ba0fcc517d3337ec52a0f0ca58302df0ac316ed77189648a318e653e0d3c803357c7845ca2d46d81c39b
|
|
7
|
+
data.tar.gz: eb2ea363dc298d76b6ebdf5b1d5e492924381e64c4c63a94c99e487be6ff055e0607e370822a0645983163a2472a2e2e332f26d27495e7d459d268331665b563
|
data/AGENTS.md
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# Repository Guidelines
|
|
2
2
|
|
|
3
3
|
## Project Structure & Module Organization
|
|
4
|
+
|
|
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`.
|
|
5
6
|
- `bin/` — Executables and tooling shims: `bin/code` (CLI), `bin/rspec`, `bin/rubocop`, `bin/bundle`, `bin/bundler-audit`.
|
|
6
7
|
- `spec/` — RSpec tests. Shared setup in `spec/spec_helper.rb` (WebMock + Sinatra test app). File names end with `_spec.rb`.
|
|
@@ -8,6 +9,7 @@
|
|
|
8
9
|
- Root — `Gemfile`, `code-ruby.gemspec`, `Rakefile` (RSpec default), `.rubocop.yml`, `VERSION`.
|
|
9
10
|
|
|
10
11
|
## Build, Test, and Development Commands
|
|
12
|
+
|
|
11
13
|
- Install: `bundle install`
|
|
12
14
|
- Run all tests: `bundle exec rake` or `bin/rspec`
|
|
13
15
|
- Run one file/example: `bin/rspec spec/code_spec.rb:42`
|
|
@@ -17,22 +19,25 @@
|
|
|
17
19
|
- CLI examples: `bin/code -h`, `bin/code -p '1+2'`, `bin/code -t 2 'loop { }'`
|
|
18
20
|
|
|
19
21
|
## Coding Style & Naming Conventions
|
|
22
|
+
|
|
20
23
|
- Ruby 3.4.5; 2-space indentation; keep `# frozen_string_literal: true`.
|
|
21
24
|
- Follow `.rubocop.yml`; prefer small, single-responsibility classes under `lib/code/...` reflecting their constants.
|
|
22
25
|
- File names: snake_case; tests mirror source paths under `spec/` with `_spec.rb` suffix.
|
|
23
26
|
|
|
24
27
|
## Testing Guidelines
|
|
28
|
+
|
|
25
29
|
- Framework: RSpec. Network calls are disabled via WebMock; use the provided `FakeHttpBin` rack app for HTTP behavior.
|
|
26
30
|
- Add focused specs near the feature (e.g., parser under `spec/code/parser/*`, objects under `spec/code/object/*`).
|
|
27
31
|
- For language-level behaviors, extend `spec/code_spec.rb` with input → output examples.
|
|
28
32
|
- Ensure new behavior has at least one positive and one edge/failure case.
|
|
29
33
|
|
|
30
34
|
## Commit & Pull Request Guidelines
|
|
35
|
+
|
|
31
36
|
- Commits: short, imperative subjects (e.g., "fix parser whitespace"). Version bumps (`VERSION`, `vX.Y.Z`) are handled by maintainers.
|
|
32
37
|
- PRs: include a clear description, reproduction or CLI examples, and links to issues. Update docs in `docs/` when grammar/precedence changes.
|
|
33
38
|
- Keep diffs minimal and focused; include tests and run `bin/rubocop` before submitting.
|
|
34
39
|
|
|
35
40
|
## Security & Configuration Tips
|
|
41
|
+
|
|
36
42
|
- Tooling versions: see `.tool-versions`, `.ruby-version`, `.node-version`, `.npm-version`.
|
|
37
43
|
- 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
data/VERSION
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
1.7.
|
|
1
|
+
1.7.5
|
data/lib/code/object/html.rb
CHANGED
|
@@ -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
|
|
data/lib/code/object/http.rb
CHANGED
|
@@ -199,23 +199,24 @@ class Code
|
|
|
199
199
|
headers.each { |key, value| request[key.to_s] = value.to_s }
|
|
200
200
|
request.body = body if body.present?
|
|
201
201
|
request.set_form_data(**data.as_json) if data.present?
|
|
202
|
-
|
|
202
|
+
|
|
203
|
+
begin
|
|
204
|
+
response = http.request(request)
|
|
205
|
+
rescue ::Timeout::Error, ::Net::OpenTimeout, ::Net::ReadTimeout, ::Errno::ETIMEDOUT
|
|
206
|
+
raise(::Code::Error.new("timeout"))
|
|
207
|
+
end
|
|
203
208
|
|
|
204
209
|
code = response.code.to_i
|
|
205
210
|
location = response["location"].to_s
|
|
206
211
|
|
|
207
|
-
if (300..399).cover?(code) && location.present? && redirects
|
|
212
|
+
if (300..399).cover?(code) && location.present? && redirects.positive?
|
|
208
213
|
new_uri = ::URI.join(uri, location)
|
|
209
214
|
|
|
210
215
|
if new_uri.host == uri.host
|
|
211
216
|
code_fetch(
|
|
212
217
|
"get",
|
|
213
218
|
new_uri.to_s,
|
|
214
|
-
{
|
|
215
|
-
username: username,
|
|
216
|
-
password: password,
|
|
217
|
-
headers: headers
|
|
218
|
-
},
|
|
219
|
+
{ username: username, password: password, headers: headers },
|
|
219
220
|
redirects: redirects - 1
|
|
220
221
|
)
|
|
221
222
|
else
|
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/lib/code.rb
CHANGED
|
@@ -24,6 +24,8 @@ class Code
|
|
|
24
24
|
|
|
25
25
|
def self.parse(source, timeout: DEFAULT_TIMEOUT)
|
|
26
26
|
Timeout.timeout(timeout) { Parser.parse(source).to_raw }
|
|
27
|
+
rescue Timeout::Error
|
|
28
|
+
raise(Error.new("timeout"))
|
|
27
29
|
end
|
|
28
30
|
|
|
29
31
|
def self.evaluate(...)
|
|
@@ -42,6 +44,8 @@ class Code
|
|
|
42
44
|
timeout: timeout
|
|
43
45
|
)
|
|
44
46
|
end
|
|
47
|
+
rescue Timeout::Error
|
|
48
|
+
raise(Error.new("timeout"))
|
|
45
49
|
end
|
|
46
50
|
|
|
47
51
|
private
|
data/spec/code_spec.rb
CHANGED
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
|
|
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
|