dsl_evaluator 0.2.4 → 0.2.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +3 -0
- data/README.md +8 -1
- data/lib/dsl_evaluator/printer.rb +4 -16
- data/lib/dsl_evaluator/version.rb +1 -1
- data/lib/dsl_evaluator.rb +31 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 75e69e5dcedabbb5526f3904000165c50045a1f1629957c576132daec5c538ee
|
4
|
+
data.tar.gz: 1ce18a76ee79dd815bf7284b3cf831097b48a0a863cefe1cd217b88e663d82fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d521c3290df0b2c6347a56233ae4ee4f24bc20e7c1eefe05c99cfe810ebd99fca9041ace34c5e43e2963e3a4fb52a2937310b72e5871d89d2ed1cf3459cb325f
|
7
|
+
data.tar.gz: 8456cdad0388860b6011e9c849712281dc00640a562fa44f9b3d2a67cccb3a9b89ee0eb8ff52aa07aa1153dfdae001a7c9e763ba9621afb8e775a32b17405a56
|
data/CHANGELOG.md
CHANGED
@@ -3,6 +3,9 @@
|
|
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.2.5] - 2022-03-06
|
7
|
+
- [#6](https://github.com/tongueroo/dsl_evaluator/pull/6) DslEvaluator.print_code public method
|
8
|
+
|
6
9
|
## [0.2.4] - 2022-03-03
|
7
10
|
- print error message as part of trace
|
8
11
|
|
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,14 @@ class Dsl
|
|
24
23
|
end
|
25
24
|
```
|
26
25
|
|
26
|
+
For other libraries where printing the code and context lines around the code is useful, you can use:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
path = "replace with path to file"
|
30
|
+
line_number = "replace with line number. usually can get the exception.message"
|
31
|
+
DslEvaluator.print_code(path, line_number)
|
32
|
+
```
|
33
|
+
|
27
34
|
## Installation
|
28
35
|
|
29
36
|
Add this line to your application's Gemfile:
|
@@ -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
|
data/lib/dsl_evaluator.rb
CHANGED
@@ -44,5 +44,36 @@ module DslEvaluator
|
|
44
44
|
end
|
45
45
|
memoize :config
|
46
46
|
|
47
|
+
# So other libraries can use this method
|
48
|
+
def print_code(path, line_number)
|
49
|
+
check_line_number!(line_number)
|
50
|
+
line_number = line_number.to_i
|
51
|
+
contents = IO.read(path)
|
52
|
+
content_lines = contents.split("\n")
|
53
|
+
context = 5 # lines of context
|
54
|
+
top, bottom = [line_number-context-1, 0].max, line_number+context-1
|
55
|
+
lpad = content_lines.size.to_s.size
|
56
|
+
content_lines[top..bottom].each_with_index do |line_content, index|
|
57
|
+
current_line = top+index+1
|
58
|
+
if current_line == line_number
|
59
|
+
printf("%#{lpad}d %s\n".color(:red), current_line, line_content)
|
60
|
+
else
|
61
|
+
printf("%#{lpad}d %s\n", current_line, line_content)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
|
65
|
+
logger.info "Rerun with FULL_BACKTRACE=1 to see full backtrace" unless ENV['FULL_BACKTRACE']
|
66
|
+
end
|
67
|
+
|
68
|
+
def check_line_number!(line_number)
|
69
|
+
return line_number unless line_number.is_a?(String)
|
70
|
+
integer = line_number.to_i
|
71
|
+
if integer == 0
|
72
|
+
logger.error "ERROR: Think you accidentally passed in a String for the line_number: #{line_number}".color(:red)
|
73
|
+
puts caller
|
74
|
+
exit 1
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
47
78
|
extend self
|
48
79
|
end
|
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.2.
|
4
|
+
version: 0.2.5
|
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-03-
|
11
|
+
date: 2022-03-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|