Class: DeepCover::Config

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

Instance Method Summary collapse

Constructor Details

#initialize(notify = nil) ⇒ Config

Returns a new instance of Config.



5
6
7
8
9
10
# File 'lib/deep_cover/config.rb', line 5

def initialize(notify = nil)
  @notify = nil
  @options = {ignore_uncovered: []}
  set(**DEFAULTS)
  @notify = notify
end

Instance Method Details

#allow_partial(allow_partial = nil) ⇒ Object



98
99
100
101
102
103
104
# File 'lib/deep_cover/config.rb', line 98

def allow_partial(allow_partial = nil)
  if allow_partial != nil
    change(:allow_partial, allow_partial)
  else
    @options[:allow_partial]
  end
end

#cache_directory(cache_directory = nil) ⇒ Object



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

def cache_directory(cache_directory = nil)
  if cache_directory
    change(:cache_directory, cache_directory)
  else
    File.expand_path(@options[:cache_directory])
  end
end

#detect_uncovered(*keywords) ⇒ Object

Raises:

  • (ArgumentError)


48
49
50
51
52
53
54
55
56
# File 'lib/deep_cover/config.rb', line 48

def detect_uncovered(*keywords)
  raise ArgumentError, 'No block is accepted' if block_given?
  if keywords.empty?
    OPTIONALLY_COVERED - @options[:ignore_uncovered]
  else
    keywords = check_uncovered(keywords)
    change(:ignore_uncovered, @options[:ignore_uncovered] - keywords)
  end
end

#ignore_uncovered(*keywords, &block) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/deep_cover/config.rb', line 34

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)
  end
  if keywords.empty?
    @options[:ignore_uncovered]
  else
    keywords = check_uncovered(keywords)
    change(:ignore_uncovered, @options[:ignore_uncovered] | keywords)
  end
end

#load_hash_for_serialize(hash) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/deep_cover/config.rb', line 26

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

#output(path_or_false = nil) ⇒ Object



82
83
84
85
86
87
88
# File 'lib/deep_cover/config.rb', line 82

def output(path_or_false = nil)
  if path_or_false != nil
    change(:output, path_or_false)
  else
    @options[:output]
  end
end

#paths(paths = nil) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/deep_cover/config.rb', line 58

def paths(paths = nil)
  if paths
    change(:paths, Array(paths).dup)
  else
    @options[:paths]
  end
end

#reporter(reporter = nil) ⇒ Object



74
75
76
77
78
79
80
# File 'lib/deep_cover/config.rb', line 74

def reporter(reporter = nil)
  if reporter
    change(:reporter, reporter)
  else
    @options[:reporter]
  end
end

#resetObject



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

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

#set(**options) ⇒ Object



113
114
115
116
117
118
119
# File 'lib/deep_cover/config.rb', line 113

def set(**options)
  @options[:ignore_uncovered] = [] if options.has_key?(:ignore_uncovered)
  options.each do |key, value|
    public_send key, value
  end
  self
end

#to_hashObject Also known as: to_h



12
13
14
# File 'lib/deep_cover/config.rb', line 12

def to_hash
  @options.dup
end

#to_hash_for_serializeObject



17
18
19
20
21
22
23
24
# File 'lib/deep_cover/config.rb', line 17

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] = hash[:output] ? File.expand_path(hash[:output]) : hash[:output]
  hash[:cache_directory] = File.expand_path(hash[:cache_directory])
  hash
end

#tracker_global(tracker_global = nil) ⇒ Object



66
67
68
69
70
71
72
# File 'lib/deep_cover/config.rb', line 66

def tracker_global(tracker_global = nil)
  if tracker_global
    change(:tracker_global, tracker_global)
  else
    @options[:tracker_global]
  end
end