Class: Hanami::Model::Configuration
- Inherits:
-
Object
- Object
- Hanami::Model::Configuration
- Defined in:
- lib/hanami/model/configuration.rb
Overview
Configuration for the framework, models and adapters.
Hanami::Model has its own global configuration that can be manipulated via ‘Hanami::Model.configure`.
Instance Attribute Summary collapse
- #entities ⇒ Object readonly private
- #logger ⇒ Object private
- #mappings ⇒ Object readonly private
- #migrations_logger ⇒ Object readonly private
-
#url ⇒ Object
readonly
private
NOTE: This must be changed when we want to support several adapters at the time.
Instance Method Summary collapse
- #configure_gateway ⇒ Object private
-
#connection ⇒ Object
private
NOTE: This must be changed when we want to support several adapters at the time.
- #define_entities_mappings(container, repositories) ⇒ Object private
- #define_mappings(root, &blk) ⇒ Object private
-
#gateway ⇒ Object
private
NOTE: This must be changed when we want to support several adapters at the time.
-
#initialize(configurator) ⇒ Configuration
constructor
private
A new instance of Configuration.
- #load!(repositories, &blk) ⇒ Object private
- #method_missing(method_name, *args, &blk) ⇒ Object private
-
#migrations ⇒ Object
Migrations directory.
- #register_entity(plural, singular, klass) ⇒ Object private
- #respond_to_missing?(method_name, include_all) ⇒ Boolean private
- #rom ⇒ Object private
-
#root ⇒ Object
private
Root directory.
-
#schema ⇒ Object
Path for schema dump file.
Constructor Details
#initialize(configurator) ⇒ Configuration
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.
Returns a new instance of Configuration.
32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/hanami/model/configuration.rb', line 32 def initialize(configurator) @backend = configurator.backend @url = configurator.url @migrations = configurator._migrations @schema = configurator._schema @gateway_config = configurator._gateway @logger = configurator._logger @migrations_logger = configurator.migrations_logger @mappings = {} @entities = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &blk) ⇒ 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.
168 169 170 171 172 173 174 |
# File 'lib/hanami/model/configuration.rb', line 168 def method_missing(method_name, *args, &blk) if rom.respond_to?(method_name) rom.__send__(method_name, *args, &blk) else super end end |
Instance Attribute Details
#entities ⇒ 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.
20 21 22 |
# File 'lib/hanami/model/configuration.rb', line 20 def entities @entities end |
#logger ⇒ 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.
24 25 26 |
# File 'lib/hanami/model/configuration.rb', line 24 def logger @logger end |
#mappings ⇒ 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.
16 17 18 |
# File 'lib/hanami/model/configuration.rb', line 16 def mappings @mappings end |
#migrations_logger ⇒ 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/configuration.rb', line 28 def migrations_logger @migrations_logger end |
#url ⇒ 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.
NOTE: This must be changed when we want to support several adapters at the time
48 49 50 |
# File 'lib/hanami/model/configuration.rb', line 48 def url @url end |
Instance Method Details
#configure_gateway ⇒ 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.
122 123 124 |
# File 'lib/hanami/model/configuration.rb', line 122 def configure_gateway @gateway_config&.call(gateway) end |
#connection ⇒ 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.
NOTE: This must be changed when we want to support several adapters at the time
57 58 59 |
# File 'lib/hanami/model/configuration.rb', line 57 def connection gateway.connection end |
#define_entities_mappings(container, 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.
109 110 111 112 113 114 115 116 117 118 |
# File 'lib/hanami/model/configuration.rb', line 109 def define_entities_mappings(container, repositories) return unless defined?(Sql::Entity::Schema) repositories.each do |r| relation = r.relation entity = r.entity entity.schema = Sql::Entity::Schema.new(entities, container.relations[relation], mappings.fetch(relation)) end end |
#define_mappings(root, &blk) ⇒ 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.
96 97 98 |
# File 'lib/hanami/model/configuration.rb', line 96 def define_mappings(root, &blk) @mappings[root] = Mapping.new(&blk) end |
#gateway ⇒ 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.
NOTE: This must be changed when we want to support several adapters at the time
68 69 70 |
# File 'lib/hanami/model/configuration.rb', line 68 def gateway gateways[:default] end |
#load!(repositories, &blk) ⇒ 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.
152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/hanami/model/configuration.rb', line 152 def load!(repositories, &blk) rom.setup.auto_registration(config.directory.to_s) unless config.directory.nil? rom.instance_eval(&blk) if block_given? configure_gateway repositories.each(&:load!) self.logger = logger container = ROM.container(rom) define_entities_mappings(container, repositories) container rescue => exception raise Hanami::Model::Error.for(exception) end |
#migrations ⇒ Object
Migrations directory
83 84 85 |
# File 'lib/hanami/model/configuration.rb', line 83 def migrations (@migrations.nil? ? root : root.join(@migrations)).realpath end |
#register_entity(plural, singular, klass) ⇒ 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.
102 103 104 105 |
# File 'lib/hanami/model/configuration.rb', line 102 def register_entity(plural, singular, klass) @entities[plural] = klass @entities[singular] = klass end |
#respond_to_missing?(method_name, include_all) ⇒ Boolean
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.
178 179 180 |
# File 'lib/hanami/model/configuration.rb', line 178 def respond_to_missing?(method_name, include_all) rom.respond_to?(method_name, include_all) end |
#rom ⇒ 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.
139 140 141 142 143 144 145 |
# File 'lib/hanami/model/configuration.rb', line 139 def rom @rom ||= ROM::Configuration.new(@backend, @url, infer_relations: false) rescue => exception raise UnknownDatabaseAdapterError.new(@url) if exception. =~ /adapters/ raise exception end |