Class: Rant::Plugin::ConfigureCheck

Inherits:
Object
  • Object
show all
Includes:
Console
Defined in:
lib/rant/plugin/configure.rb

Overview

class Configure

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(key, val = nil) {|_self| ... } ⇒ ConfigureCheck

Returns a new instance of ConfigureCheck.

Yields:

  • (_self)

Yield Parameters:


314
315
316
317
318
319
320
321
# File 'lib/rant/plugin/configure.rb', line 314

def initialize(key, val = nil)
    @key = key or raise ArgumentError, "no key given"
    @value = @default = val
    @guess_block = nil
    @interact_block = nil
    @react_block = nil
    yield self if block_given?
end

Instance Attribute Details

#default(val) ⇒ Object


322
323
324
325
# File 'lib/rant/plugin/configure.rb', line 322

def default(val)
    @default = val
    @value = @default if @value.nil?
end

#guess_blockObject

Returns the value of attribute guess_block


311
312
313
# File 'lib/rant/plugin/configure.rb', line 311

def guess_block
  @guess_block
end

#interact_blockObject

Returns the value of attribute interact_block


312
313
314
# File 'lib/rant/plugin/configure.rb', line 312

def interact_block
  @interact_block
end

#keyObject (readonly)

Returns the value of attribute key


308
309
310
# File 'lib/rant/plugin/configure.rb', line 308

def key
  @key
end

#react_blockObject

Returns the value of attribute react_block


313
314
315
# File 'lib/rant/plugin/configure.rb', line 313

def react_block
  @react_block
end

#valueObject

Returns the value of attribute value


309
310
311
# File 'lib/rant/plugin/configure.rb', line 309

def value
  @value
end

Instance Method Details

#guess(&block) ⇒ Object


326
327
328
# File 'lib/rant/plugin/configure.rb', line 326

def guess(&block)
    @guess_block = block
end

#interact(&block) ⇒ Object


329
330
331
# File 'lib/rant/plugin/configure.rb', line 329

def interact(&block)
    @interact_block = block
end

#react(&block) ⇒ Object


332
333
334
# File 'lib/rant/plugin/configure.rb', line 332

def react(&block)
    @react_block = block
end

#run_check(modes = [:guess], env = ENV) ⇒ Object

Run checks as specified by modes. modes has to be a list of symbols from the Configure::CHECK_MODES.


338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
# File 'lib/rant/plugin/configure.rb', line 338

def run_check(modes = [:guess], env = ENV)
    val = nil
    modes.each { |mode|
	case mode
	when :default
	    val = @default
	when :env
	    val = env[@key]
	when :interact
	    val = @interact_block[self] if @interact_block
	when :guess
	    val = @guess_block[self] if @guess_block
	else
	    raise "unknown configure mode"
	end
	break unless val.nil?
    }
    val.nil? or @value = val
    @react_block && @react_block[@value]
    @value
end