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
- #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
20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# 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 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[0]).each do |i| hash[i] = value[1] end hash end end end |
#physical_shard_configs ⇒ Object
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
39 40 41 |
# File 'lib/sequel/schema-sharding/configuration.rb', line 39 def schema_name(table_name) config['tables'][table_name.to_s]['schema_name'] end |
#table_names ⇒ Object
35 36 37 |
# File 'lib/sequel/schema-sharding/configuration.rb', line 35 def table_names config['tables'].keys end |