class Sequel::SchemaSharding::Configuration

Attributes

env[R]
yaml_path[R]

Public Class Methods

new(env, yaml_path) click to toggle source
# File lib/sequel/schema-sharding/configuration.rb, line 8
def initialize(env, yaml_path)
  @env = env
  @yaml_path = yaml_path
end

Public Instance Methods

logical_shard_configs(table_name) click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# 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) click to toggle source
# 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() click to toggle source
# File lib/sequel/schema-sharding/configuration.rb, line 40
def table_names
  config['tables'].keys
end

Private Instance Methods

config() click to toggle source
# File lib/sequel/schema-sharding/configuration.rb, line 65
def config
  yaml[env.to_s]
end
parse_logical_shard_config_for(table_name) click to toggle source
# File lib/sequel/schema-sharding/configuration.rb, line 54
def parse_logical_shard_config_for(table_name)
  table_configs = config['tables'][table_name]
  raise "Unknown table #{table_name} in configuration" if table_configs.nil?
  table_configs['logical_shards'].inject({}) do |hash, value|
    eval(value[1]).each do |i|
      hash[i] = value[0]
    end
    hash
  end
end
yaml() click to toggle source
# File lib/sequel/schema-sharding/configuration.rb, line 69
def yaml
  @raw_yaml ||= YAML.load_file(yaml_path)
end