dorian-eval 1.4.0 → 1.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/VERSION +1 -1
- data/bin/eval +17 -9
- data/lib/dorian/eval.rb +34 -11
- metadata +5 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d7a272daa6fb5f6fb24e3befe68aeb8d998f98c04ec2e836123000eb64451bd
|
4
|
+
data.tar.gz: '0955b048336373365f83d14a5b9e9ac7ba5e4feb46ae9fe3af1f26cbd7df4e5a'
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6dfb7752e53f551933c41e7ca4957701f1d68378100487b1bf8257896212d7d2fbe9d645e3606ac3ad0fad1f6a529a72a6f2b7915e0d4bf992987aa88691c541
|
7
|
+
data.tar.gz: 83f1f5e00173244d0f08922d963ba84cb563b8bf9e6524b855af001b7bee6059ef56c6da46e6ca0f3ad6083b4fd22dbc1cdf721bdba8427390bf9043fc5c625d
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.4.
|
1
|
+
1.4.2
|
data/bin/eval
CHANGED
@@ -28,6 +28,12 @@ parsed =
|
|
28
28
|
rails: {
|
29
29
|
alias: :r
|
30
30
|
},
|
31
|
+
returns: {
|
32
|
+
alias: :return
|
33
|
+
},
|
34
|
+
fast: {
|
35
|
+
alias: :f
|
36
|
+
},
|
31
37
|
version: {
|
32
38
|
alias: :v
|
33
39
|
},
|
@@ -42,12 +48,14 @@ if parsed.options.version
|
|
42
48
|
abort File.read(File.expand_path("../VERSION", __dir__))
|
43
49
|
end
|
44
50
|
|
45
|
-
Dorian::Eval.eval(
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
51
|
+
p Dorian::Eval.eval(
|
52
|
+
ruby: parsed.arguments.join(" "),
|
53
|
+
it: parsed.options.it,
|
54
|
+
debug: parsed.options.debug,
|
55
|
+
stdout: parsed.options.stdout,
|
56
|
+
stderr: parsed.options.stderr,
|
57
|
+
colorize: parsed.options.colorize,
|
58
|
+
rails: parsed.options.rails,
|
59
|
+
returns: parsed.options.returns,
|
60
|
+
fast: parsed.options.fast
|
61
|
+
)
|
data/lib/dorian/eval.rb
CHANGED
@@ -4,7 +4,12 @@ require "yaml"
|
|
4
4
|
|
5
5
|
class Dorian
|
6
6
|
class Eval
|
7
|
-
Return =
|
7
|
+
Return =
|
8
|
+
Data.define(:stdout, :stderr, :returned) do
|
9
|
+
def initialize(stdout: "", stderr: "", returned: nil)
|
10
|
+
super
|
11
|
+
end
|
12
|
+
end
|
8
13
|
|
9
14
|
attr_reader :ruby,
|
10
15
|
:it,
|
@@ -13,7 +18,8 @@ class Dorian
|
|
13
18
|
:stderr,
|
14
19
|
:colorize,
|
15
20
|
:rails,
|
16
|
-
:returns
|
21
|
+
:returns,
|
22
|
+
:fast
|
17
23
|
|
18
24
|
COLORS = { red: "\e[31m", green: "\e[32m", reset: "\e[0m" }.freeze
|
19
25
|
|
@@ -25,7 +31,8 @@ class Dorian
|
|
25
31
|
stderr: true,
|
26
32
|
colorize: false,
|
27
33
|
rails: false,
|
28
|
-
returns: false
|
34
|
+
returns: false,
|
35
|
+
fast: false
|
29
36
|
)
|
30
37
|
@ruby = ruby.to_s.empty? ? "nil" : ruby
|
31
38
|
@it = it.to_s.empty? ? nil : it
|
@@ -35,6 +42,7 @@ class Dorian
|
|
35
42
|
@colorize = !!colorize
|
36
43
|
@rails = !!rails
|
37
44
|
@returns = !!returns
|
45
|
+
@fast = !!fast
|
38
46
|
end
|
39
47
|
|
40
48
|
def self.eval(...)
|
@@ -42,6 +50,14 @@ class Dorian
|
|
42
50
|
end
|
43
51
|
|
44
52
|
def eval
|
53
|
+
fast? ? eval_fast : eval_slow
|
54
|
+
end
|
55
|
+
|
56
|
+
def eval_fast
|
57
|
+
Return.new(returned: Kernel.eval(full_ruby))
|
58
|
+
end
|
59
|
+
|
60
|
+
def eval_slow
|
45
61
|
read_out, write_out = IO.pipe
|
46
62
|
read_err, write_err = IO.pipe
|
47
63
|
|
@@ -61,10 +77,14 @@ class Dorian
|
|
61
77
|
if returns?
|
62
78
|
Return.new(stdout: out, stderr: err, returned: YAML.safe_load(out))
|
63
79
|
else
|
64
|
-
Return.new(stdout: out, stderr: err
|
80
|
+
Return.new(stdout: out, stderr: err)
|
65
81
|
end
|
66
82
|
end
|
67
83
|
|
84
|
+
def fast?
|
85
|
+
!!fast
|
86
|
+
end
|
87
|
+
|
68
88
|
def debug?
|
69
89
|
!!debug
|
70
90
|
end
|
@@ -94,27 +114,30 @@ class Dorian
|
|
94
114
|
end
|
95
115
|
|
96
116
|
def to_ruby(ruby)
|
97
|
-
|
117
|
+
case ruby
|
118
|
+
when Struct
|
98
119
|
keys = ruby.to_h.keys.map { |key| to_ruby(key) }
|
99
120
|
values = ruby.to_h.values.map { |value| to_ruby(value) }
|
100
121
|
"Struct.new(#{keys.join(", ")}).new(#{values.join(", ")})"
|
101
|
-
|
102
|
-
ruby.is_a?(TrueClass) || ruby.is_a?(FalseClass) || ruby.is_a?(Float) ||
|
103
|
-
ruby.is_a?(Integer)
|
122
|
+
when String, Symbol, NilClass, TrueClass, FalseClass, Float, Integer
|
104
123
|
ruby.inspect
|
105
|
-
|
124
|
+
when Array
|
106
125
|
"[#{ruby.map { |element| to_ruby(element) }.join(", ")}]"
|
107
|
-
|
126
|
+
when Hash
|
108
127
|
"{#{ruby.map { |key, value| "#{to_ruby(key)} => #{to_ruby(value)}" }}}"
|
109
128
|
else
|
110
129
|
raise "#{ruby.class} not supported"
|
111
130
|
end
|
112
131
|
end
|
113
132
|
|
133
|
+
def slow?
|
134
|
+
!fast?
|
135
|
+
end
|
136
|
+
|
114
137
|
def full_ruby
|
115
138
|
full_ruby = "it = #{to_ruby(it)}\n"
|
116
139
|
full_ruby +=
|
117
|
-
if returns?
|
140
|
+
if returns? && slow?
|
118
141
|
<<~RUBY
|
119
142
|
require "yaml"
|
120
143
|
puts (#{ruby}).to_yaml
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dorian-eval
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.4.
|
4
|
+
version: 1.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dorian Marié
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2024-
|
11
|
+
date: 2024-09-05 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: yaml
|
@@ -46,16 +46,16 @@ require_paths:
|
|
46
46
|
- lib
|
47
47
|
required_ruby_version: !ruby/object:Gem::Requirement
|
48
48
|
requirements:
|
49
|
-
- -
|
49
|
+
- - ">="
|
50
50
|
- !ruby/object:Gem::Version
|
51
|
-
version: 3
|
51
|
+
version: '3'
|
52
52
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
53
53
|
requirements:
|
54
54
|
- - ">="
|
55
55
|
- !ruby/object:Gem::Version
|
56
56
|
version: '0'
|
57
57
|
requirements: []
|
58
|
-
rubygems_version: 3.5.
|
58
|
+
rubygems_version: 3.5.16
|
59
59
|
signing_key:
|
60
60
|
specification_version: 4
|
61
61
|
summary: evaluates ruby
|