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.
30 31 32 33 34 35 36 37 38 39 40 |
# File 'lib/hanami/model/configuration.rb', line 30 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.
166 167 168 169 170 171 172 |
# File 'lib/hanami/model/configuration.rb', line 166 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.
18 19 20 |
# File 'lib/hanami/model/configuration.rb', line 18 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.
22 23 24 |
# File 'lib/hanami/model/configuration.rb', line 22 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.
14 15 16 |
# File 'lib/hanami/model/configuration.rb', line 14 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.
26 27 28 |
# File 'lib/hanami/model/configuration.rb', line 26 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
46 47 48 |
# File 'lib/hanami/model/configuration.rb', line 46 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.
120 121 122 |
# File 'lib/hanami/model/configuration.rb', line 120 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
55 56 57 |
# File 'lib/hanami/model/configuration.rb', line 55 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.
107 108 109 110 111 112 113 114 115 116 |
# File 'lib/hanami/model/configuration.rb', line 107 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.
94 95 96 |
# File 'lib/hanami/model/configuration.rb', line 94 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
66 67 68 |
# File 'lib/hanami/model/configuration.rb', line 66 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.
150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/hanami/model/configuration.rb', line 150 def load!(repositories, &blk) # rubocop:disable Metrics/AbcSize 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 => e raise Hanami::Model::Error.for(e) end |
#migrations ⇒ Object
Migrations directory
81 82 83 |
# File 'lib/hanami/model/configuration.rb', line 81 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.
100 101 102 103 |
# File 'lib/hanami/model/configuration.rb', line 100 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.
176 177 178 |
# File 'lib/hanami/model/configuration.rb', line 176 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.
137 138 139 140 141 142 143 |
# File 'lib/hanami/model/configuration.rb', line 137 def rom @rom ||= ROM::Configuration.new(@backend, @url, infer_relations: false) rescue => e raise UnknownDatabaseAdapterError.new(@url) if e. =~ /adapters/ raise e end |