Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/tongueroo/dsl_evaluator
Small module to help with DSL evaluation: produces a human-friendly backtrace error
https://github.com/tongueroo/dsl_evaluator
Last synced: 3 months ago
JSON representation
Small module to help with DSL evaluation: produces a human-friendly backtrace error
- Host: GitHub
- URL: https://github.com/tongueroo/dsl_evaluator
- Owner: tongueroo
- License: mit
- Created: 2020-05-12T18:04:56.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2024-04-22T23:16:02.000Z (9 months ago)
- Last Synced: 2024-04-23T00:31:40.989Z (9 months ago)
- Language: Ruby
- Size: 31.3 KB
- Stars: 0
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# DslEvaluator
Small module to help with DSL evaluation. Notably, it produces a human-friendly backtrace error showing the original user-provided source code if there's a syntax error.
## Usage
Example usage:
```ruby
DslEvaluator.configure do |config|
config.backtrace.reject_pattern = "/lib/lono"
config.logger = Lono.logger
config.on_exception = :exit
config.root = Lono.root
endclass Dsl
include DslEvaluator
def build
path = "/path/to/user/provided/dsl/file.rb"
evaluate_file(path) # from DslEvaluator module
end
end
```## Print Code Helper
For other libraries where printing the code and context lines around the code is useful, you can use `DslEvaluator.print_code`.
The `print_code` method understands "polymorphic" arguments.
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)
```ruby
call_line = ufo_config_call_line
DslEvaluator.print_code(call_line)
```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)
```ruby
path = "replace with path to file"
line_number = "replace with line number. usually can get the exception.message"
DslEvaluator.print_code(path, line_number)
```## Installation
Add this line to your application's Gemfile:
```ruby
gem 'dsl_evaluator'
```And then execute:
$ bundle install
Or install it yourself as:
$ gem install dsl_evaluator
## Contributing
Bug reports and pull requests are welcome on GitHub at https://github.com/tongueroo/dsl_evaluator.
## License
The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).