Class: Specbandit::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/specbandit/configuration.rb

Constant Summary collapse

DEFAULT_REDIS_URL =
'redis://localhost:6379'
DEFAULT_BATCH_SIZE =
5
DEFAULT_KEY_TTL =

6 hours in seconds

21_600
DEFAULT_KEY_RERUN_TTL =

1 week in seconds

604_800
DEFAULT_ADAPTER =
'cli'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/specbandit/configuration.rb', line 15

def initialize
  @redis_url = ENV.fetch('SPECBANDIT_REDIS_URL', DEFAULT_REDIS_URL)
  @batch_size = Integer(ENV.fetch('SPECBANDIT_BATCH_SIZE', DEFAULT_BATCH_SIZE))
  @key = ENV.fetch('SPECBANDIT_KEY', nil)
  @rspec_opts = parse_rspec_opts(ENV.fetch('SPECBANDIT_RSPEC_OPTS', nil))
  @key_ttl = Integer(ENV.fetch('SPECBANDIT_KEY_TTL', DEFAULT_KEY_TTL))
  @key_rerun = ENV.fetch('SPECBANDIT_KEY_RERUN', nil)
  @key_rerun_ttl = Integer(ENV.fetch('SPECBANDIT_KEY_RERUN_TTL', DEFAULT_KEY_RERUN_TTL))
  @rerun = env_truthy?('SPECBANDIT_RERUN')
  @verbose = env_truthy?('SPECBANDIT_VERBOSE')
  @adapter = ENV.fetch('SPECBANDIT_ADAPTER', DEFAULT_ADAPTER)
  @command = ENV.fetch('SPECBANDIT_COMMAND', nil)
  @command_opts = parse_space_separated(ENV.fetch('SPECBANDIT_COMMAND_OPTS', nil))
end

Instance Attribute Details

#adapterObject

Returns the value of attribute adapter.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def adapter
  @adapter
end

#batch_sizeObject

Returns the value of attribute batch_size.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def batch_size
  @batch_size
end

#commandObject

Returns the value of attribute command.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def command
  @command
end

#command_optsObject

Returns the value of attribute command_opts.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def command_opts
  @command_opts
end

#keyObject

Returns the value of attribute key.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def key
  @key
end

#key_rerunObject

Returns the value of attribute key_rerun.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def key_rerun
  @key_rerun
end

#key_rerun_ttlObject

Returns the value of attribute key_rerun_ttl.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def key_rerun_ttl
  @key_rerun_ttl
end

#key_ttlObject

Returns the value of attribute key_ttl.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def key_ttl
  @key_ttl
end

#redis_urlObject

Returns the value of attribute redis_url.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def redis_url
  @redis_url
end

#rerunObject

Returns the value of attribute rerun.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def rerun
  @rerun
end

#rspec_optsObject

Returns the value of attribute rspec_opts.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def rspec_opts
  @rspec_opts
end

#verboseObject

Returns the value of attribute verbose.



5
6
7
# File 'lib/specbandit/configuration.rb', line 5

def verbose
  @verbose
end

Instance Method Details

#validate!Object

Raises:



30
31
32
33
34
35
36
# File 'lib/specbandit/configuration.rb', line 30

def validate!
  raise Error, 'key is required (set via --key or SPECBANDIT_KEY)' if key.nil? || key.empty?
  raise Error, 'batch_size must be a positive integer' unless batch_size.positive?
  raise Error, 'key_ttl must be a positive integer' unless key_ttl.positive?
  raise Error, 'key_rerun_ttl must be a positive integer' unless key_rerun_ttl.positive?
  raise Error, '--rerun requires --key-rerun to be set' if rerun && (key_rerun.nil? || key_rerun.empty?)
end