dorian-eval 1.2.0 → 1.3.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/lib/dorian/eval.rb +35 -13
  4. metadata +17 -3
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: b21f0fd649da60ad757aee35c4cd37882238256ad3cce477d4ef091251958ce0
4
- data.tar.gz: '08c67d23fabfcb66678e1527ec0743ce3e920162f1b947126384e2623bb3e928'
3
+ metadata.gz: 0e3397d795e44365e644442920fa42a4e0059b9ae6c973c6229789022b717ea0
4
+ data.tar.gz: 1e273dea96c18ea6b2e29f8bd8be8acbaa534d9c9c062caa617ba80943e86ddb
5
5
  SHA512:
6
- metadata.gz: 28a5aa59bcb7da623d70f44094ab1c85fd49bee49aebaf84bed690227b044a040f20a30fbcfaea4a03a31ae2a5b460268a4834a21b52fd4889f5b80d98874ae4
7
- data.tar.gz: 2cbb210c32dc52ef8dd9f46002f1e0b1d21f25293322174b0b634b71d27a076af9686d030e7d35088e2f8daf64be645998114f20ec2ed3ac7ef282beaf53a2ab
6
+ metadata.gz: 4c74e41390380d59c9a9d3689a319662e688e109aa85b226e18c4dfd37bbbc2dc04e976ce68f09512a3f711345768ab1261f9fe9fe1d0a294cdd12d34546e7a4
7
+ data.tar.gz: 3432b27087c160ebb42d5640c65489705e5a99891ed7d09340cb3fdc208dc21b2fb59d57b923a8c5f1de15a6c8864a0589b9aea9534284d4c132f73c29de6484
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.2.0
1
+ 1.3.0
data/lib/dorian/eval.rb CHANGED
@@ -1,28 +1,33 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require "yaml"
4
+
3
5
  class Dorian
4
6
  class Eval
5
- attr_reader :ruby, :it, :debug, :stdout, :stderr, :colorize, :rails
7
+ Return = Data.define(:stdout, :stderr, :returned)
8
+
9
+ attr_reader :ruby, :it, :debug, :stdout, :stderr, :colorize, :rails, :returns
6
10
 
7
11
  COLORS = { red: "\e[31m", green: "\e[32m", reset: "\e[0m" }.freeze
8
12
 
9
13
  def initialize(
10
- *args,
11
- ruby: "",
12
- it: "",
14
+ ruby: nil,
15
+ it: nil,
13
16
  debug: false,
14
17
  stdout: true,
15
18
  stderr: true,
16
19
  colorize: false,
17
- rails: false
20
+ rails: false,
21
+ returns: false
18
22
  )
19
- @ruby = ruby.empty? ? args.join(" ") : ruby
20
- @it = it
23
+ @ruby = ruby.to_s.empty? ? "nil" : ruby
24
+ @it = it.to_s.empty? ? nil : it
21
25
  @debug = !!debug
22
26
  @stdout = !!stdout
23
27
  @stderr = !!stderr
24
28
  @colorize = !!colorize
25
29
  @rails = !!rails
30
+ @returns = !!returns
26
31
  end
27
32
 
28
33
  def self.eval(...)
@@ -46,7 +51,11 @@ class Dorian
46
51
  err += gets(read_err, color: :red, print: stderr?, method: :warn).to_s
47
52
  end
48
53
 
49
- [out, err]
54
+ if returns?
55
+ Return.new(stdout: out, stderr: err, returned: YAML.safe_load(out))
56
+ else
57
+ Return.new(stdout: out, stderr: err, returned: nil)
58
+ end
50
59
  end
51
60
 
52
61
  def debug?
@@ -69,15 +78,28 @@ class Dorian
69
78
  !!rails
70
79
  end
71
80
 
81
+ def returns?
82
+ !!returns
83
+ end
84
+
72
85
  def prefix
73
- debug? ? "[#{it}] " : ""
86
+ debug? && !returns? && it ? "[#{it}] " : ""
74
87
  end
75
88
 
76
89
  def full_ruby
77
- full_ruby = <<~RUBY
78
- it = #{it.inspect}
79
- #{ruby}
80
- RUBY
90
+ if returns?
91
+ full_ruby = <<~RUBY
92
+ require "yaml"
93
+
94
+ it = #{it.inspect}
95
+ puts (#{ruby}).to_yaml
96
+ RUBY
97
+ else
98
+ full_ruby = <<~RUBY
99
+ it = #{it.inspect}
100
+ #{ruby}
101
+ RUBY
102
+ end
81
103
 
82
104
  full_ruby = <<~RUBY if rails?
83
105
  require "#{Dir.pwd}/config/environment"
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: dorian-eval
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0
4
+ version: 1.3.0
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-08-29 00:00:00.000000000 Z
12
- dependencies: []
11
+ date: 2024-08-31 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: yaml
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  description: evaluates ruby
14
28
  email: dorian@dorianmarie.com
15
29
  executables: