module Tanj

Constants

VERSION

Public Class Methods

array(name, options = {}) click to toggle source
# File lib/tanj.rb, line 17
def self.array(name, options = {})
  b = binding.of_caller(1)

  if options[:index]
    options[:index].map! do |idx|
      if idx.is_a? Symbol
        { name: idx, value: b.eval(idx.to_s) }
      elsif idx.is_a? Range
        [
          idx.begin.is_a?(Symbol) ?
            { name: idx.begin, value: b.eval(idx.begin.to_s) } : { value: idx.begin },
          idx.end.is_a?(Symbol) ?
            { name: idx.end, value: b.eval(idx.end.to_s) } : { value: idx.end }
        ]
      else
        idx
      end
    end
  end

  log(caller_locations[0], {
    type: "array",
    value: b.eval(name.to_s),
    name: name,
    options: options
  })
end
config(options) click to toggle source
# File lib/tanj.rb, line 13
def self.config(options)
  @@logger = options[:logger] unless options[:logger].nil?
end
here() click to toggle source
# File lib/tanj.rb, line 57
def self.here
  log(caller_locations[0], type: "here")
end
message(msg) click to toggle source
# File lib/tanj.rb, line 53
def self.message(msg)
  log(caller_locations[0], type: "message", message: msg)
end
var(name) click to toggle source
# File lib/tanj.rb, line 45
def self.var(name)
  log(caller_locations[0], {
    type: "variable",
    value: binding.of_caller(1).eval(name.to_s),
    name: name
  })
end

Private Class Methods

log(location, hash) click to toggle source
# File lib/tanj.rb, line 63
def self.log(location, hash)
  hash[:where] = {line_num: location.lineno, path: location.absolute_path, label: location.label}
  @@logger.log "tanj| #{hash.to_json}"
end