Class: MixedGauge::Config
- Inherits:
-
Object
- Object
- MixedGauge::Config
- 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
-
#cluster_configs ⇒ Object
readonly
Returns the value of attribute cluster_configs.
-
#hash_proc ⇒ Object
readonly
Returns the value of attribute hash_proc.
Instance Method Summary collapse
-
#define_cluster(cluster_name) {|MixedGauge::ClusterConfig| ... } ⇒ Object
Define config for specific cluster.
- #fetch_cluster_config(cluster_name) ⇒ MixedGauge::ClusterConfig
-
#initialize ⇒ Config
constructor
A new instance of Config.
-
#register_hash_function(&block) ⇒ Object
Register arbitrary hash function.
Constructor Details
#initialize ⇒ Config
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_configs ⇒ Object (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_proc ⇒ Object (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.
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
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.
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 |