The Configuration class holds the default configuration options for Rubyrep. Configuration values are changed with the Initializer::run method.
Methods
public class
public instance
Constants
| DEFAULT_OPTIONS | = | { :proxy_block_size => 1000, :row_buffer_size => 1000, :replicator => :two_way, :committer => :buffered_commit, :commit_frequency => 1000, :table_ordering => true, :scan_progress_printer => :progress_bar, :use_ansi => true_if_running_in_a_terminal_and_not_under_windows, :initial_sync => true, :adjust_sequences => true, :sequence_adjustment_buffer => 0, :sequence_increment => 2, :left_sequence_offset => 0, :right_sequence_offset => 1, :replication_interval => 1, :auto_key_limit => 0, :database_connection_timeout => 5, :rep_prefix => 'rr', :key_sep => '|', } | Default options for a new Configuration object. |
Attributes
| left | [RW] | Connection settings for the “left” database. See Configuration#right for details. |
| options | [R] |
General options. Possible settings:
Sync specific settings
Replication specific settings:
Example of an :after_infrastructure_setup handler:
lambda do |session|
[:left, :right].each do |database|
session.send(database).execute "GRANT SELECT, UPDATE, INSERT ON rr_pending_changes TO scott"
end
end
|
| right | [RW] |
Connection settings for the “right” database. Takes a similar
hash as ActiveRecord::Base.establish_connection. Additional settings in
case a proxy is used:
Other additional settings:
|
Public class methods
initialize configuration settings
# File lib/rubyrep/configuration.rb, line 268 def initialize self.left = {} self.right = {} self.options = DEFAULT_OPTIONS.clone end
Returns true unless running on windows...
# File lib/rubyrep/configuration.rb, line 27 def self.true_if_running_in_a_terminal_and_not_under_windows # Not using RUBY_PLATFORM as it should also work under JRuby $stdout.tty? and not ENV['OS'] =~ /windows/i end
Public instance methods
Adds the specified options for the provided table_spec. A table_spec can be either
- a table name or
- a table pair (e. g. “my_left_table, my_right_table“)
- a regexp matching multiple tables.
options is hash with possible generic values as described under options. Additional, exclusively table specific options:
- :primary_key_names: array of primary key names
# File lib/rubyrep/configuration.rb, line 204 def add_table_options(table_spec, options) i = nil tables_with_options.each_with_index { |table_options, k| i = k if table_options[0] == table_spec } if i table_options = tables_with_options[i][1] else table_options = {} tables_with_options << [table_spec, table_options] end table_options.merge! options end
Yields all table specs that have been set up with the given option
- key: the option key
Yields:
- table_spec: the table specification of the matching option (or nil if non-table specific setting)
- option_value: the option value for the specified key
# File lib/rubyrep/configuration.rb, line 224 def each_matching_option(key) yield nil, options[key] if options.include?(key) tables_with_options.each do |table_options| yield table_options[0], table_options[1][key] if table_options[1].include? key end end
Ensures that rubyrep infrastructure tables are excluded
# File lib/rubyrep/configuration.rb, line 164 def exclude_rubyrep_tables exclude_tables Regexp.new("^#{options[:rep_prefix]}_.*") end
Excludes the specified table from the list of tables that should be processed. Refer to add_table_options for detailed description of what constitutes a valid table specification.
# File lib/rubyrep/configuration.rb, line 191 def exclude_tables(table_spec) excluded_table_specs << table_spec unless excluded_table_specs.include?(table_spec) end
Array of table specifications for tables that should not be processed Refer to add_table_options for what constitutes a valid table specification.
# File lib/rubyrep/configuration.rb, line 159 def excluded_table_specs @excluded_table_specs ||= [] end
Adds the specified tables to the list of tables that should be processed. If options are provided, store them for future processing. Refer to add_table_options for detailed description of parameters.
# File lib/rubyrep/configuration.rb, line 181 def include_tables(table_spec, options = nil) included_table_specs << table_spec unless included_table_specs.include?(table_spec) add_table_options(table_spec, options) if options end
Array of table specifications for tables that should be processed Refer to add_table_options for what constitutes a valid table specification.
# File lib/rubyrep/configuration.rb, line 153 def included_table_specs @included_table_specs ||= [] end
Merges the specified options hash into the existing options
# File lib/rubyrep/configuration.rb, line 146 def options=(options) @options ||= {} @options = @options.merge! options end
Returns an option hash for the given table. Accumulates options for all matching table specs (most recently added options overwrite according options added before).
Also includes the general options as returned by options. (Table specific options overwrite the general options).
Possible option values are described under add_tables.
# File lib/rubyrep/configuration.rb, line 239 def options_for_table(table) resulting_options = options.clone tables_with_options.each do |table_options| match = false if table_options[0].kind_of? Regexp match = (table_options[0] =~ table) else match = (table_options[0].sub(/(^.*),.*/,'\1').strip == table) end resulting_options.merge! table_options[1] if match end # Merge the default syncer& replicator options in [ Syncers.configured_syncer(resulting_options), Replicators.configured_replicator(resulting_options) ].each do |processor_class| if processor_class.respond_to? :default_options default_processor_options = processor_class.default_options.clone else default_processor_options = {} end resulting_options = default_processor_options.merge!(resulting_options) end resulting_options end
A list of tables having table specific options that should be considered during processing (scanned, synced, …) tables_with_options is a 2 element array with
- first element: A table_spec (either a table name or a regexp matching multiple tables)
- second element: The options hash (detailed format described in add_tables
Should only be accessed via add_table_options and options_for_table
# File lib/rubyrep/configuration.rb, line 174 def tables_with_options @tables_with_options ||= [] end