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.
149 150 151 152 153 154 155 |
# File 'lib/hanami/model/configuration.rb', line 149 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.
114 115 116 |
# File 'lib/hanami/model/configuration.rb', line 114 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
52 53 54 |
# File 'lib/hanami/model/configuration.rb', line 52 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.
101 102 103 104 105 106 107 108 109 110 |
# File 'lib/hanami/model/configuration.rb', line 101 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.
88 89 90 |
# File 'lib/hanami/model/configuration.rb', line 88 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
60 61 62 |
# File 'lib/hanami/model/configuration.rb', line 60 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.
133 134 135 136 137 138 139 140 141 142 143 144 145 |
# File 'lib/hanami/model/configuration.rb', line 133 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
75 76 77 |
# File 'lib/hanami/model/configuration.rb', line 75 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.
94 95 96 97 |
# File 'lib/hanami/model/configuration.rb', line 94 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.
159 160 161 |
# File 'lib/hanami/model/configuration.rb', line 159 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.
127 128 129 |
# File 'lib/hanami/model/configuration.rb', line 127 def rom @rom ||= ROM::Configuration.new(@backend, @url, infer_relations: false) end |