dorian-eval 1.3.0 → 1.4.0
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/VERSION +1 -1
- data/lib/dorian/eval.rb +37 -13
- 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: 10646b3b875591f349e5b45416f4a96705d23b948fe9b2ee065d7ceed5bb5619
|
4
|
+
data.tar.gz: 542b45a942b3fc281385163ae9f158d8f3227a73547d04c6686b76622b768273
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3879cb847be21d2d6aaaebc2c92a998be47fa61fec48b573609c03ac680202487e39631447e88f712716c902dae69d19bce4e71c39ac51397c193fa67abdd3b2
|
7
|
+
data.tar.gz: ab6dd6ba4f37f0106c8f0a6a8ddad40eef87bbccaa6d6e813538cc99f04e652436e3d6b45004171db00917e97f80782d42a9c3ade3828499c9f1d043021f3bd2
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
1.
|
1
|
+
1.4.0
|
data/lib/dorian/eval.rb
CHANGED
@@ -6,7 +6,14 @@ class Dorian
|
|
6
6
|
class Eval
|
7
7
|
Return = Data.define(:stdout, :stderr, :returned)
|
8
8
|
|
9
|
-
attr_reader :ruby,
|
9
|
+
attr_reader :ruby,
|
10
|
+
:it,
|
11
|
+
:debug,
|
12
|
+
:stdout,
|
13
|
+
:stderr,
|
14
|
+
:colorize,
|
15
|
+
:rails,
|
16
|
+
:returns
|
10
17
|
|
11
18
|
COLORS = { red: "\e[31m", green: "\e[32m", reset: "\e[0m" }.freeze
|
12
19
|
|
@@ -86,20 +93,37 @@ class Dorian
|
|
86
93
|
debug? && !returns? && it ? "[#{it}] " : ""
|
87
94
|
end
|
88
95
|
|
89
|
-
def
|
90
|
-
if
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
96
|
+
def to_ruby(ruby)
|
97
|
+
if ruby.is_a?(Struct)
|
98
|
+
keys = ruby.to_h.keys.map { |key| to_ruby(key) }
|
99
|
+
values = ruby.to_h.values.map { |value| to_ruby(value) }
|
100
|
+
"Struct.new(#{keys.join(", ")}).new(#{values.join(", ")})"
|
101
|
+
elsif ruby.is_a?(String) || ruby.is_a?(Symbol) || ruby.is_a?(NilClass) ||
|
102
|
+
ruby.is_a?(TrueClass) || ruby.is_a?(FalseClass) || ruby.is_a?(Float) ||
|
103
|
+
ruby.is_a?(Integer)
|
104
|
+
ruby.inspect
|
105
|
+
elsif ruby.is_a?(Array)
|
106
|
+
"[#{ruby.map { |element| to_ruby(element) }.join(", ")}]"
|
107
|
+
elsif ruby.is_a?(Hash)
|
108
|
+
"{#{ruby.map { |key, value| "#{to_ruby(key)} => #{to_ruby(value)}" }}}"
|
97
109
|
else
|
98
|
-
|
99
|
-
it = #{it.inspect}
|
100
|
-
#{ruby}
|
101
|
-
RUBY
|
110
|
+
raise "#{ruby.class} not supported"
|
102
111
|
end
|
112
|
+
end
|
113
|
+
|
114
|
+
def full_ruby
|
115
|
+
full_ruby = "it = #{to_ruby(it)}\n"
|
116
|
+
full_ruby +=
|
117
|
+
if returns?
|
118
|
+
<<~RUBY
|
119
|
+
require "yaml"
|
120
|
+
puts (#{ruby}).to_yaml
|
121
|
+
RUBY
|
122
|
+
else
|
123
|
+
<<~RUBY
|
124
|
+
#{ruby}
|
125
|
+
RUBY
|
126
|
+
end
|
103
127
|
|
104
128
|
full_ruby = <<~RUBY if rails?
|
105
129
|
require "#{Dir.pwd}/config/environment"
|