Module: DeepCover::ConfigSetter

Included in:
DeepCover
Defined in:
lib/deep_cover/config_setter.rb

Instance Method Summary collapse

Instance Method Details

#config(notify = self) ⇒ Object

Raises:

  • (ArgumentError)


9
10
11
12
13
14
15
# File 'lib/deep_cover/config_setter.rb', line 9

def config(notify = self)
  raise ArgumentError, 'config does not accept a block. Did you mean `configure`?' if block_given?
  @config ||= Config.new(notify)
  config_queue.each { |block| configure(&block) }
  config_queue.clear
  @config
end

#config_queueObject



5
6
7
# File 'lib/deep_cover/config_setter.rb', line 5

def config_queue
  @config_queue ||= []
end

#configure(&block) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/deep_cover/config_setter.rb', line 17

def configure(&block)
  raise 'Must provide a block' unless block
  @config ||= nil # avoid warning
  if @config == nil
    config_queue << block
  else
    case block.arity
    when 0
      @config.instance_eval(&block)
    when 1
      block.call(@config)
    end
  end
  self
end