1
1
# frozen_string_literal: true
2
2
3
+ # :markup: markdown
4
+
3
5
module ActiveRecord
4
6
class DatabaseConfigurations
5
- # = Active Record Database Hash Config
7
+ # # Active Record Database Hash Config
6
8
#
7
- # A + HashConfig+ object is created for each database configuration entry that
8
- # is created from a hash.
9
+ # A ` HashConfig` object is created for each database configuration entry that is
10
+ # created from a hash.
9
11
#
10
12
# A hash config:
11
13
#
12
- # { "development" => { "database" => "db_name" } }
14
+ # { "development" => { "database" => "db_name" } }
13
15
#
14
16
# Becomes:
15
17
#
16
- # #<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10
17
- # @env_name="development", @name="primary", @config={database: "db_name"}>
18
+ # #<ActiveRecord::DatabaseConfigurations::HashConfig:0x00007fd1acbded10
19
+ # @env_name="development", @name="primary", @config={database: "db_name"}>
18
20
#
19
21
# See ActiveRecord::DatabaseConfigurations for more info.
20
22
class HashConfig < DatabaseConfig
21
23
attr_reader :configuration_hash
22
24
23
- # Initialize a new +HashConfig+ object
25
+ # Initialize a new `HashConfig` object
26
+ #
27
+ # #### Parameters
24
28
#
25
- # ==== Parameters
29
+ # * `env_name` - The Rails environment, i.e. "development".
30
+ # * `name` - The db config name. In a standard two-tier database configuration
31
+ # this will default to "primary". In a multiple database three-tier database
32
+ # configuration this corresponds to the name used in the second tier, for
33
+ # example "primary_readonly".
34
+ # * `configuration_hash` - The config hash. This is the hash that contains the
35
+ # database adapter, name, and other important information for database
36
+ # connections.
26
37
#
27
- # * <tt>env_name</tt> - The \Rails environment, i.e. "development".
28
- # * <tt>name</tt> - The db config name. In a standard two-tier
29
- # database configuration this will default to "primary". In a multiple
30
- # database three-tier database configuration this corresponds to the name
31
- # used in the second tier, for example "primary_readonly".
32
- # * <tt>configuration_hash</tt> - The config hash. This is the hash that contains the
33
- # database adapter, name, and other important information for database
34
- # connections.
35
38
def initialize ( env_name , name , configuration_hash )
36
39
super ( env_name , name )
37
40
@configuration_hash = configuration_hash . symbolize_keys . freeze
38
41
end
39
42
40
43
# Determines whether a database configuration is for a replica / readonly
41
- # connection. If the + replica+ key is present in the config, + replica?+ will
42
- # return + true+ .
44
+ # connection. If the ` replica` key is present in the config, ` replica?` will
45
+ # return ` true` .
43
46
def replica?
44
47
configuration_hash [ :replica ]
45
48
end
46
49
47
- # The migrations paths for a database configuration. If the
48
- # +migrations_paths+ key is present in the config, +migrations_paths+
49
- # will return its value.
50
+ # The migrations paths for a database configuration. If the `migrations_paths`
51
+ # key is present in the config, `migrations_paths` will return its value.
50
52
def migrations_paths
51
53
configuration_hash [ :migrations_paths ]
52
54
end
@@ -91,8 +93,8 @@ def checkout_timeout
91
93
( configuration_hash [ :checkout_timeout ] || 5 ) . to_f
92
94
end
93
95
94
- # + reaping_frequency+ is configurable mostly for historical reasons, but it could
95
- # also be useful if someone wants a very low + idle_timeout+ .
96
+ # ` reaping_frequency` is configurable mostly for historical reasons, but it
97
+ # could also be useful if someone wants a very low ` idle_timeout` .
96
98
def reaping_frequency
97
99
configuration_hash . fetch ( :reaping_frequency , 60 ) &.to_f
98
100
end
@@ -106,9 +108,8 @@ def adapter
106
108
configuration_hash [ :adapter ] &.to_s
107
109
end
108
110
109
- # The path to the schema cache dump file for a database.
110
- # If omitted, the filename will be read from ENV or a
111
- # default will be derived.
111
+ # The path to the schema cache dump file for a database. If omitted, the
112
+ # filename will be read from ENV or a default will be derived.
112
113
def schema_cache_path
113
114
configuration_hash [ :schema_cache_path ]
114
115
end
@@ -129,14 +130,14 @@ def primary? # :nodoc:
129
130
Base . configurations . primary? ( name )
130
131
end
131
132
132
- # Determines whether to dump the schema/structure files and the
133
- # filename that should be used.
133
+ # Determines whether to dump the schema/structure files and the filename that
134
+ # should be used.
134
135
#
135
- # If + configuration_hash[:schema_dump]+ is set to + false+ or + nil+
136
- # the schema will not be dumped.
136
+ # If ` configuration_hash[:schema_dump]` is set to ` false` or ` nil` the schema
137
+ # will not be dumped.
137
138
#
138
- # If the config option is set that will be used. Otherwise \ Rails
139
- # will generate the filename from the database config name.
139
+ # If the config option is set that will be used. Otherwise Rails will generate
140
+ # the filename from the database config name.
140
141
def schema_dump ( format = ActiveRecord . schema_format )
141
142
if configuration_hash . key? ( :schema_dump )
142
143
if config = configuration_hash [ :schema_dump ]
0 commit comments