Class: DynamicMigrations::Postgres::Server::Database::Schema::Table::UniqueConstraint
- Inherits:
-
DynamicMigrations::Postgres::Server::Database::Source
- Object
- DynamicMigrations::Postgres::Server::Database::Source
- DynamicMigrations::Postgres::Server::Database::Schema::Table::UniqueConstraint
- Defined in:
- lib/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rb
Overview
This class represents a postgres table unique_constraint
Defined Under Namespace
Classes: DuplicateColumnError, ExpectedArrayOfColumnsError, ExpectedTableError, UnexpectedNullsPositionError, UnexpectedOrderError
Instance Attribute Summary collapse
-
#deferrable ⇒ Object
readonly
Returns the value of attribute deferrable.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#initially_deferred ⇒ Object
readonly
Returns the value of attribute initially_deferred.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#table ⇒ Object
readonly
Returns the value of attribute table.
Attributes inherited from DynamicMigrations::Postgres::Server::Database::Source
Instance Method Summary collapse
- #column_names ⇒ Object
-
#columns ⇒ Object
return an array of this unique_constraints columns.
- #differences_descriptions(other_unique_constraint) ⇒ Object
-
#has_description? ⇒ Boolean
return true if this has a description, otherwise false.
-
#initialize(source, table, columns, name, description: nil, deferrable: false, initially_deferred: false) ⇒ UniqueConstraint
constructor
initialize a new object to represent a unique_constraint in a postgres table.
Methods inherited from DynamicMigrations::Postgres::Server::Database::Source
#assert_is_a_symbol!, #from_configuration?, #from_database?
Constructor Details
#initialize(source, table, columns, name, description: nil, deferrable: false, initially_deferred: false) ⇒ UniqueConstraint
initialize a new object to represent a unique_constraint in a postgres table
33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rb', line 33 def initialize source, table, columns, name, description: nil, deferrable: false, initially_deferred: false super source raise ExpectedTableError, table unless table.is_a? Table @table = table @columns = {} # assert that the provided columns is an array unless columns.is_a?(Array) && columns.count > 0 raise ExpectedArrayOfColumnsError end columns.each do |column| add_column column end raise ExpectedSymbolError, name unless name.is_a? Symbol @name = name unless description.nil? raise ExpectedStringError, description unless description.is_a? String @description = description.strip @description = nil if description == "" end raise ExpectedBooleanError, deferrable unless [true, false].include?(deferrable) @deferrable = deferrable raise ExpectedBooleanError, initially_deferred unless [true, false].include?(initially_deferred) @initially_deferred = initially_deferred end |
Instance Attribute Details
#deferrable ⇒ Object (readonly)
Returns the value of attribute deferrable.
28 29 30 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rb', line 28 def deferrable @deferrable end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
30 31 32 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rb', line 30 def description @description end |
#initially_deferred ⇒ Object (readonly)
Returns the value of attribute initially_deferred.
29 30 31 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rb', line 29 def initially_deferred @initially_deferred end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
27 28 29 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rb', line 27 def name @name end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
26 27 28 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rb', line 26 def table @table end |
Instance Method Details
#column_names ⇒ Object
74 75 76 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rb', line 74 def column_names @columns.keys end |
#columns ⇒ Object
return an array of this unique_constraints columns
70 71 72 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rb', line 70 def columns @columns.values end |
#differences_descriptions(other_unique_constraint) ⇒ Object
78 79 80 81 82 83 84 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rb', line 78 def differences_descriptions other_unique_constraint method_differences_descriptions other_unique_constraint, [ :column_names, :deferrable, :initially_deferred ] end |
#has_description? ⇒ Boolean
return true if this has a description, otherwise false
65 66 67 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/unique_constraint.rb', line 65 def has_description? !@description.nil? end |