Coder Social home page Coder Social logo

dsl_evaluator's Introduction

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:

DslEvaluator.configure do |config|
  config.backtrace.reject_pattern = "/lib/lono"
  config.logger = Lono.logger
  config.on_exception = :exit
  config.root = Lono.root
end

class 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
call_line = ufo_config_call_line
DslEvaluator.print_code(call_line)
  1. If the caller line info is custom. Example of this is in ufo erb/yaml.rb
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:

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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.