class DeepCover::Config

Constants

NOT_SPECIFIED

Public Class Methods

new(notify = nil) click to toggle source
# File lib/deep_cover/config.rb, line 7
def initialize(notify = nil)
  @notify = nil
  @options = {}
  set(**DEFAULTS)
  @notify = notify
end
options_to_ignored(**options) click to toggle source
# File lib/deep_cover/config.rb, line 112
def self.options_to_ignored(**options)
  OPTIONALLY_COVERED
    .select { |filter| options[FILTER_NAME[filter]] }
end

Public Instance Methods

[](opt) click to toggle source
# File lib/deep_cover/config.rb, line 97
def [](opt)
  public_send(opt)
end
[]=(opt, value) click to toggle source
# File lib/deep_cover/config.rb, line 101
def []=(opt, value)
  public_send(opt, value)
end
cache_directory(cache_directory = NOT_SPECIFIED) click to toggle source
Calls superclass method
# File lib/deep_cover/config.rb, line 85
def cache_directory(cache_directory = NOT_SPECIFIED)
  return File.expand_path(super) if cache_directory == NOT_SPECIFIED
  super
end
detect_uncovered(*keywords) click to toggle source
# File lib/deep_cover/config.rb, line 50
def detect_uncovered(*keywords)
  raise ArgumentError, 'No block is accepted' if block_given?
  unless keywords.empty?
    keywords = check_uncovered(keywords)
    set(**keywords.to_h { |kind| [FILTER_NAME[kind], false] })
  end
  OPTIONALLY_COVERED - Config.options_to_ignored(**@options)
end
exclude_paths(paths = NOT_SPECIFIED) click to toggle source
Calls superclass method
# File lib/deep_cover/config.rb, line 75
def exclude_paths(paths = NOT_SPECIFIED)
  paths = Array(paths).dup unless paths == NOT_SPECIFIED
  super
end
ignore_uncovered(*keywords, &block) click to toggle source
# File lib/deep_cover/config.rb, line 36
def ignore_uncovered(*keywords, &block)
  if block
    raise ArgumentError, "wrong number of arguments (given #{keywords.size}, expected 0..1)" if keywords.size > 1
    keywords << Node.unique_filter if keywords.empty?
    Node.create_filter(keywords.first, &block)
    AttributeAccessors.define_accessor(FILTER_NAME[keywords.first])
  end
  unless keywords.empty?
    keywords = check_uncovered(keywords)
    set(**keywords.to_h { |kind| [FILTER_NAME[kind], true] })
  end
  Config.options_to_ignored(**@options)
end
load_hash_for_serialize(hash) click to toggle source
# File lib/deep_cover/config.rb, line 28
def load_hash_for_serialize(hash)
  @options.merge!(hash)
  hash.each_key { |option| @notify.config_changed(option) } if @notify
  # This was already transformed, it should all be absolute paths / globs, avoid doing it for nothing by setting it right away
  # TODO: (Max) I don't like mixup of configs being partly on DeepCover and Config like that...
  DeepCover.instance_variable_set(:@lookup_globs, hash[:paths])
end
paths(paths = NOT_SPECIFIED) click to toggle source
Calls superclass method
# File lib/deep_cover/config.rb, line 80
def paths(paths = NOT_SPECIFIED)
  paths = Array(paths).dup unless paths == NOT_SPECIFIED
  super
end
reset() click to toggle source
# File lib/deep_cover/config.rb, line 90
def reset
  DEFAULTS.each do |key, value|
    change(key, value)
  end
  self
end
set(**options) click to toggle source
# File lib/deep_cover/config.rb, line 105
def set(**options)
  options.each do |key, value|
    self[key] = value
  end
  self
end
to_h()
Alias for: to_hash
to_hash() click to toggle source
# File lib/deep_cover/config.rb, line 14
def to_hash
  @options.dup
end
Also aliased as: to_h
to_hash_for_serialize() click to toggle source
# File lib/deep_cover/config.rb, line 19
def to_hash_for_serialize
  hash = to_hash
  # TODO: (Max) I don't like mixup of configs being partly on DeepCover and Config like that...
  hash[:paths] = DeepCover.lookup_globs
  hash[:output] &&= File.expand_path(hash[:output])
  hash[:cache_directory] = File.expand_path(hash[:cache_directory])
  hash
end

Private Instance Methods

change(option, value) click to toggle source
# File lib/deep_cover/config.rb, line 126
def change(option, value)
  if @options[option] != value
    @options[option] = value.freeze
    @notify.config_changed(option) if @notify.respond_to? :config_changed
  end
  self
end
check_uncovered(keywords) click to toggle source
# File lib/deep_cover/config.rb, line 119
def check_uncovered(keywords)
  keywords = keywords.first if keywords.size == 1 && keywords.first.is_a?(Array)
  unknown = keywords - OPTIONALLY_COVERED
  raise ArgumentError, "unknown options: #{unknown.join(', ')}" unless unknown.empty?
  keywords
end