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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



13
14
15
16
17
18
19
20
21
# File 'lib/specbandit/configuration.rb', line 13

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))
end

Instance Attribute Details

#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

#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

#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

Instance Method Details

#validate!Object

Raises:



23
24
25
26
27
28
# File 'lib/specbandit/configuration.rb', line 23

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?
end