Class: DynamicMigrations::Postgres::Server::Database::Schema::Table::PrimaryKey
- Inherits:
-
DynamicMigrations::Postgres::Server::Database::Source
- Object
- DynamicMigrations::Postgres::Server::Database::Source
- DynamicMigrations::Postgres::Server::Database::Schema::Table::PrimaryKey
- Defined in:
- lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb
Overview
This class represents a postgres table primary_key
Defined Under Namespace
Classes: DuplicateColumnError, ExpectedArrayOfColumnsError, ExpectedTableError, UnexpectedIndexTypeError
Instance Attribute Summary collapse
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#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 primary keys columns.
- #differences_descriptions(other_primary_key) ⇒ Object
-
#has_description? ⇒ Boolean
return true if this has a description, otherwise false.
-
#initialize(source, table, columns, name, description: nil) ⇒ PrimaryKey
constructor
initialize a new object to represent a primary_key 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) ⇒ PrimaryKey
initialize a new object to represent a primary_key in a postgres table
28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb', line 28 def initialize source, table, columns, name, description: nil 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 end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
25 26 27 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb', line 25 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
24 25 26 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb', line 24 def name @name end |
#table ⇒ Object (readonly)
Returns the value of attribute table.
23 24 25 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb', line 23 def table @table end |
Instance Method Details
#column_names ⇒ Object
63 64 65 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb', line 63 def column_names @columns.keys end |
#columns ⇒ Object
return an array of this primary keys columns
59 60 61 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb', line 59 def columns @columns.values end |
#differences_descriptions(other_primary_key) ⇒ Object
67 68 69 70 71 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb', line 67 def differences_descriptions other_primary_key method_differences_descriptions other_primary_key, [ :column_names ] end |
#has_description? ⇒ Boolean
return true if this has a description, otherwise false
54 55 56 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb', line 54 def has_description? !@description.nil? end |