diff --git a/README.md b/README.md index da1439a..d8f63d6 100644 --- a/README.md +++ b/README.md @@ -8,13 +8,24 @@ A gem for making sure some code is running. Sometimes when coding, you run into a situation where you want to make sure a bit of code is being executed by your application. You might end up -typing something like: +typing something like the following, where you aren't positive if the code about `@noises_made` being run ~~~ruby -try_this -puts 'this is running' -try_another -puts 'blasfdd' +class Animal + def make_noise + @noises_made ||= 0 + @noises_made += 1 + puts 'noises are being made!' + nil + end +end + +class Dog < Animal + def make_noise + super + 'bark' + end +end ~~~ This way, you can run your code and check your logs to see if the `put` @@ -22,15 +33,21 @@ methods were called. If this short and simple effective method works for you, then give `aqui` a shot next time. It looks like this: ~~~ruby -try_this -aqui -try_another -aqui +class Animal + def make_noise + @noises_made ||= 0 + @noises_made += 1 + aqui # <= add this! + nil + end +end ~~~ This time, the output is colorized and contains information about where the code is running: -![screenshot](http://i.imgur.com/2AdA8YB.png) +![screenshot](http://i.imgur.com/M1ULD9O.png) + +Handy, huh? ## Installation diff --git a/Rakefile b/Rakefile index dffb605..250f832 100644 --- a/Rakefile +++ b/Rakefile @@ -2,7 +2,7 @@ require "bundler/gem_tasks" require 'rspec/core/rake_task' desc "Run specs" -RSpec::Core::RakeTask.new do |t| +RSpec::Core::RakeTask.new do end task default: :spec diff --git a/lib/aqui/colorizer.rb b/lib/aqui/colorizer.rb index 311035c..9be2346 100644 --- a/lib/aqui/colorizer.rb +++ b/lib/aqui/colorizer.rb @@ -26,13 +26,18 @@ def object_class @object.class.to_s.colorize(:light_white) end + def method + "##{@parser.method}".colorize(:light_green) + end + def message [ file, line_break, line_number, spacer, - object_class + object_class, + method ].join('') end end diff --git a/lib/aqui/parser.rb b/lib/aqui/parser.rb index 3bb37b2..7ee1aa5 100644 --- a/lib/aqui/parser.rb +++ b/lib/aqui/parser.rb @@ -7,7 +7,7 @@ def initialize(caller_message) end def parts - @parts ||= @caller_message[0..@caller_message.index(':in `')].split(':') + @parts ||= @caller_message[0..method_index].split(':') end def file @@ -17,5 +17,15 @@ def file def line_number parts[1] end + + def method + @caller_message[method_index + 5..-2] + end + + private + + def method_index + @caller_message.index(':in `') + end end end diff --git a/lib/aqui/version.rb b/lib/aqui/version.rb index 07d583b..3fee13d 100644 --- a/lib/aqui/version.rb +++ b/lib/aqui/version.rb @@ -1,4 +1,4 @@ # Version File module Aqui - VERSION = "0.0.1" + VERSION = "0.1.0" end diff --git a/script/demo.rb b/script/demo.rb index f2ef627..23b7bab 100644 --- a/script/demo.rb +++ b/script/demo.rb @@ -1,13 +1,22 @@ require "bundler/setup" Bundler.require -class ClassName - def go - 1 + 2 - aqui - 3 + 4 +# Animal +class Animal + def make_noise + @noises_made ||= 0 + @noises_made += 1 aqui + nil + end +end + +# Dog +class Dog < Animal + def make_noise + super + 'bark' end end -Model.new.go +Dog.new.make_noise