Class: MixedGauge::Config

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

Overview

Holding global configuration

Constant Summary collapse

DEFAULT_HASH_FUNCTION =
->(key) { Zlib.crc32(key) }

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfig

Returns a new instance of Config.



10
11
12
13
# File 'lib/mixed_gauge/config.rb', line 10

def initialize
  @cluster_configs = {}
  @hash_proc = DEFAULT_HASH_FUNCTION
end

Instance Attribute Details

#cluster_configsObject (readonly)

Returns the value of attribute cluster_configs.



8
9
10
# File 'lib/mixed_gauge/config.rb', line 8

def cluster_configs
  @cluster_configs
end

#hash_procObject (readonly)

Returns the value of attribute hash_proc.



8
9
10
# File 'lib/mixed_gauge/config.rb', line 8

def hash_proc
  @hash_proc
end

Instance Method Details

#define_cluster(cluster_name) {|MixedGauge::ClusterConfig| ... } ⇒ Object

Define config for specific cluster. See README.md for example.

Parameters:

  • cluster_name (Symbol)

Yields:

Raises:

  • (RuntimeError)

    When this cluster config is invalid.



20
21
22
23
24
25
# File 'lib/mixed_gauge/config.rb', line 20

def define_cluster(cluster_name, &block)
  cluster_config = ClusterConfig.new(cluster_name)
  cluster_config.instance_eval(&block)
  cluster_config.validate_config!
  @cluster_configs[cluster_name] = cluster_config
end

#fetch_cluster_config(cluster_name) ⇒ MixedGauge::ClusterConfig

Parameters:

  • cluster_name (Symbol)

Returns:



29
30
31
# File 'lib/mixed_gauge/config.rb', line 29

def fetch_cluster_config(cluster_name)
  @cluster_configs.fetch(cluster_name)
end

#register_hash_function(&block) ⇒ Object

Register arbitrary hash function. Hash function must be a proc and must return integer. See README.md for example.

Raises:

  • (ArgumentError)


36
37
38
39
40
# File 'lib/mixed_gauge/config.rb', line 36

def register_hash_function(&block)
  raise ArgumentError if block.arity != 1
  raise ArgumentError unless yield('test value').is_a? Integer
  @hash_proc = block
end