./lib/overload/raise_variants.rb in lux-fw-0.5.37 vs ./lib/overload/raise_variants.rb in lux-fw-0.6.2
- old
+ new
@@ -1,69 +1,60 @@
-class LocalRaiseError < StandardError
-end
-
class Object
# raise object
def r what
- opath = what.class.ancestors
- out = opath.join("\n> ")
+ if what.is_a?(Method)
+ rr [:source_location, what.source_location.join(':')]
+ else
+ rr what
+ end
- 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
+ what = what.respond_to?(:to_jsonp) ? what.to_jsonp : what.inspect
+ raise StandardError.new(what.nil? ? 'nil' : what)
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 ---']
+ def rr what, as_jsonp = false
+ klass = what.class
+ klass = '%s at %s' % [klass, what.source_location.join(':').sub(Lux.root.to_s, '.')] if klass == Method
+ from = caller[0].include?('raise_variants.rb') ? caller[1] : caller[0]
+ from = from.sub(Lux.root.to_s+'/', './').split(':in ').first
+ header = '--- START (%s) %s - %s ---' % [klass, from, Lux.current.request.url]
+ as_jsonp = true if ['HashWia', 'Hash'].include?(what.class.to_s)
+ if as_jsonp
+ puts header
+ puts what.to_jsonp
+ puts '--- END ---'
+ else
+ ap [header, what, '--- END ---']
+ end
end
# unique methods for object
# includes methods from modules
- def rm object
+ def r? object
dump = []
- dump.push ['Class', object.class]
+ dump.push 'Class: %s' % 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', _]
+ dump.push 'Parent Class: %s' % _
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', class_unique.sort.join(', ')]
dump.push ['Uniqe from parent simple', object.class.instance_methods(false)]
- r dump
+ rr 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
@@ -72,6 +63,5 @@
def ap(*args)
puts args
end
end
end.call
-