Class: SimpleCov::Profiles

Inherits:
Hash
  • Object
show all
Defined in:
lib/simplecov/profiles.rb

Overview

Profiles are SimpleCov configuration procs that can be easily loaded using SimpleCov.start :rails and defined using

SimpleCov.profiles.define :foo do
  # SimpleCov configuration here, same as in  SimpleCov.configure
end

Instance Method Summary collapse

Instance Method Details

#define(name, &blk) ⇒ Object

Define a SimpleCov profile:

SimpleCov.profiles.define 'rails' do
  # Same as SimpleCov.configure do .. here
end


18
19
20
21
22
23
# File 'lib/simplecov/profiles.rb', line 18

def define(name, &blk)
  name = name.to_sym
  raise SimpleCov::ConfigurationError, "SimpleCov Profile '#{name}' is already defined" unless self[name].nil?

  self[name] = blk
end

#fetch_proc(name) ⇒ Object

Returns the proc registered for the given profile name, autoloading bundled or plugin-gem profiles on first lookup. Raises if the profile cannot be located.

Lookup order:

1. already registered via #define
2. require "simplecov/profiles/<name>"   (bundled profiles)
3. require "simplecov-profile-<name>"    (third-party plugin gems)


42
43
44
45
46
47
48
# File 'lib/simplecov/profiles.rb', line 42

def fetch_proc(name)
  name = name.to_sym
  autoload_profile(name) unless key?(name)
  return self[name] if key?(name)

  raise SimpleCov::ConfigurationError, "Could not find SimpleCov Profile called '#{name}'"
end

#load(name) ⇒ Object

Applies the profile of given name on SimpleCov.configure



28
29
30
# File 'lib/simplecov/profiles.rb', line 28

def load(name)
  SimpleCov.configure(&fetch_proc(name))
end