Class: DbCharmer::Sharding::Method::HashMap
- Defined in:
- lib/db_charmer/sharding/method/hash_map.rb
Instance Attribute Summary collapse
-
#map ⇒ Object
Returns the value of attribute map.
Instance Method Summary collapse
-
#initialize(config) ⇒ HashMap
constructor
A new instance of HashMap.
- #shard_for_key(key) ⇒ Object
- #support_default_shard? ⇒ Boolean
Constructor Details
#initialize(config) ⇒ HashMap
Returns a new instance of HashMap.
7 8 9 |
# File 'lib/db_charmer/sharding/method/hash_map.rb', line 7 def initialize(config) @map = config[:map].clone or raise ArgumentError, "No :map defined!" end |
Instance Attribute Details
#map ⇒ Object
Returns the value of attribute map.
5 6 7 |
# File 'lib/db_charmer/sharding/method/hash_map.rb', line 5 def map @map end |
Instance Method Details
#shard_for_key(key) ⇒ Object
11 12 13 14 15 |
# File 'lib/db_charmer/sharding/method/hash_map.rb', line 11 def shard_for_key(key) res = map[key] || map[:default] raise ArgumentError, "Invalid key value, no shards found for this key!" unless res return res end |
#support_default_shard? ⇒ Boolean
17 18 19 |
# File 'lib/db_charmer/sharding/method/hash_map.rb', line 17 def support_default_shard? map.has_key?(:default) end |