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, InvalidNameError, 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
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb', line 31 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 InvalidNameError, "Unexpected name `#{name}`. Name should be a Symbol" unless name.is_a? Symbol raise InvalidNameError, "The name `#{name}` is too long. Names must be less than 64 characters" unless name.length < 64 @name = name unless description.nil? raise ExpectedStringError, description unless description.is_a? String @description = description.strip.freeze @description = nil if description == "" end end |
Instance Attribute Details
#description ⇒ Object (readonly)
Returns the value of attribute description.
28 29 30 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb', line 28 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
27 28 29 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.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/primary_key.rb', line 26 def table @table end |
Instance Method Details
#column_names ⇒ Object
67 68 69 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb', line 67 def column_names @columns.keys end |
#columns ⇒ Object
return an array of this primary keys columns
63 64 65 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb', line 63 def columns @columns.values end |
#differences_descriptions(other_primary_key) ⇒ Object
71 72 73 74 75 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb', line 71 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
58 59 60 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/table/primary_key.rb', line 58 def has_description? !@description.nil? end |