Class: SimpleCov::Profiles

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

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

#autoload_profile(name) ⇒ void

This method returns an undefined value.

Tries require "simplecov/profiles/<name>", then require "simplecov-profile-<name>"; swallows LoadError so fetch_proc raises the user-facing error.

Parameters:

  • name (Symbol)


1465
1466
1467
1468
1469
1470
1471
1472
1473
1474
1475
# File 'sig/simplecov.rbs', line 1465

def autoload_profile(name)
  require "simplecov/profiles/#{name}"
rescue LoadError
  begin
    # simplecov:disable — third-party gem fallback (no such gem in test env)
    require "simplecov-profile-#{name}"
    # simplecov:enable
  rescue LoadError
    # fall through; #fetch_proc raises the user-facing error
  end
end

#define(name) { ... } ⇒ profile_proc

Raises SimpleCov::ConfigurationError when the name is taken. The block runs via instance_exec against the SimpleCov module itself (which extends Configuration), not a Configuration instance.

Parameters:

  • name (Symbol, String)

Yields:

Yield Returns:

  • (void)

Returns:

  • (profile_proc)


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) ⇒ profile_proc

Returns the proc for the given profile name, autoloading bundled ("simplecov/profiles/") or plugin-gem ("simplecov-profile-") profiles on first lookup. Raises SimpleCov::ConfigurationError when none is found.

Parameters:

  • name (Symbol, String)

Returns:

  • (profile_proc)


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) ⇒ void

This method returns an undefined value.

Applies the named profile via SimpleCov.configure.

Parameters:

  • name (Symbol, String)


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

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