Class: ActiveRecord::Turntable::Configuration::DSL::ClusterDSL
- Inherits:
-
ActiveRecord::Turntable::Configuration::DSL
- Object
- ActiveRecord::Turntable::Configuration::DSL
- ActiveRecord::Turntable::Configuration::DSL::ClusterDSL
- Defined in:
- lib/active_record/turntable/configuration/dsl.rb
Defined Under Namespace
Classes: ShardSetting
Constant Summary
Constants inherited from ActiveRecord::Turntable::Configuration::DSL
Instance Attribute Summary collapse
-
#sequencers ⇒ Object
readonly
Returns the value of attribute sequencers.
Attributes inherited from ActiveRecord::Turntable::Configuration::DSL
Instance Method Summary collapse
- #algorithm(type, options = {}) ⇒ Object
- #cluster ⇒ Object
-
#initialize(configuration) ⇒ ClusterDSL
constructor
A new instance of ClusterDSL.
- #sequencer(sequencer_name, type, options = {}) ⇒ Object
- #shard(range, slaves: [], to:) ⇒ Object
Methods inherited from ActiveRecord::Turntable::Configuration::DSL
Constructor Details
#initialize(configuration) ⇒ ClusterDSL
Returns a new instance of ClusterDSL.
35 36 37 38 39 40 |
# File 'lib/active_record/turntable/configuration/dsl.rb', line 35 def initialize(configuration) super @algorithm = Algorithm.class_for("range").new(nil) @shard_settings = [] @sequencer_settings = [] end |
Instance Attribute Details
#sequencers ⇒ Object (readonly)
Returns the value of attribute sequencers.
33 34 35 |
# File 'lib/active_record/turntable/configuration/dsl.rb', line 33 def sequencers @sequencers end |
Instance Method Details
#algorithm(type, options = {}) ⇒ Object
54 55 56 |
# File 'lib/active_record/turntable/configuration/dsl.rb', line 54 def algorithm(type, = {}) @algorithm = Algorithm.class_for(type.to_s).new() end |
#cluster ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/active_record/turntable/configuration/dsl.rb', line 42 def cluster Cluster.build(configuration.sequencer_registry) do |c| c.algorithm = @algorithm @shard_settings.each do |setting| c.shard_registry.add(setting) end @sequencer_settings.each do |name, type, | c.sequencer_registry.add(name, type, , c) end end end |
#sequencer(sequencer_name, type, options = {}) ⇒ Object
58 59 60 |
# File 'lib/active_record/turntable/configuration/dsl.rb', line 58 def sequencer(sequencer_name, type, = {}) @sequencer_settings << [sequencer_name.to_s, type.to_s, ] end |
#shard(range, slaves: [], to:) ⇒ Object
73 74 75 |
# File 'lib/active_record/turntable/configuration/dsl.rb', line 73 def shard(range, slaves: [], to:) @shard_settings << ShardSetting.new(to.to_s, range, slaves.map(&:to_s)) end |