Class: BenchmarkSpec

Inherits:
Hash
  • Object
show all
Defined in:
lib/railsbench/benchmark_specs.rb

Constant Summary collapse

READERS =
%w(uri method post_data query_string new_session action controller session_data xhr raw_data)

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, hash) ⇒ BenchmarkSpec



13
14
15
16
# File 'lib/railsbench/benchmark_specs.rb', line 13

def initialize(name, hash)
  super(hash)
  @name = name
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



6
7
8
# File 'lib/railsbench/benchmark_specs.rb', line 6

def name
  @name
end

Class Method Details

.load(name, file_name = nil) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/railsbench/benchmark_specs.rb', line 23

def load(name, file_name = nil)
  unless file_name
    file_name = ENV['RAILS_ROOT'] + "/config/benchmarks.yml"
  end
  @@specs = YAML::load(ERB.new(IO.read(file_name)).result)
  raise "There is no benchmark named '#{name}'" unless @@specs[name]
  parse(@@specs, name)
end

.parse(specs, name) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/railsbench/benchmark_specs.rb', line 32

def parse(specs, name)
  spec = specs[name]
  if spec.is_a?(String)
    spec.split(/, */).collect!{ |n| parse(specs, n) }.flatten
  elsif spec.is_a?(Hash)
    [ BenchmarkSpec.new(name,spec) ]
  elsif spec.is_a?(Array)
    spec.collect{|n| parse(specs, n)}.flatten
  else
    raise "oops: unknown entry type in benchmark specification"
  end
end

Instance Method Details

#inspectObject



18
19
20
# File 'lib/railsbench/benchmark_specs.rb', line 18

def inspect
  "BenchmarkSpec(#{name},#{super})"
end