class Object
Public Instance Methods
__colorize__(obj)
click to toggle source
# File lib/cutter/colored_outputs.rb, line 4 def __colorize__ obj colors = Cutter::ColoredOutputs.colors_config color = colors[obj] || :default color != :default ? to_s.send(color) : to_s end
inspect!(*options) { || ... }
click to toggle source
inspect!
may be called inside any method as 'inspect! {}' or more rigorously as 'inspect!(binding)' Binding is a Ruby class: www.ruby-doc.org/core/classes/Binding.html
# File lib/cutter/inspection.rb, line 24 def inspect! *options, &block return true if Cutter::Inspection.quiet? # Getting binding _binding = options.first if options.first.class == Binding raise ArgumentError, "Try inspect(binding) or inspect! {}", caller if (!block_given? && !_binding) _binding ||= block.binding max = true if options.include? :max options << :instance << :max << :self << :caller if max options.uniq! iv = true if options.include? :instance # Want caller methods chain to be traced? - pass option :caller to #inspect! _caller = true if options.include? :caller self_inspection = eval('self.inspect', _binding) if options.include? :self # Basic info method_name = eval('__method__', _binding) class_name = eval('self.class', _binding) if method_name && (meth = method(method_name.to_sym)).respond_to?(:source_location) source_path, source_number = meth.source_location end puts "\n%s `%s' %s" % ['method:'.__colorize__(:method), method_name.__colorize__(:method_name), ('(maximal tracing)' if max)] puts " %s %s:%s" % ['source_location:'.__colorize__(:source), source_path.dup.__colorize__(:source_path), source_number.to_s.__colorize__(:source_number)] if source_path && source_number puts " %s %s" % ['called from class:'.__colorize__(:called_from), class_name.__colorize__(:class_name)] # Local Variables lvb = eval('local_variables',_binding) puts " %s %s" % ['local_variables:'.__colorize__(:lv), ("[]" if lvb.empty?)] lvb.map do |lv| local_variable = eval(lv.to_s, _binding) local_variable = (max ? local_variable.inspect : local_variable.__real_to_s__) puts " %s: %s" % [lv.__colorize__(:lv_names), local_variable.__colorize__(:lv_values)] end if lvb # Instance Variables begin ivb = eval('instance_variables',_binding) puts " %s %s" % ["instance_variables:".__colorize__(:iv), ("[]" if ivb.empty?)] ivb.map do |iv| instance_variable = eval(iv.to_s, _binding) instance_variable = (max ? instance_variable.inspect : instance_variable.__real_to_s__) puts " %s: %s" % [iv.__colorize__(:iv_names), instance_variable.__colorize__(:iv_values)] end if ivb end if iv # Self inspection begin puts " self inspection:".__colorize__(:self_inspection) puts " %s" % self_inspection.__colorize__(:self_inspection_trace) end if self_inspection # Caller methods chain begin puts " caller methods: ".__colorize__(:caller_methods) caller.each do |meth| puts " %s" % meth.__colorize__(:caller_method) end end if _caller puts "\n" # Yield mysterious things if they exist in block. yield if block_given? end
Also aliased as: iii
line(sp = "")
click to toggle source
# File lib/cutter/colored_outputs.rb, line 10 def line sp = "" log_coloured sp, "------------------------------", color(:line) end
lll(object = nil)
click to toggle source
# File lib/cutter/inspection.rb, line 126 def lll object = nil Rails.logger.info object.inspect end
log_coloured(sp, msg, color = :default)
click to toggle source
# File lib/cutter/colored_outputs.rb, line 14 def log_coloured sp, msg, color = :default message = sp + msg message = color != :default ? message.send(color) : message puts message end
ppp(object = nil)
click to toggle source
# File lib/cutter/inspection.rb, line 122 def ppp object = nil puts object.inspect end
rrr(object = nil)
click to toggle source
# File lib/cutter/inspection.rb, line 118 def rrr object = nil raise object.inspect end
stamper(*args) { |scope| ... }
click to toggle source
# File lib/cutter/stamper.rb, line 8 def stamper *args, &block return if stamper_class.off? options = args.extract_options! name = args.first capture = options.delete :capture scope = stamper_class[name] || stamper_class[:default] scope.indent = stamper_class.last ? stamper_class.last.indent + 1 : 0 stamper_class.push scope msg = 'no msg' if scope message = scope.label.values.first end print "\n" spaces = " " * scope.indent log_coloured spaces, "#{message}", __color__(:message_name) log_coloured spaces, "#{'-'*message.length}", __color__(:message_line) scope.time_initial = Time.now (class << self; self end).send :define_method, :stamp do |*args| scope.stamp args.first end (class << self; self end).send :define_method, :stamp! do |*args| scope.stamp args.first end capture ? capture_stdout { yield scope } : yield(scope) (class << self; self end).send :remove_method, :stamp if respond_to? :stamp (class << self; self end).send :remove_method, :stamp! if respond_to? :stamp! scope.indent -= 1 if scope.indent > 0 stamper_class.pop time_passed = Time.now.ms_since scope.time_initial tps = "#{time_passed}ms" offset = message.length - tps.length offset = 0 if offset < 0 log_coloured spaces, "#{'-'*message.length}", __color__(:total_line) log_coloured spaces + "#{' ' * (offset)}", tps, __color__(:total_count) print "\n" tps end
Protected Instance Methods
__real_to_s__()
click to toggle source
“Real string”. It is now used to print Symbols with colons
# File lib/cutter/inspection.rb, line 107 def __real_to_s__ case self when Symbol, Array, Hash inspect else to_s end end
Private Instance Methods
__color__(type)
click to toggle source
# File lib/cutter/stamper.rb, line 66 def __color__ type stamper_class.colors_config[type] if stamper_class.colors? end
stamper_class()
click to toggle source
# File lib/cutter/stamper.rb, line 70 def stamper_class Cutter::Stamper end