Class: Sequel::SchemaSharding::Configuration
- Inherits:
-
Object
- Object
- Sequel::SchemaSharding::Configuration
- Defined in:
- lib/sequel/schema-sharding/configuration.rb
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#yaml_path ⇒ Object
readonly
Returns the value of attribute yaml_path.
Instance Method Summary collapse
-
#initialize(env, yaml_path) ⇒ Configuration
constructor
A new instance of Configuration.
- #logical_shard_configs(table_name) ⇒ Object
- #number_of_shards(table_name) ⇒ Object
- #physical_shard_configs ⇒ Object
- #schema_name(table_name) ⇒ Object
- #table_names ⇒ Object
Constructor Details
#initialize(env, yaml_path) ⇒ Configuration
Returns a new instance of Configuration.
8 9 10 11 |
# File 'lib/sequel/schema-sharding/configuration.rb', line 8 def initialize(env, yaml_path) @env = env @yaml_path = yaml_path end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
6 7 8 |
# File 'lib/sequel/schema-sharding/configuration.rb', line 6 def env @env end |
#yaml_path ⇒ Object (readonly)
Returns the value of attribute yaml_path.
6 7 8 |
# File 'lib/sequel/schema-sharding/configuration.rb', line 6 def yaml_path @yaml_path end |
Instance Method Details
#logical_shard_configs(table_name) ⇒ Object
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/sequel/schema-sharding/configuration.rb', line 28 def logical_shard_configs(table_name) table_name = table_name.to_s @logical_shard_table_configs ||= {} @logical_shard_table_configs[table_name] ||= begin config, number_of_shards = parse_logical_shard_config_for(table_name), number_of_shards(table_name) raise "Shard number mismatch: expected #{number_of_shards} got #{config.size} for table #{table_name}" if config.size != number_of_shards config end end |
#number_of_shards(table_name) ⇒ Object
48 49 50 |
# File 'lib/sequel/schema-sharding/configuration.rb', line 48 def number_of_shards(table_name) config['tables'][table_name.to_s]['number_of_shards'] end |
#physical_shard_configs ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/sequel/schema-sharding/configuration.rb', line 13 def physical_shard_configs @physical_shard_configs ||= config['physical_shards'].inject({}) do |hash, value| shard_config = config['common'].merge(value[1]) if shard_config['replicas'] shard_config['replicas'] = shard_config['replicas'].map do |name, replica| config['common'].merge(replica) end end hash[value[0]] = shard_config hash end end |
#schema_name(table_name) ⇒ Object
44 45 46 |
# File 'lib/sequel/schema-sharding/configuration.rb', line 44 def schema_name(table_name) config['tables'][table_name.to_s]['schema_name'] end |
#table_names ⇒ Object
40 41 42 |
# File 'lib/sequel/schema-sharding/configuration.rb', line 40 def table_names config['tables'].keys end |