dorian-eval 1.0.0 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (5) hide show
  1. checksums.yaml +4 -4
  2. data/VERSION +1 -1
  3. data/bin/eval +33 -9
  4. data/lib/dorian/eval.rb +34 -16
  5. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e5c8633bae8b5db55cbe5bc38d09e06f04f87618c6665b3a781cb6d284b50cea
4
- data.tar.gz: 91b5dce1c22902b23aa196b8dc5200ea7712c211b49e7b2fca47ac32c4ebece1
3
+ metadata.gz: cd6d10903e8c43ae9f0fbd906a87d2e8d689f404efe3490af4444d00427a35a2
4
+ data.tar.gz: 12ad8928f6052e1761174f6b8aeb242ce2b2e682dd8ff07f79896612d66c1524
5
5
  SHA512:
6
- metadata.gz: 73e30d2c70ec85b556b0f901129edf3d60ba5922e1973c8fb3c618ecbc1ecba945227bbb5f98fe38cea1618f72b2ae8a5063b9cace5ba5c9a35a8ba519a137d1
7
- data.tar.gz: cd8f9f463821b3aeb0de6efd8d05de5942bab9fb968b6df117e42ab462ab129a159d8657960d3c35cecea98df382a776f06438c0a5664202db54bee8220489bf
6
+ metadata.gz: afa0fb9a8bf3631d7ad589ae71917c276080be3224e8c7bcdca3bc64e2c5cc9f83c79a69537bfb672746e2163a0fc00625a4164f05513a6ca48edf284c71dcc2
7
+ data.tar.gz: 13b97ad458f8ddc4577e733f930a2dc947d7f023455d5ac81b60e28805d369914ee40800d7be4ce816b91d292908e33789e17b0f9174729e02d09b42b526381e
data/VERSION CHANGED
@@ -1 +1 @@
1
- 1.0.0
1
+ 1.1.0
data/bin/eval CHANGED
@@ -4,14 +4,37 @@
4
4
  require "dorian/arguments"
5
5
  require_relative "../lib/dorian/eval"
6
6
 
7
- parsed = Dorian::Arguments.parse(
8
- it: { type: :string, alias: :i },
9
- debug: { alias: :d },
10
- stdout: { aliases: [:out, :o], default: true },
11
- stderr: { aliases: [:err, :e], default: true },
12
- colorize: { aliases: [:color, :c], default: true },
13
- version: { alias: :v }, help: { alias: :h }
14
- )
7
+ parsed =
8
+ Dorian::Arguments.parse(
9
+ it: {
10
+ type: :string,
11
+ alias: :i
12
+ },
13
+ debug: {
14
+ alias: :d
15
+ },
16
+ stdout: {
17
+ aliases: %i[out o],
18
+ default: true
19
+ },
20
+ stderr: {
21
+ aliases: %i[err e],
22
+ default: true
23
+ },
24
+ colorize: {
25
+ aliases: %i[color c],
26
+ default: true
27
+ },
28
+ rails: {
29
+ alias: :r
30
+ },
31
+ version: {
32
+ alias: :v
33
+ },
34
+ help: {
35
+ alias: :h
36
+ }
37
+ )
15
38
 
16
39
  abort parsed.help if parsed.options.help
17
40
 
@@ -25,5 +48,6 @@ Dorian::Eval.eval(
25
48
  debug: parsed.options.debug,
26
49
  stdout: parsed.options.stdout,
27
50
  stderr: parsed.options.stderr,
28
- colorize: parsed.options.colorize
51
+ colorize: parsed.options.colorize,
52
+ rails: parsed.options.rails
29
53
  )
data/lib/dorian/eval.rb CHANGED
@@ -1,12 +1,8 @@
1
1
  class Dorian
2
2
  class Eval
3
- attr_reader :ruby, :it, :debug, :stdout, :stderr, :colorize
3
+ attr_reader :ruby, :it, :debug, :stdout, :stderr, :colorize, :rails
4
4
 
5
- COLORS = {
6
- red: "\e[31m",
7
- green: "\e[32m",
8
- reset: "\e[0m"
9
- }
5
+ COLORS = { red: "\e[31m", green: "\e[32m", reset: "\e[0m" }
10
6
 
11
7
  def initialize(
12
8
  *args,
@@ -15,7 +11,8 @@ class Dorian
15
11
  debug: false,
16
12
  stdout: true,
17
13
  stderr: true,
18
- colorize: false
14
+ colorize: false,
15
+ rails: false
19
16
  )
20
17
  @ruby = ruby.empty? ? args.join(" ") : ruby
21
18
  @it = it
@@ -23,6 +20,7 @@ class Dorian
23
20
  @stdout = !!stdout
24
21
  @stderr = !!stderr
25
22
  @colorize = !!colorize
23
+ @rails = !!rails
26
24
  end
27
25
 
28
26
  def self.eval(...)
@@ -33,15 +31,7 @@ class Dorian
33
31
  read_out, write_out = IO.pipe
34
32
  read_err, write_err = IO.pipe
35
33
 
36
- Process.spawn(
37
- RbConfig.ruby,
38
- "-e",
39
- "it = #{it.inspect}",
40
- "-e",
41
- ruby,
42
- out: write_out,
43
- err: write_err
44
- )
34
+ spawn(write_out:, write_err:)
45
35
 
46
36
  write_out.close
47
37
  write_err.close
@@ -73,10 +63,38 @@ class Dorian
73
63
  !!colorize
74
64
  end
75
65
 
66
+ def rails?
67
+ !!rails
68
+ end
69
+
76
70
  def prefix
77
71
  debug? ? "[#{it}] " : ""
78
72
  end
79
73
 
74
+ def full_ruby
75
+ full_ruby = <<~RUBY
76
+ it = #{it.inspect}
77
+ #{ruby}
78
+ RUBY
79
+
80
+ full_ruby = <<~RUBY if rails?
81
+ require "#{Dir.pwd}/config/environment"
82
+ #{full_ruby}
83
+ RUBY
84
+
85
+ full_ruby
86
+ end
87
+
88
+ def spawn(write_out:, write_err:)
89
+ Process.spawn(
90
+ RbConfig.ruby,
91
+ "-e",
92
+ full_ruby,
93
+ out: write_out,
94
+ err: write_err
95
+ )
96
+ end
97
+
80
98
  def gets(read, color: nil, print: true)
81
99
  original_string = read.gets
82
100
  return unless original_string
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.0.0
4
+ version: 1.1.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-24 00:00:00.000000000 Z
11
+ date: 2024-08-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: evaluates ruby
14
14
  email: dorian@dorianmarie.com