Parent

Class/Module Index [+]

Quicksearch

RR::TableSpecResolver

Resolves table specifications as provided e. g. in the command line of rrscan

Attributes

session[RW]

The Session instance from which the table specifications are resolved.

Public Class Methods

new(session) click to toggle source

Creates a resolver that works based on the given Session instance.

# File lib/rubyrep/table_spec_resolver.rb, line 20
def initialize(session)
  self.session = session
end

Public Instance Methods

non_existing_tables(table_pairs) click to toggle source

Returns all those tables from the given table_pairs that do not exist.

  • table_pairs: same as described at table_pairs_without_excluded

Returns: A hash with keys :left and :right, with the value for each key being an array of non-existing tables for the according database. The keys only exist if there are according missing tables.

# File lib/rubyrep/table_spec_resolver.rb, line 31
def non_existing_tables(table_pairs)
  [:left, :right].inject({}) do |memo, database|
    found_tables = table_pairs.inject([]) do |phantom_tables, table_pair|
      phantom_tables << table_pair[database] unless tables(database).include?(table_pair[database])
      phantom_tables
    end
    memo[database] = found_tables unless found_tables.empty?
    memo
  end
end
resolve(included_table_specs, excluded_table_specs = [], verify = true) click to toggle source

Resolves the given array of table specificifications. Table specifications are either

  • strings as produced by BaseRunner#get_options or

  • actual regular expressions

If excluded_table_specs is provided, removes all tables that match it (even if otherwise matching included_table_specs).

If verify is true, raises an exception if any non-existing tables are specified.

Returns an array of table name pairs in Hash form. For example something like

[{:left => 'my_table', :right => 'my_table_backup'}]

Takes care that a table is only returned once.

# File lib/rubyrep/table_spec_resolver.rb, line 57
def resolve(included_table_specs, excluded_table_specs = [], verify = true)
  table_pairs = expand_table_specs(included_table_specs, verify)
  table_pairs = table_pairs_without_duplicates(table_pairs)
  table_pairs = table_pairs_without_excluded(table_pairs, excluded_table_specs)

  if verify
    non_existing_tables = non_existing_tables(table_pairs)
    unless non_existing_tables.empty?
      raise "non-existing tables specified: #{non_existing_tables.inspect}"
    end
  end

  table_pairs
end
tables(database) click to toggle source

Returns the array of tables of the specified database. Caches the table array.

  • database: either :left or :right

# File lib/rubyrep/table_spec_resolver.rb, line 11
def tables(database)
  @table_cache ||= {}
  unless @table_cache[database]
    @table_cache[database] = session.send(database).tables
  end
  @table_cache[database]
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.