Class: DynamicMigrations::Postgres::Server::Database::Schema::Enum
- Inherits:
-
DynamicMigrations::Postgres::Server::Database::Source
- Object
- DynamicMigrations::Postgres::Server::Database::Source
- DynamicMigrations::Postgres::Server::Database::Schema::Enum
- Defined in:
- lib/dynamic_migrations/postgres/server/database/schema/enum.rb
Overview
This class represents a postgres enum.
Defined Under Namespace
Classes: ExpectedSchemaError, ExpectedValuesError, ValueAlreadyExistsError, ValueMustBeStringError
Instance Attribute Summary collapse
-
#columns ⇒ Object
readonly
Returns the value of attribute columns.
-
#description ⇒ Object
readonly
Returns the value of attribute description.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#schema ⇒ Object
readonly
Returns the value of attribute schema.
-
#values ⇒ Object
readonly
Returns the value of attribute values.
Attributes inherited from DynamicMigrations::Postgres::Server::Database::Source
Instance Method Summary collapse
-
#add_column(column) ⇒ Object
for tracking all the columns which are associated with this enum.
- #add_value(value) ⇒ Object
- #differences_descriptions(other_enum) ⇒ Object
- #full_name ⇒ Object
-
#has_description? ⇒ Boolean
returns true if this enum has a description, otehrwise false.
-
#initialize(source, schema, name, values, description: nil) ⇒ Enum
constructor
initialize a new object to represent a postgres enum.
Methods inherited from DynamicMigrations::Postgres::Server::Database::Source
#assert_is_a_symbol!, #from_configuration?, #from_database?
Constructor Details
#initialize(source, schema, name, values, description: nil) ⇒ Enum
initialize a new object to represent a postgres enum
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/enum.rb', line 29 def initialize source, schema, name, values, description: nil super source @columns = [] raise ExpectedSchemaError, schema unless schema.is_a? Schema @schema = schema raise ExpectedSymbolError, name unless name.is_a? Symbol @name = name unless values.is_a?(Array) && values.count > 0 raise ExpectedValuesError, "Values are required for enums" end @values = [] values.each do |value| add_value value end unless description.nil? raise ExpectedStringError, description unless description.is_a? String @description = description.strip @description = nil if description == "" end end |
Instance Attribute Details
#columns ⇒ Object (readonly)
Returns the value of attribute columns.
26 27 28 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/enum.rb', line 26 def columns @columns end |
#description ⇒ Object (readonly)
Returns the value of attribute description.
25 26 27 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/enum.rb', line 25 def description @description end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
23 24 25 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/enum.rb', line 23 def name @name end |
#schema ⇒ Object (readonly)
Returns the value of attribute schema.
22 23 24 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/enum.rb', line 22 def schema @schema end |
#values ⇒ Object (readonly)
Returns the value of attribute values.
24 25 26 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/enum.rb', line 24 def values @values end |
Instance Method Details
#add_column(column) ⇒ Object
for tracking all the columns which are associated with this enum
73 74 75 76 77 78 79 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/enum.rb', line 73 def add_column column # this should never happen, but adding it just in case unless column.source == source raise "Internal error - column source `#{column.source}` does not match enum source `#{source}`" end @columns << column end |
#add_value(value) ⇒ Object
55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/enum.rb', line 55 def add_value value unless value.is_a? String raise ValueMustBeStringError, "Value `#{value}` must be a string" end if @values.include? value raise ValueAlreadyExistsError, "Value `#{value}` already exists in enum `#{name}`" end @values << value end |
#differences_descriptions(other_enum) ⇒ Object
81 82 83 84 85 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/enum.rb', line 81 def differences_descriptions other_enum method_differences_descriptions other_enum, [ :values ] end |
#full_name ⇒ Object
87 88 89 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/enum.rb', line 87 def full_name :"#{schema.name}.#{name}" end |
#has_description? ⇒ Boolean
returns true if this enum has a description, otehrwise false
68 69 70 |
# File 'lib/dynamic_migrations/postgres/server/database/schema/enum.rb', line 68 def has_description? !@description.nil? end |