Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions lib/pilfer/profiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@ def profile(*args, &app)
profile_files_matching(/./, *args, &app)
end

def profile_if(*args, &app)
if args.shift
profile(*args, &app)
else
app.call
end
end

def profile_files_matching(matcher, description = nil,
reporter_options = {},
profiler = method(:lineprof),
Expand Down
6 changes: 6 additions & 0 deletions spec/pilfer/profiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,12 @@
Pilfer::Profiler.new(reporter).
profile(description, reporter_options, profiler, start) { }
end

it 'should not run if conditioned and condition is false' do
reporter.should_not_receive(:write)
Pilfer::Profiler.new(reporter).
profile_if(false, description, reporter_options, profiler, start) { }
end
end

describe '#profile_files_matching' do
Expand Down