Module: DynamicMigrations::Postgres::Server::Database::LoadedSchemas
- Included in:
- DynamicMigrations::Postgres::Server::Database
- Defined in:
- lib/dynamic_migrations/postgres/server/database/loaded_schemas.rb
Defined Under Namespace
Classes: LoadedSchemaAlreadyExistsError, LoadedSchemaDoesNotExistError
Instance Method Summary collapse
-
#add_loaded_schema(schema_name) ⇒ Object
adds a new loaded schema for this database.
-
#has_loaded_schema?(schema_name) ⇒ Boolean
returns true if this table has a loaded schema with the provided name, otherwise false.
-
#loaded_schema(schema_name) ⇒ Object
returns the loaded schema object for the provided schema name, and raises an error if the schema does not exist.
-
#loaded_schemas ⇒ Object
returns an array of this tables loaded schemas.
-
#loaded_schemas_hash ⇒ Object
returns a hash of this tables loaded schemas, keyed by schema name.
Instance Method Details
#add_loaded_schema(schema_name) ⇒ Object
adds a new loaded schema for this database
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/dynamic_migrations/postgres/server/database/loaded_schemas.rb', line 15 def add_loaded_schema schema_name raise ExpectedSymbolError, schema_name unless schema_name.is_a? Symbol if has_loaded_schema? schema_name raise LoadedSchemaAlreadyExistsError, "Loaded schema #{schema_name} already exists" end included_target = self if included_target.is_a? Database new_schema = @loaded_schemas[schema_name] = Schema.new :database, included_target, schema_name else raise ModuleIncludedIntoUnexpectedTargetError, included_target end # sort the hash so that the schemas are in alphabetical order by name sorted_schemas = {} @loaded_schemas.keys.sort.each do |schema_name| sorted_schemas[schema_name] = @loaded_schemas[schema_name] end @loaded_schemas = sorted_schemas # return the new schema new_schema end |
#has_loaded_schema?(schema_name) ⇒ Boolean
returns true if this table has a loaded schema with the provided name, otherwise false
49 50 51 52 |
# File 'lib/dynamic_migrations/postgres/server/database/loaded_schemas.rb', line 49 def has_loaded_schema? schema_name raise ExpectedSymbolError, schema_name unless schema_name.is_a? Symbol @loaded_schemas.key? schema_name end |
#loaded_schema(schema_name) ⇒ Object
returns the loaded schema object for the provided schema name, and raises an error if the schema does not exist
38 39 40 41 42 43 44 45 46 |
# File 'lib/dynamic_migrations/postgres/server/database/loaded_schemas.rb', line 38 def loaded_schema schema_name unless schema_name.is_a? Symbol raise ExpectedSymbolError, schema_name end unless has_loaded_schema? schema_name raise LoadedSchemaDoesNotExistError, "Loaded schema `#{schema_name}` does not exist" end @loaded_schemas[schema_name] end |
#loaded_schemas ⇒ Object
returns an array of this tables loaded schemas
55 56 57 |
# File 'lib/dynamic_migrations/postgres/server/database/loaded_schemas.rb', line 55 def loaded_schemas @loaded_schemas.values end |
#loaded_schemas_hash ⇒ Object
returns a hash of this tables loaded schemas, keyed by schema name
60 61 62 |
# File 'lib/dynamic_migrations/postgres/server/database/loaded_schemas.rb', line 60 def loaded_schemas_hash @loaded_schemas end |