Class: RR::TableSpecResolver
- Inherits:
-
Object
- Object
- RR::TableSpecResolver
- Defined in:
- lib/rubyrep/table_spec_resolver.rb
Overview
Resolves table specifications as provided e. g. in the command line of rrscan
Instance Attribute Summary collapse
-
#session ⇒ Object
The
Session
instance from which the table specifications are resolved.
Instance Method Summary collapse
-
#initialize(session) ⇒ TableSpecResolver
constructor
Creates a resolver that works based on the given
Session
instance. -
#non_existing_tables(table_pairs) ⇒ Object
Returns all those tables from the given table_pairs that do not exist.
-
#resolve(included_table_specs, excluded_table_specs = [], verify = true) ⇒ Object
Resolves the given array of table specificifications.
-
#tables(database) ⇒ Object
Returns the array of tables of the specified database.
Constructor Details
#initialize(session) ⇒ TableSpecResolver
Creates a resolver that works based on the given Session
instance.
20 21 22 |
# File 'lib/rubyrep/table_spec_resolver.rb', line 20 def initialize(session) self.session = session end |
Instance Attribute Details
#session ⇒ Object
The Session
instance from which the table specifications are resolved.
7 8 9 |
# File 'lib/rubyrep/table_spec_resolver.rb', line 7 def session @session end |
Instance Method Details
#non_existing_tables(table_pairs) ⇒ Object
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.
31 32 33 34 35 36 37 38 39 40 |
# 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) ⇒ Object
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.
57 58 59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/rubyrep/table_spec_resolver.rb', line 57 def resolve(included_table_specs, excluded_table_specs = [], verify = true) table_pairs = (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) ⇒ Object
Returns the array of tables of the specified database. Caches the table array.
-
database: either :
left
or :right
11 12 13 14 15 16 17 |
# 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 |