Class: DeepCover::Config

Inherits:
Object
  • Object
show all
Includes:
AttributeAccessors
Defined in:
lib/deep_cover/config.rb

Defined Under Namespace

Modules: AttributeAccessors

Constant Summary collapse

NOT_SPECIFIED =
Object.new

Class Method Summary collapse

Instance Method Summary collapse

Methods included from AttributeAccessors

define_accessor

Constructor Details

#initialize(notify = nil) ⇒ Config

Returns a new instance of Config.



7
8
9
10
11
12
# File 'lib/deep_cover/config.rb', line 7

def initialize(notify = nil)
  @notify = nil
  @options = {}
  set(**DEFAULTS)
  @notify = notify
end

Class Method Details

.options_to_ignored(**options) ⇒ Object



112
113
114
115
# File 'lib/deep_cover/config.rb', line 112

def self.options_to_ignored(**options)
  OPTIONALLY_COVERED
    .select { |filter| options[FILTER_NAME[filter]] }
end

Instance Method Details

#[](opt) ⇒ Object



97
98
99
# File 'lib/deep_cover/config.rb', line 97

def [](opt)
  public_send(opt)
end

#[]=(opt, value) ⇒ Object



101
102
103
# File 'lib/deep_cover/config.rb', line 101

def []=(opt, value)
  public_send(opt, value)
end

#cache_directory(cache_directory = NOT_SPECIFIED) ⇒ Object



85
86
87
88
# 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) ⇒ Object

Raises:

  • (ArgumentError)


50
51
52
53
54
55
56
57
# 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) ⇒ Object



75
76
77
78
# 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) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
# 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) ⇒ Object



28
29
30
31
32
33
34
# 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) ⇒ Object



80
81
82
83
# File 'lib/deep_cover/config.rb', line 80

def paths(paths = NOT_SPECIFIED)
  paths = Array(paths).dup unless paths == NOT_SPECIFIED
  super
end

#resetObject



90
91
92
93
94
95
# File 'lib/deep_cover/config.rb', line 90

def reset
  DEFAULTS.each do |key, value|
    change(key, value)
  end
  self
end

#set(**options) ⇒ Object



105
106
107
108
109
110
# File 'lib/deep_cover/config.rb', line 105

def set(**options)
  options.each do |key, value|
    self[key] = value
  end
  self
end

#to_hashObject Also known as: to_h



14
15
16
# File 'lib/deep_cover/config.rb', line 14

def to_hash
  @options.dup
end

#to_hash_for_serializeObject



19
20
21
22
23
24
25
26
# 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