Class: PgHaMigrations::TableCollection
- Inherits:
-
Object
- Object
- PgHaMigrations::TableCollection
- Includes:
- Enumerable
- Defined in:
- lib/pg_ha_migrations/relation.rb
Instance Attribute Summary collapse
-
#raw_set ⇒ Object
readonly
Returns the value of attribute raw_set.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(tables, &blk) ⇒ TableCollection
constructor
A new instance of TableCollection.
- #subset?(other) ⇒ Boolean
- #to_sql ⇒ Object
- #with_partitions ⇒ Object
Constructor Details
#initialize(tables, &blk) ⇒ TableCollection
Returns a new instance of TableCollection.
220 221 222 223 224 225 226 227 228 229 230 |
# File 'lib/pg_ha_migrations/relation.rb', line 220 def initialize(tables, &blk) @raw_set = tables.map(&blk).to_set if raw_set.empty? raise ArgumentError, "Expected a non-empty list of tables" end if raw_set.uniq(&:mode).size > 1 raise ArgumentError, "Expected all tables in collection to have the same lock mode" end end |
Instance Attribute Details
#raw_set ⇒ Object (readonly)
Returns the value of attribute raw_set.
211 212 213 |
# File 'lib/pg_ha_migrations/relation.rb', line 211 def raw_set @raw_set end |
Class Method Details
.from_table_names(tables, mode = nil) ⇒ Object
216 217 218 |
# File 'lib/pg_ha_migrations/relation.rb', line 216 def self.from_table_names(tables, mode=nil) new(tables) { |table| Table.from_table_name(table, mode) } end |
Instance Method Details
#subset?(other) ⇒ Boolean
232 233 234 |
# File 'lib/pg_ha_migrations/relation.rb', line 232 def subset?(other) raw_set.subset?(other.raw_set) end |
#to_sql ⇒ Object
236 237 238 |
# File 'lib/pg_ha_migrations/relation.rb', line 236 def to_sql map(&:fully_qualified_name).join(", ") end |
#with_partitions ⇒ Object
240 241 242 243 244 245 246 |
# File 'lib/pg_ha_migrations/relation.rb', line 240 def with_partitions tables = flat_map do |table| table.partitions(include_sub_partitions: true, include_self: true) end self.class.new(tables) end |