Module: UltraSettings
- Defined in:
- lib/ultra_settings.rb,
lib/ultra_settings/field.rb,
lib/ultra_settings/coerce.rb,
lib/ultra_settings/railtie.rb,
lib/ultra_settings/version.rb,
lib/ultra_settings/rack_app.rb,
lib/ultra_settings/web_view.rb,
lib/ultra_settings/view_helper.rb,
lib/ultra_settings/yaml_config.rb,
lib/ultra_settings/config_helper.rb,
lib/ultra_settings/configuration.rb,
lib/ultra_settings/render_helper.rb,
lib/ultra_settings/application_view.rb,
lib/ultra_settings/configuration_view.rb,
lib/ultra_settings/uninitialized_runtime_settings.rb
Overview
This is the root namespace for UltraSettings. You can add configurations to this namespace using the add method.
Defined Under Namespace
Modules: ConfigHelper, RenderHelper, ViewHelper Classes: ApplicationView, Coerce, Configuration, ConfigurationView, Field, RackApp, Railtie, UninitializedRuntimeSettings, WebView, YamlConfig
Constant Summary collapse
- VALID_NAME__PATTERN =
/\A[a-z_][a-zA-Z0-9_]*\z/- VERSION =
File.read(File.join(__dir__, "..", "..", "VERSION")).strip
Class Attribute Summary collapse
-
.runtime_settings ⇒ void
writeonly
Set the object to use for runtime settings.
-
.runtime_settings_secure ⇒ void
writeonly
Set whether or not the runtime settings engine is considered secure.
-
.runtime_settings_url(name: nil, type: nil, description: nil) ⇒ String?
private
Get the URL for changing runtime settings.
Class Method Summary collapse
-
.__configuration_names__ ⇒ Array<String>
private
Get the names of all of the configurations that have been added.
-
.__configurations__ ⇒ Array<UltraSettings::Configuration>
private
Get an array of all of the configuration instances that have been loaded into memory.
-
.__runtime_settings__ ⇒ Object?
private
Get the object to use for runtime settings.
-
.add(name, klass = nil) ⇒ void
Adds a configuration to the root namespace.
-
.added?(class_name) ⇒ Boolean
Returns true if the provided class has been added as a configuration.
-
.env_var_delimiter=(value) ⇒ void
Set the delimiter to use when determining environment variable names.
-
.env_var_upcase=(value) ⇒ void
Control if environment variable names should be upcased.
-
.environment_variables_disabled=(value) ⇒ void
Control if settings can be loaded from environment variables.
-
.fields_secret_by_default=(value) ⇒ void
Set whether fields should be considered secret by default.
-
.override!(settings, &block) ⇒ Object
Explicitly set values for setting within a block.
-
.runtime_setting_delimiter=(value) ⇒ void
Set the delimiter to use when determining setting names.
-
.runtime_setting_upcase=(value) ⇒ void
Control if setting names should be upcased.
-
.runtime_settings_disabled=(value) ⇒ void
Control if settings can be loaded from runtime settings.
-
.runtime_settings_secure? ⇒ Boolean
Check if the runtime settings engine is considered secure.
-
.yaml_config_disabled=(value) ⇒ void
Control if settings can be loaded from YAML configuration files.
-
.yaml_config_env=(value) ⇒ void
Set the environment to use when loading YAML configuration files.
-
.yaml_config_path=(value) ⇒ void
Set the directory to use when loading YAML configuration files.
Class Attribute Details
.runtime_settings=(value) ⇒ void (writeonly)
This method returns an undefined value.
Set the object to use for runtime settings. This can be any object that responds to the [] method. If you are using the ‘super_settings` gem, you can set this to `SuperSettings`.
172 173 174 |
# File 'lib/ultra_settings.rb', line 172 def runtime_settings=(value) @runtime_settings = value end |
.runtime_settings_secure=(value) ⇒ void (writeonly)
This method returns an undefined value.
Set whether or not the runtime settings engine is considered secure. If this is set to false, then runtime settings will be disabled for all fields marked as secret. The default value is true.
213 214 215 |
# File 'lib/ultra_settings.rb', line 213 def runtime_settings_secure=(value) @runtime_settings_secure = value end |
.runtime_settings_url(name: nil, type: nil, description: nil) ⇒ String?
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.
Get the URL for changing runtime settings.
198 199 200 201 202 203 204 205 |
# File 'lib/ultra_settings.rb', line 198 def runtime_settings_url(name: nil, type: nil, description: nil) url = @runtime_settings_url.to_s return nil if url.empty? url.gsub("${name}", URI.encode_www_form_component(name.to_s)) .gsub("${type}", URI.encode_www_form_component(type.to_s)) .gsub("${description}", URI.encode_www_form_component(description.to_s)) end |
Class Method Details
.__configuration_names__ ⇒ Array<String>
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.
Get the names of all of the configurations that have been added.
259 260 261 |
# File 'lib/ultra_settings.rb', line 259 def __configuration_names__ @configurations.keys end |
.__configurations__ ⇒ Array<UltraSettings::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.
Get an array of all of the configuration instances that have been loaded into memory.
267 268 269 270 271 272 273 274 |
# File 'lib/ultra_settings.rb', line 267 def __configurations__ @configurations.each do |name, class_name| __load_config__(name, class_name) end config_classes = ObjectSpace.each_object(Class).select { |klass| klass < Configuration } config_classes.collect(&:instance) end |
.__runtime_settings__ ⇒ 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.
Get the object to use for runtime settings.
178 179 180 |
# File 'lib/ultra_settings.rb', line 178 def __runtime_settings__ @runtime_settings end |
.add(name, klass = nil) ⇒ void
This method returns an undefined value.
Adds a configuration to the root namespace. The configuration will be available as a method on the UltraSettings module with the provide name.
53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'lib/ultra_settings.rb', line 53 def add(name, klass = nil) name = name.to_s unless name.match?(VALID_NAME__PATTERN) raise ArgumentError.new("Invalid configuration name: #{name.inspect}") end class_name = klass&.to_s class_name ||= "#{classify(name)}Configuration" @mutex.synchronize do @configurations[name] = class_name eval " def \#{name}\n __load_config__(\#{name.inspect}, \#{class_name.inspect})\n end\n RUBY\n end\nend\n", binding, __FILE__, __LINE__ + 1 # rubocop:disable Security/Eval |
.added?(class_name) ⇒ Boolean
Returns true if the provided class has been added as a configuration.
77 78 79 |
# File 'lib/ultra_settings.rb', line 77 def added?(class_name) @configurations.values.collect(&:to_s).include?(class_name.to_s) end |
.env_var_delimiter=(value) ⇒ void
This method returns an undefined value.
Set the delimiter to use when determining environment variable names. By default this is an underscore.
126 127 128 |
# File 'lib/ultra_settings.rb', line 126 def env_var_delimiter=(value) Configuration.env_var_delimiter = value.to_s end |
.env_var_upcase=(value) ⇒ void
This method returns an undefined value.
Control if environment variable names should be upcased. By default this is true.
144 145 146 |
# File 'lib/ultra_settings.rb', line 144 def env_var_upcase=(value) Configuration.env_var_upcase = !!value end |
.environment_variables_disabled=(value) ⇒ void
This method returns an undefined value.
Control if settings can be loaded from environment variables. By default environment variables are enabled. This can also be disabled on individual Configuration classes.
87 88 89 |
# File 'lib/ultra_settings.rb', line 87 def environment_variables_disabled=(value) Configuration.environment_variables_disabled = !!value end |
.fields_secret_by_default=(value) ⇒ void
This method returns an undefined value.
Set whether fields should be considered secret by default.
226 227 228 |
# File 'lib/ultra_settings.rb', line 226 def fields_secret_by_default=(value) Configuration.fields_secret_by_default = value end |
.override!(settings, &block) ⇒ Object
Explicitly set values for setting within a block. This is useful for testing or other situations where you want hard code a specific set of values.
235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 |
# File 'lib/ultra_settings.rb', line 235 def override!(settings, &block) settings = settings.to_a config_name, values = settings.first config_name = config_name.to_s other_settings = settings[1..-1] unless @configurations.include?(config_name) raise ArgumentError.new("Unknown configuration: #{config_name.inspect}") end config = send(config_name) config.override!(values) do if other_settings.empty? yield else override!(other_settings, &block) end end end |
.runtime_setting_delimiter=(value) ⇒ void
This method returns an undefined value.
Set the delimiter to use when determining setting names. By default this is a period.
135 136 137 |
# File 'lib/ultra_settings.rb', line 135 def runtime_setting_delimiter=(value) Configuration.runtime_setting_delimiter = value.to_s end |
.runtime_setting_upcase=(value) ⇒ void
This method returns an undefined value.
Control if setting names should be upcased. By default this is false.
152 153 154 |
# File 'lib/ultra_settings.rb', line 152 def runtime_setting_upcase=(value) Configuration.runtime_setting_upcase = !!value end |
.runtime_settings_disabled=(value) ⇒ void
This method returns an undefined value.
Control if settings can be loaded from runtime settings. By default runtime settings are enabled. This can also be disabled on individual Configuration classes.
97 98 99 |
# File 'lib/ultra_settings.rb', line 97 def runtime_settings_disabled=(value) Configuration.runtime_settings_disabled = !!value end |
.runtime_settings_secure? ⇒ Boolean
Check if the runtime settings engine is considered secure.
218 219 220 |
# File 'lib/ultra_settings.rb', line 218 def runtime_settings_secure? @runtime_settings_secure end |
.yaml_config_disabled=(value) ⇒ void
This method returns an undefined value.
Control if settings can be loaded from YAML configuration files. By default YAML configuration is enabled. This can also be disabled on individual Configuration classes.
107 108 109 |
# File 'lib/ultra_settings.rb', line 107 def yaml_config_disabled=(value) Configuration.yaml_config_disabled = !!value end |
.yaml_config_env=(value) ⇒ void
This method returns an undefined value.
Set the environment to use when loading YAML configuration files. In a Rails application this will be the current Rails environment. Defaults to “development”.
117 118 119 |
# File 'lib/ultra_settings.rb', line 117 def yaml_config_env=(value) Configuration.yaml_config_env = value end |
.yaml_config_path=(value) ⇒ void
This method returns an undefined value.
Set the directory to use when loading YAML configuration files. In a Rails application this will be the config directory. Otherwise it will be the current working directory.
162 163 164 |
# File 'lib/ultra_settings.rb', line 162 def yaml_config_path=(value) Configuration.yaml_config_path = value.to_s end |