Skip to content

Commit

Permalink
adds method name to output
Browse files Browse the repository at this point in the history
  • Loading branch information
hstove committed Jan 27, 2015
1 parent 820d000 commit 0373265
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 20 deletions.
37 changes: 27 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,29 +8,46 @@ 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`
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

Expand Down
2 changes: 1 addition & 1 deletion Rakefile
Original file line number Diff line number Diff line change
Expand Up @@ -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
7 changes: 6 additions & 1 deletion lib/aqui/colorizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
12 changes: 11 additions & 1 deletion lib/aqui/parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
2 changes: 1 addition & 1 deletion lib/aqui/version.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Version File
module Aqui
VERSION = "0.0.1"
VERSION = "0.1.0"
end
21 changes: 15 additions & 6 deletions script/demo.rb
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 0373265

Please sign in to comment.