Class: Lotus::Model::Configuration
- Inherits:
-
Object
- Object
- Lotus::Model::Configuration
- Defined in:
- lib/lotus/model/configuration.rb
Overview
Configuration for the framework, models and adapters.
Lotus::Model has its own global configuration that can be manipulated via ‘Lotus::Model.configure`.
Constant Summary collapse
- DEFAULT_MIGRATIONS_PATH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default migrations path
Pathname.new('db/migrations').freeze
- DEFAULT_SCHEMA_PATH =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
Default schema path
Pathname.new('db/schema.sql').freeze
Instance Attribute Summary collapse
-
#adapter_config ⇒ Lotus::Model::Config::Adapter
readonly
An adapter configuration template.
-
#mapper ⇒ Lotus::Model::Mapper
readonly
The persistence mapper.
Instance Method Summary collapse
-
#adapter(options = nil) ⇒ Object
Register adapter.
-
#duplicate ⇒ Lotus::Model::Configuration
private
Duplicate by copying the settings in a new instance.
-
#initialize ⇒ Lotus::Model::Configuration
constructor
Initialize a configuration instance.
-
#load! ⇒ Object
Load the configuration for the current framework.
-
#mapping(path = nil, &blk) ⇒ Object
Set global persistence mapping.
-
#migrations(path = nil) ⇒ Object
Migrations directory.
-
#reset! ⇒ Object
(also: #unload!)
Reset all the values to the defaults.
-
#root ⇒ Object
private
Root directory.
-
#schema(path = nil) ⇒ Object
Schema.
Constructor Details
#initialize ⇒ Lotus::Model::Configuration
Initialize a configuration instance
49 50 51 |
# File 'lib/lotus/model/configuration.rb', line 49 def initialize reset! end |
Instance Attribute Details
#adapter_config ⇒ Lotus::Model::Config::Adapter (readonly)
An adapter configuration template
41 42 43 |
# File 'lib/lotus/model/configuration.rb', line 41 def adapter_config @adapter_config end |
#mapper ⇒ Lotus::Model::Mapper (readonly)
The persistence mapper
34 35 36 |
# File 'lib/lotus/model/configuration.rb', line 34 def mapper @mapper end |
Instance Method Details
#adapter ⇒ Lotus::Model::Config::Adapter, NilClass #adapter ⇒ Object
Register adapter
There could only 1 adapter can be registered per application
114 115 116 117 118 119 120 121 |
# File 'lib/lotus/model/configuration.rb', line 114 def adapter( = nil) if .nil? @adapter_config else () @adapter_config ||= Lotus::Model::Config::Adapter.new() end end |
#duplicate ⇒ Lotus::Model::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.
Duplicate by copying the settings in a new instance.
234 235 236 237 238 239 |
# File 'lib/lotus/model/configuration.rb', line 234 def duplicate Configuration.new.tap do |c| c.instance_variable_set(:@adapter_config, @adapter_config) c.instance_variable_set(:@mapper, @mapper) end end |
#load! ⇒ Object
Load the configuration for the current framework
74 75 76 77 78 79 |
# File 'lib/lotus/model/configuration.rb', line 74 def load! _build_mapper _build_adapter mapper.load!(@adapter) end |
#mapping(blk) ⇒ Object #mapping(path) ⇒ Object
Set global persistence mapping
153 154 155 |
# File 'lib/lotus/model/configuration.rb', line 153 def mapping(path=nil, &blk) @mapper_config = Lotus::Model::Config::Mapper.new(path, &blk) end |
#migrations ⇒ Pathname #migrations(path) ⇒ Object
Migrations directory
It defaults to db/migrations
.
181 182 183 184 185 186 187 |
# File 'lib/lotus/model/configuration.rb', line 181 def migrations(path = nil) if path.nil? @migrations else @migrations = root.join(path).realpath end end |
#reset! ⇒ Object Also known as: unload!
Reset all the values to the defaults
58 59 60 61 62 63 64 65 |
# File 'lib/lotus/model/configuration.rb', line 58 def reset! @adapter = nil @adapter_config = nil @mapper = NullMapper.new @mapper_config = nil @migrations = DEFAULT_MIGRATIONS_PATH @schema = DEFAULT_SCHEMA_PATH end |
#root ⇒ 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.
Root directory
224 225 226 |
# File 'lib/lotus/model/configuration.rb', line 224 def root Lotus.respond_to?(:root) ? Lotus.root : Pathname.pwd end |
#schema ⇒ Pathname #schema(path) ⇒ Object
Schema
It defaults to db/schema.sql
.
212 213 214 215 216 217 218 |
# File 'lib/lotus/model/configuration.rb', line 212 def schema(path = nil) if path.nil? @schema else @schema = root.join(path) end end |