Module: Hanami::Model
- Defined in:
- lib/hanami/model.rb,
lib/hanami/model/sql.rb,
lib/hanami/model/error.rb,
lib/hanami/model/types.rb,
lib/hanami/model/mapping.rb,
lib/hanami/model/plugins.rb,
lib/hanami/model/version.rb,
lib/hanami/model/migrator.rb,
lib/hanami/model/migration.rb,
lib/hanami/model/sql/types.rb,
lib/hanami/model/association.rb,
lib/hanami/model/entity_name.rb,
lib/hanami/model/sql/console.rb,
lib/hanami/model/configurator.rb,
lib/hanami/model/configuration.rb,
lib/hanami/model/relation_name.rb,
lib/hanami/model/plugins/schema.rb,
lib/hanami/model/mapped_relation.rb,
lib/hanami/model/migrator/logger.rb,
lib/hanami/model/plugins/mapping.rb,
lib/hanami/model/associations/dsl.rb,
lib/hanami/model/migrator/adapter.rb,
lib/hanami/model/sql/entity/schema.rb,
lib/hanami/model/plugins/timestamps.rb,
lib/hanami/model/sql/consoles/mysql.rb,
lib/hanami/model/migrator/connection.rb,
lib/hanami/model/sql/consoles/sqlite.rb,
lib/hanami/model/associations/has_one.rb,
lib/hanami/model/associations/has_many.rb,
lib/hanami/model/sql/consoles/abstract.rb,
lib/hanami/model/migrator/mysql_adapter.rb,
lib/hanami/model/associations/belongs_to.rb,
lib/hanami/model/migrator/sqlite_adapter.rb,
lib/hanami/model/sql/consoles/postgresql.rb,
lib/hanami/model/associations/many_to_many.rb,
lib/hanami/model/migrator/postgres_adapter.rb,
lib/hanami/model/sql/types/schema/coercions.rb
Overview
Hanami::Model migrations
Defined Under Namespace
Modules: Associations, Plugins, Sql, Types Classes: Association, CheckConstraintViolationError, Configuration, Configurator, ConstraintViolationError, DatabaseError, EntityName, Error, ForeignKeyConstraintViolationError, InvalidCommandError, MappedRelation, Mapping, Migration, MigrationError, Migrator, MissingPrimaryKeyError, NotNullConstraintViolationError, RelationName, UniqueConstraintViolationError, UnknownAttributeError, UnknownDatabaseAdapterError, UnknownDatabaseTypeError
Constant Summary collapse
- VERSION =
Defines the version
'1.3.2'.freeze
Class Attribute Summary collapse
- .config ⇒ Object readonly private
- .loaded ⇒ Object (also: loaded?) readonly private
Class Method Summary collapse
-
.configuration ⇒ Object
Current configuration.
-
.configure(&block) ⇒ Object
Configure the framework.
- .container ⇒ Object private
-
.disconnect ⇒ Object
Disconnect from the database.
- .load!(&blk) ⇒ Object
-
.migration(&blk) ⇒ Object
Define a migration.
- .repositories ⇒ Object private
Class Attribute Details
.config ⇒ Object (readonly)
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
28 29 30 |
# File 'lib/hanami/model.rb', line 28 def config @config end |
.loaded ⇒ Object (readonly) Also known as: loaded?
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
32 33 34 |
# File 'lib/hanami/model.rb', line 32 def loaded @loaded end |
Class Method Details
.configuration ⇒ Object
Current configuration
60 61 62 |
# File 'lib/hanami/model.rb', line 60 def self.configuration @configuration ||= Configuration.new(config) end |
.configure(&block) ⇒ Object
Configure the framework
52 53 54 55 |
# File 'lib/hanami/model.rb', line 52 def self.configure(&block) @config = Configurator.build(&block) self end |
.container ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
72 73 74 75 76 |
# File 'lib/hanami/model.rb', line 72 def self.container raise 'Not loaded' unless loaded? @container end |
.disconnect ⇒ Object
Disconnect from the database
This is useful for rebooting applications in production and to ensure that the framework prunes stale connections.
105 106 107 |
# File 'lib/hanami/model.rb', line 105 def self.disconnect configuration.connection&.disconnect end |
.load!(&blk) ⇒ Object
79 80 81 82 |
# File 'lib/hanami/model.rb', line 79 def self.load!(&blk) @container = configuration.load!(repositories, &blk) @loaded = true end |
.migration(&blk) ⇒ Object
Define a migration
It must define an up/down strategy to write schema changes (up) and to rollback them (down).
We can use up
and down
blocks for custom strategies, or only one change
block that automatically implements “down” strategy.
48 49 50 |
# File 'lib/hanami/model/sql.rb', line 48 def self.migration(&blk) Migration.new(configuration.gateways[:default], &blk) end |
.repositories ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
66 67 68 |
# File 'lib/hanami/model.rb', line 66 def self.repositories @__repositories__ end |