Class: EmailAddress::Config
- Inherits:
-
Object
- Object
- EmailAddress::Config
- Defined in:
- lib/email_address/config.rb
Class Attribute Summary collapse
-
.providers ⇒ Object
readonly
Returns the value of attribute providers.
Class Method Summary collapse
- .all_settings(*configs) ⇒ Object
-
.configure(config = {}) ⇒ Object
Set multiple default configuration settings.
- .error_message(name, locale = "en") ⇒ Object
-
.error_messages(hash = {}, locale = "en", *extra) ⇒ Object
Customize your own error message text.
-
.provider(name, config = {}) ⇒ Object
Configure or lookup a provider by name.
- .setting(name, *value) ⇒ Object
Instance Method Summary collapse
- #[](setting) ⇒ Object
- #[]=(setting, value) ⇒ Object
- #configure(settings) ⇒ Object
-
#initialize(overrides = {}) ⇒ Config
constructor
A new instance of Config.
- #to_h ⇒ Object
Constructor Details
#initialize(overrides = {}) ⇒ Config
Returns a new instance of Config.
223 224 225 |
# File 'lib/email_address/config.rb', line 223 def initialize(overrides = {}) @config = Config.all_settings(overrides) end |
Class Attribute Details
.providers ⇒ Object (readonly)
Returns the value of attribute providers.
187 188 189 |
# File 'lib/email_address/config.rb', line 187 def providers @providers end |
Class Method Details
.all_settings(*configs) ⇒ Object
217 218 219 220 221 |
# File 'lib/email_address/config.rb', line 217 def self.all_settings(*configs) config = @config.clone configs.each { |c| config.merge!(c) } config end |
.configure(config = {}) ⇒ Object
Set multiple default configuration settings
175 176 177 |
# File 'lib/email_address/config.rb', line 175 def self.configure(config = {}) @config.merge!(config) end |
.error_message(name, locale = "en") ⇒ Object
199 200 201 |
# File 'lib/email_address/config.rb', line 199 def self.(name, locale = "en") @errors.dig(locale, "email_address", name.to_s) || name.to_s end |
.error_messages(hash = {}, locale = "en", *extra) ⇒ Object
Customize your own error message text.
204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/email_address/config.rb', line 204 def self.(hash = {}, locale = "en", *extra) hash = extra.first if extra.first.is_a? Hash @errors[locale] ||= {} @errors[locale]["email_address"] ||= {} unless hash.nil? || hash.empty? @errors[locale]["email_address"] = @errors[locale]["email_address"].merge(hash) end @errors[locale]["email_address"] end |
.provider(name, config = {}) ⇒ Object
Configure or lookup a provider by name.
191 192 193 194 195 196 197 |
# File 'lib/email_address/config.rb', line 191 def self.provider(name, config = {}) name = name.to_sym if config.size > 0 @providers[name.to_sym] = config end @providers[name] end |
.setting(name, *value) ⇒ Object
179 180 181 182 183 |
# File 'lib/email_address/config.rb', line 179 def self.setting(name, *value) name = name.to_sym @config[name] = value.first if value.size > 0 @config[name] end |
Instance Method Details
#[](setting) ⇒ Object
231 232 233 |
# File 'lib/email_address/config.rb', line 231 def [](setting) @config[setting.to_sym] end |
#[]=(setting, value) ⇒ Object
227 228 229 |
# File 'lib/email_address/config.rb', line 227 def []=(setting, value) @config[setting.to_sym] = value end |
#configure(settings) ⇒ Object
235 236 237 |
# File 'lib/email_address/config.rb', line 235 def configure(settings) @config = @config.merge(settings) end |
#to_h ⇒ Object
239 240 241 |
# File 'lib/email_address/config.rb', line 239 def to_h @config end |