dsl_evaluator 0.2.4 → 0.3.1
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/CHANGELOG.md +9 -0
- data/README.md +21 -1
- data/lib/dsl_evaluator/printer/concern.rb +65 -0
- data/lib/dsl_evaluator/printer.rb +5 -17
- data/lib/dsl_evaluator/version.rb +1 -1
- data/lib/dsl_evaluator.rb +1 -0
- metadata +4 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 641dfdf2c67b8959300970f5bc19894204a2d55a58d9652d7eccd6e18632c5e2
|
4
|
+
data.tar.gz: 1e47b3a332e0af2f7fdaaaccfa7b561b53843d7e576f1f24eb9f11a00ea48d90
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 7cb86de8092865008528a23d1e1762a8883a8c69af372c254c01fc6e5a46441ddeadb8ba4467fc7433fbce4f4ae613879b4a76412e6ca2b7f09bba60c47ac87b
|
7
|
+
data.tar.gz: 9319047be3502508e571151109d3c11760050dc03f5eb97775409ce6bdc9025bf764680daec19b6c6ee2bb047eb8a453446d5003b2705febf52d0ca3e8f4bd71
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,15 @@
|
|
3
3
|
All notable changes to this project will be documented in this file.
|
4
4
|
This project *loosely tries* to adhere to [Semantic Versioning](http://semver.org/).
|
5
5
|
|
6
|
+
## [0.3.1] - 2022-07-11
|
7
|
+
- [#8](https://github.com/tongueroo/dsl_evaluator/pull/8) fix select pattern when not set
|
8
|
+
|
9
|
+
## [0.3.0] - 2022-03-14
|
10
|
+
- [#7](https://github.com/tongueroo/dsl_evaluator/pull/7) Print code improvements
|
11
|
+
|
12
|
+
## [0.2.5] - 2022-03-06
|
13
|
+
- [#6](https://github.com/tongueroo/dsl_evaluator/pull/6) DslEvaluator.print_code public method
|
14
|
+
|
6
15
|
## [0.2.4] - 2022-03-03
|
7
16
|
- print error message as part of trace
|
8
17
|
|
data/README.md
CHANGED
@@ -14,7 +14,6 @@ DslEvaluator.configure do |config|
|
|
14
14
|
config.root = Lono.root
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
17
|
class Dsl
|
19
18
|
include DslEvaluator
|
20
19
|
def build
|
@@ -24,6 +23,27 @@ class Dsl
|
|
24
23
|
end
|
25
24
|
```
|
26
25
|
|
26
|
+
## Print Code Helper
|
27
|
+
|
28
|
+
For other libraries where printing the code and context lines around the code is useful, you can use `DslEvaluator.print_code`.
|
29
|
+
|
30
|
+
The `print_code` method understands "polymorphic" arguments.
|
31
|
+
|
32
|
+
1. If the caller line info is part of a standard ruby backtrace line. Example of this is in ufo [helpers/ecr.rb](https://github.com/boltops-tools/ufo/blob/master/lib/ufo/task_definition/helpers/ecr.rb)
|
33
|
+
|
34
|
+
```ruby
|
35
|
+
call_line = ufo_config_call_line
|
36
|
+
DslEvaluator.print_code(call_line)
|
37
|
+
```
|
38
|
+
|
39
|
+
2. If the caller line info is custom. Example of this is in ufo [erb/yaml.rb](https://github.com/boltops-tools/ufo/blob/9247b77c6ad2a3a6307155a2a130308a24668333/lib/ufo/task_definition/erb/yaml.rb#L16)
|
40
|
+
|
41
|
+
```ruby
|
42
|
+
path = "replace with path to file"
|
43
|
+
line_number = "replace with line number. usually can get the exception.message"
|
44
|
+
DslEvaluator.print_code(path, line_number)
|
45
|
+
```
|
46
|
+
|
27
47
|
## Installation
|
28
48
|
|
29
49
|
Add this line to your application's Gemfile:
|
@@ -0,0 +1,65 @@
|
|
1
|
+
class DslEvaluator::Printer
|
2
|
+
module Concern
|
3
|
+
# So other libraries can use this method
|
4
|
+
# The `print_code` method understands "polymorphic" arguments.
|
5
|
+
# See README.md
|
6
|
+
def print_code(*args)
|
7
|
+
if args.size == 2 # print_code(path, line_number)
|
8
|
+
path, line_number = args
|
9
|
+
else # print_code(caller_line)
|
10
|
+
# IE: .ufo/config/web/dev.rb:10:in `block in evaluate_file'
|
11
|
+
# User passed in a "standard" ruby backtrace call line
|
12
|
+
# windows: "C:/Ruby31-x64/lib/ruby/gems/3.1.0/gems/terraspace-1.1.1/lib/terraspace/builder.rb:34:in `build'"
|
13
|
+
# linux: "/home/ec2-user/.rvm/gems/ruby-3.0.3/gems/terraspace-1.1.1/lib/terraspace/compiler/dsl/syntax/mod.rb:4:in `<module:Mod>'"
|
14
|
+
caller_line = args[0]
|
15
|
+
parts = caller_line.split(':')
|
16
|
+
is_windows = caller_line.match(/^[a-zA-Z]:/) # windows vs linux
|
17
|
+
calling_file = is_windows ? parts[1] : parts[0]
|
18
|
+
line_number = is_windows ? parts[2] : parts[1]
|
19
|
+
path = calling_file
|
20
|
+
end
|
21
|
+
|
22
|
+
check_line_number!(line_number)
|
23
|
+
line_number = line_number.to_i
|
24
|
+
|
25
|
+
logger.info "Here's the original caller line from:"
|
26
|
+
logger.info pretty_path(path).color(:green)
|
27
|
+
|
28
|
+
contents = IO.read(path)
|
29
|
+
content_lines = contents.split("\n")
|
30
|
+
context = 5 # lines of context
|
31
|
+
top, bottom = [line_number-context-1, 0].max, line_number+context-1
|
32
|
+
lpad = content_lines.size.to_s.size
|
33
|
+
content_lines[top..bottom].each_with_index do |line_content, index|
|
34
|
+
current_line = top+index+1
|
35
|
+
if current_line == line_number
|
36
|
+
printf("%#{lpad}d %s\n".color(:red), current_line, line_content)
|
37
|
+
else
|
38
|
+
printf("%#{lpad}d %s\n", current_line, line_content)
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
logger.info "Rerun with FULL_BACKTRACE=1 to see full backtrace" unless ENV['FULL_BACKTRACE']
|
43
|
+
end
|
44
|
+
|
45
|
+
def check_line_number!(line_number)
|
46
|
+
return line_number unless line_number.is_a?(String)
|
47
|
+
integer = line_number.to_i
|
48
|
+
if integer == 0
|
49
|
+
logger.error "ERROR: Think you accidentally passed in a String for the line_number: #{line_number}".color(:red)
|
50
|
+
puts caller
|
51
|
+
exit 1
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def pretty_path(path)
|
56
|
+
path.sub("#{Dir.pwd}/",'').sub(/^\.\//,'')
|
57
|
+
end
|
58
|
+
|
59
|
+
# Replace HOME with ~ - different from the main pretty_path
|
60
|
+
def pretty_home(path)
|
61
|
+
path.sub(ENV['HOME'], '~')
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
@@ -9,26 +9,14 @@ module DslEvaluator
|
|
9
9
|
info = error_info
|
10
10
|
path = info[:path]
|
11
11
|
line_number = info[:line_number].to_i
|
12
|
-
|
13
12
|
logger.error "ERROR: #{@error.message}".color(:red)
|
14
13
|
logger.error "Error evaluating #{pretty_path(path)}".color(:red)
|
15
14
|
logger.error "Here's the line with the error:\n\n"
|
15
|
+
print_code(path, line_number)
|
16
|
+
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
context = 5 # lines of context
|
20
|
-
top, bottom = [line_number-context-1, 0].max, line_number+context-1
|
21
|
-
lpad = content_lines.size.to_s.size
|
22
|
-
content_lines[top..bottom].each_with_index do |line_content, index|
|
23
|
-
current_line = top+index+1
|
24
|
-
if current_line == line_number
|
25
|
-
printf("%#{lpad}d %s\n".color(:red), current_line, line_content)
|
26
|
-
else
|
27
|
-
printf("%#{lpad}d %s\n", current_line, line_content)
|
28
|
-
end
|
29
|
-
end
|
30
|
-
|
31
|
-
logger.info "Rerun with FULL_BACKTRACE=1 to see full backtrace" unless ENV['FULL_BACKTRACE']
|
18
|
+
def print_code(path, line_number)
|
19
|
+
DslEvaluator.print_code(path, line_number)
|
32
20
|
end
|
33
21
|
|
34
22
|
def error_info
|
@@ -86,7 +74,7 @@ module DslEvaluator
|
|
86
74
|
|
87
75
|
def select(lines)
|
88
76
|
pattern = config.backtrace.select_pattern
|
89
|
-
return unless pattern
|
77
|
+
return lines unless pattern
|
90
78
|
|
91
79
|
lines.select do |l|
|
92
80
|
if pattern.is_a?(String)
|
data/lib/dsl_evaluator.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: dsl_evaluator
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tung Nguyen
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-
|
11
|
+
date: 2022-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -89,6 +89,7 @@ files:
|
|
89
89
|
- lib/dsl_evaluator/autoloader.rb
|
90
90
|
- lib/dsl_evaluator/logger.rb
|
91
91
|
- lib/dsl_evaluator/printer.rb
|
92
|
+
- lib/dsl_evaluator/printer/concern.rb
|
92
93
|
- lib/dsl_evaluator/version.rb
|
93
94
|
homepage: https://github.com/tongueroo/dsl_evaluator
|
94
95
|
licenses:
|
@@ -110,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
111
|
- !ruby/object:Gem::Version
|
111
112
|
version: '0'
|
112
113
|
requirements: []
|
113
|
-
rubygems_version: 3.
|
114
|
+
rubygems_version: 3.3.12
|
114
115
|
signing_key:
|
115
116
|
specification_version: 4
|
116
117
|
summary: DSL evaluation library. It produces a human-friendly backtrace error
|