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.
196 197 198 199 200 201 202 203 204 205 206 |
# File 'lib/pg_ha_migrations/relation.rb', line 196 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.
187 188 189 |
# File 'lib/pg_ha_migrations/relation.rb', line 187 def raw_set @raw_set end |
Class Method Details
.from_table_names(tables, mode = nil) ⇒ Object
192 193 194 |
# File 'lib/pg_ha_migrations/relation.rb', line 192 def self.from_table_names(tables, mode=nil) new(tables) { |table| Table.from_table_name(table, mode) } end |
Instance Method Details
#subset?(other) ⇒ Boolean
208 209 210 |
# File 'lib/pg_ha_migrations/relation.rb', line 208 def subset?(other) raw_set.subset?(other.raw_set) end |
#to_sql ⇒ Object
212 213 214 |
# File 'lib/pg_ha_migrations/relation.rb', line 212 def to_sql map(&:fully_qualified_name).join(", ") end |
#with_partitions ⇒ Object
216 217 218 219 220 221 222 |
# File 'lib/pg_ha_migrations/relation.rb', line 216 def with_partitions tables = flat_map do |table| table.partitions(include_sub_partitions: true, include_self: true) end self.class.new(tables) end |