Class: BenchBloc::Bloc::Task

Inherits:
BenchBloc::Bloc show all
Defined in:
lib/bench_bloc/bloc_task.rb,
lib/bench_bloc/bloc/bloc_task.rb

Instance Attribute Summary collapse

Attributes inherited from BenchBloc::Bloc

#bloc_hash, #bloc_namespaces

Instance Method Summary collapse

Methods inherited from BenchBloc::Bloc

#[], #generate_bloc, #rake_bloc

Constructor Details

#initialize(namespace, bloc_task) ⇒ Task

Returns a new instance of Task.



10
11
12
13
14
# File 'lib/bench_bloc/bloc_task.rb', line 10

def initialize namespace, bloc_task
  super(bloc_task)
  @namespace = namespace
  parse_bloc_task bloc_task
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



3
4
5
# File 'lib/bench_bloc/bloc_task.rb', line 3

def description
  @description
end

#labelObject (readonly)

Returns the value of attribute label.



3
4
5
# File 'lib/bench_bloc/bloc_task.rb', line 3

def label
  @label
end

#namespaceObject (readonly)

Returns the value of attribute namespace.



3
4
5
# File 'lib/bench_bloc/bloc_task.rb', line 3

def namespace
  @namespace
end

#profileObject (readonly)

Returns the value of attribute profile.



3
4
5
# File 'lib/bench_bloc/bloc_task.rb', line 3

def profile
  @profile
end

#titleObject (readonly)

Returns the value of attribute title.



3
4
5
# File 'lib/bench_bloc/bloc_task.rb', line 3

def title
  @title
end

#to_profileObject (readonly)

Returns the value of attribute to_profile.



3
4
5
# File 'lib/bench_bloc/bloc_task.rb', line 3

def to_profile
  @to_profile
end

Instance Method Details

#rake_taskObject



16
17
18
19
20
21
22
23
24
25
# File 'lib/bench_bloc/bloc_task.rb', line 16

def rake_task
  desc description
  task namespace => :environment do
    to_profs = [to_profile.call].flatten
    bm_results = bm_run_results self, to_profs
    bm_log_results bm_results, description
    # run ruby-prof
    # format_ruby_prof(run_ruby_prof(new_task[:prof], tp)) if @options[:ruby_prof] == true
  end
end

#run_taskObject

TODO: Put into a TaskRunner class



18
19
20
21
22
23
24
25
26
# File 'lib/bench_bloc/bloc/bloc_task.rb', line 18

def run_task
  Benchmark.bm do |x|
    [to_profile.call].flatten.each do |otp|
      x.report(label.call(otp)) do
        profile.call(otp)
      end
    end
  end
end