Class: Sequel::SchemaSharding::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/sequel/schema-sharding/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#envObject (readonly)

Returns the value of attribute env.



6
7
8
# File 'lib/sequel/schema-sharding/configuration.rb', line 6

def env
  @env
end

#yaml_pathObject (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



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/sequel/schema-sharding/configuration.rb', line 20

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



40
41
42
# File 'lib/sequel/schema-sharding/configuration.rb', line 40

def number_of_shards(table_name)
  config['tables'][table_name.to_s]['number_of_shards']
end

#physical_shard_configsObject



13
14
15
16
17
18
# File 'lib/sequel/schema-sharding/configuration.rb', line 13

def physical_shard_configs
  @physical_shard_configs ||= config['physical_shards'].inject({}) do |hash, value|
    hash[value[0]] = config['common'].merge(value[1])
    hash
  end
end

#schema_name(table_name) ⇒ Object



36
37
38
# File 'lib/sequel/schema-sharding/configuration.rb', line 36

def schema_name(table_name)
  config['tables'][table_name.to_s]['schema_name']
end

#table_namesObject



32
33
34
# File 'lib/sequel/schema-sharding/configuration.rb', line 32

def table_names
  config['tables'].keys
end