Class: PgHaMigrations::Relation
- Inherits:
-
Struct
- Object
- Struct
- PgHaMigrations::Relation
- Defined in:
- lib/pg_ha_migrations/relation.rb
Overview
This object represents a pointer to an actual relation in Postgres. The mode attribute is optional metadata which can represent a lock that has already been acquired or a potential lock that we are looking to acquire.
Instance Attribute Summary collapse
-
#mode ⇒ Object
Returns the value of attribute mode.
-
#name ⇒ Object
Returns the value of attribute name.
-
#schema ⇒ Object
Returns the value of attribute schema.
Class Method Summary collapse
Instance Method Summary collapse
- #==(other) ⇒ Object
- #conflicts_with?(other) ⇒ Boolean
-
#eql?(other) ⇒ Boolean
Some code paths need to compare lock modes, while others just need to determine if the relation is the same object in Postgres, so equality here is simply looking at the relation name / schema.
- #fully_qualified_name ⇒ Object
- #hash ⇒ Object
-
#initialize(name, schema, mode = nil) ⇒ Relation
constructor
A new instance of Relation.
- #present? ⇒ Boolean
Constructor Details
Instance Attribute Details
#mode ⇒ Object
Returns the value of attribute mode
6 7 8 |
# File 'lib/pg_ha_migrations/relation.rb', line 6 def mode @mode end |
#name ⇒ Object
Returns the value of attribute name
6 7 8 |
# File 'lib/pg_ha_migrations/relation.rb', line 6 def name @name end |
#schema ⇒ Object
Returns the value of attribute schema
6 7 8 |
# File 'lib/pg_ha_migrations/relation.rb', line 6 def schema @schema end |
Class Method Details
.connection ⇒ Object
7 8 9 |
# File 'lib/pg_ha_migrations/relation.rb', line 7 def self.connection ActiveRecord::Base.connection end |
Instance Method Details
#==(other) ⇒ Object
45 46 47 |
# File 'lib/pg_ha_migrations/relation.rb', line 45 def ==(other) eql?(other) end |
#conflicts_with?(other) ⇒ Boolean
31 32 33 34 35 |
# File 'lib/pg_ha_migrations/relation.rb', line 31 def conflicts_with?(other) eql?(other) && ( mode.nil? || other.mode.nil? || mode.conflicts_with?(other.mode) ) end |
#eql?(other) ⇒ Boolean
Some code paths need to compare lock modes, while others just need to determine if the relation is the same object in Postgres, so equality here is simply looking at the relation name / schema. To also compare lock modes, #conflicts_with? is used.
41 42 43 |
# File 'lib/pg_ha_migrations/relation.rb', line 41 def eql?(other) other.is_a?(Relation) && hash == other.hash end |
#fully_qualified_name ⇒ Object
20 21 22 23 24 25 |
# File 'lib/pg_ha_migrations/relation.rb', line 20 def fully_qualified_name @fully_qualified_name ||= [ PG::Connection.quote_ident(schema), PG::Connection.quote_ident(name), ].join(".") end |
#hash ⇒ Object
49 50 51 |
# File 'lib/pg_ha_migrations/relation.rb', line 49 def hash [name, schema].hash end |
#present? ⇒ Boolean
27 28 29 |
# File 'lib/pg_ha_migrations/relation.rb', line 27 def present? name.present? && schema.present? end |