Sha256: 218e3d476e8c00149e02eb443364b058ad4a882c001847a3fe5574e564b54a27

Contents?: true

Size: 1.76 KB

Versions: 6

Compression:

Stored size: 1.76 KB

Contents

class LocalRaiseError < StandardError
end

class Object
  # raise object
  def r what
    opath = what.class.ancestors
    out   = opath.join("\n> ")

    data = what.is_a?(Hash) ? JSON.pretty_generate(what) : what.ai(plain:true)
    out = [data, out, ''].join("\n\n-\n\n")

    # unique_methods = what.methods - what.class.ancestors[0].instance_methods
    # raise unique_methods

    raise LocalRaiseError.new out
  end

  # better console log dump
  def rr what
    src = caller[0].sub(Lux.root.to_s+'/', '').sub(Lux.fw_root.to_s, 'lux-fw').split(':in `').first
    ap ['--- START (%s) %s ---' % [what.class, src], what, '--- END ---']
  end

  # unique methods for object
  # includes methods from modules
  def rm object
    dump = []

    dump.push ['Class', object.class]

    instance_unique = object.methods - object.class.ancestors[0].instance_methods
    class_unique    = object.methods

    object.class.ancestors.drop(1).each do |_|
      class_unique -= _.instance_methods

      if _.class != Module
        dump.push ['Parent Class', _]
        break
      end
    end

    dump.push ['Instance uniqe', instance_unique.sort] if instance_unique[0]
    dump.push ['Uniqe from parent', class_unique.sort]
    dump.push ['Uniqe from parent simple', object.class.instance_methods(false)]

    r dump
  end

  def rr! what
    print "\e[H\e[2J\e[3J" # clear osx screen :)
    rr what
  end

  # show method info
  # show User, :secure_hash
  def rr? instance, m
    el = instance.class.instance_method(m)
    puts el.source_location.join(':').yellow
    puts '-'
    puts el.source if el.respond_to?(:source)
    nil
  end
end

###

# if we dont have awesome print in prodction, define mock
method(:ap) rescue Proc.new do
  class Object
    def ap(*args)
      puts args
    end
  end
end.call

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
lux-fw-0.5.37 ./lib/overload/raise_variants.rb
lux-fw-0.5.36 ./lib/overload/raise_variants.rb
lux-fw-0.5.35 ./lib/overload/raise_variants.rb
lux-fw-0.5.34 ./lib/overload/raise_variants.rb
lux-fw-0.5.33 ./lib/overload/raise_variants.rb
lux-fw-0.5.32 ./lib/overload/raise_variants.rb