Class: HeyYou::Config
- Inherits:
-
Object
- Object
- HeyYou::Config
- Extended by:
- Configurable
- Defined in:
- lib/hey_you/config.rb,
lib/hey_you/config/push.rb,
lib/hey_you/config/email.rb,
lib/hey_you/config/conigurable.rb,
lib/hey_you/config/data_source.rb
Defined Under Namespace
Modules: Configurable Classes: CollectionFileNotDefined, DataSource, Email, Push
Constant Summary collapse
- DEFAULTS =
{ registered_channels: %i[email push], splitter: '.', log_tag: 'HeyYou', localization: false, require_all_channels: false }
- DEFAULT_REGISTERED_CHANNELS =
DEFAULT_SPLITTER = '.'
- DEFAULT_GLOBAL_LOG_TAG =
'HeyYou'
- DEFAULT_LOCALIZATION_FLAG =
false
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
-
#configured ⇒ Object
readonly
Returns the value of attribute configured.
-
#data_source ⇒ Object
Returns the value of attribute data_source.
-
#env_collection ⇒ Object
readonly
Returns the value of attribute env_collection.
-
#localization ⇒ Object
Returns the value of attribute localization.
-
#log_tag ⇒ Object
Returns the value of attribute log_tag.
-
#logger ⇒ Object
Returns the value of attribute logger.
-
#registered_channels ⇒ Object
Returns the value of attribute registered_channels.
-
#registered_receivers ⇒ Object
readonly
Returns the value of attribute registered_receivers.
-
#require_all_channels ⇒ Object
Returns the value of attribute require_all_channels.
-
#splitter ⇒ Object
Returns the value of attribute splitter.
Instance Method Summary collapse
-
#initialize ⇒ Config
constructor
A new instance of Config.
- #log(msg) ⇒ Object
-
#registrate_channel(ch) ⇒ Object
Registrate new custom channel.
- #registrate_receiver(receiver_class) ⇒ Object
- #validate_config ⇒ Object
Methods included from Configurable
Constructor Details
#initialize ⇒ Config
Returns a new instance of Config.
42 43 44 45 46 47 48 49 50 |
# File 'lib/hey_you/config.rb', line 42 def initialize @registered_channels ||= DEFAULTS[:registered_channels] @splitter ||= DEFAULTS[:splitter] @registered_receivers = [] @log_tag ||= DEFAULTS[:log_tag] @localization ||= DEFAULTS[:localization] @require_all_channels = DEFAULTS[:require_all_channels] define_ch_config_methods end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
36 37 38 |
# File 'lib/hey_you/config.rb', line 36 def collection @collection end |
#configured ⇒ Object (readonly)
Returns the value of attribute configured.
36 37 38 |
# File 'lib/hey_you/config.rb', line 36 def configured @configured end |
#data_source ⇒ Object
Returns the value of attribute data_source.
37 38 39 |
# File 'lib/hey_you/config.rb', line 37 def data_source @data_source end |
#env_collection ⇒ Object (readonly)
Returns the value of attribute env_collection.
36 37 38 |
# File 'lib/hey_you/config.rb', line 36 def env_collection @env_collection end |
#localization ⇒ Object
Returns the value of attribute localization.
37 38 39 |
# File 'lib/hey_you/config.rb', line 37 def localization @localization end |
#log_tag ⇒ Object
Returns the value of attribute log_tag.
37 38 39 |
# File 'lib/hey_you/config.rb', line 37 def log_tag @log_tag end |
#logger ⇒ Object
Returns the value of attribute logger.
37 38 39 |
# File 'lib/hey_you/config.rb', line 37 def logger @logger end |
#registered_channels ⇒ Object
Returns the value of attribute registered_channels.
37 38 39 |
# File 'lib/hey_you/config.rb', line 37 def registered_channels @registered_channels end |
#registered_receivers ⇒ Object (readonly)
Returns the value of attribute registered_receivers.
36 37 38 |
# File 'lib/hey_you/config.rb', line 36 def registered_receivers @registered_receivers end |
#require_all_channels ⇒ Object
Returns the value of attribute require_all_channels.
37 38 39 |
# File 'lib/hey_you/config.rb', line 37 def require_all_channels @require_all_channels end |
#splitter ⇒ Object
Returns the value of attribute splitter.
37 38 39 |
# File 'lib/hey_you/config.rb', line 37 def splitter @splitter end |
Instance Method Details
#log(msg) ⇒ Object
83 84 85 |
# File 'lib/hey_you/config.rb', line 83 def log(msg) logger&.info("[#{log_tag}] #{msg} ") end |
#registrate_channel(ch) ⇒ Object
Registrate new custom channel. For successful registration, in application must be exists:
-
HeyYou::Channels::<YOUR_CHANNEL_NAME> < HeyYou::Channels::Base
-
HeyYou::Builder::<YOUR_CHANNEL_NAME> < HeyYou::Builder::Base
-
HeyYou::Config::<YOUR_CHANNEL_NAME> extended HeyYou::Config::Configurable
78 79 80 81 |
# File 'lib/hey_you/config.rb', line 78 def registrate_channel(ch) registered_channels << ch.to_sym define_ch_config_method(ch) end |
#registrate_receiver(receiver_class) ⇒ Object
60 61 62 63 |
# File 'lib/hey_you/config.rb', line 60 def registrate_receiver(receiver_class) log("#{receiver_class} registrated as receiver") @registered_receivers << receiver_class end |
#validate_config ⇒ Object
65 66 67 68 69 70 |
# File 'lib/hey_you/config.rb', line 65 def validate_config registered_channels.each do |ch| ch_config = send(ch) ch_config.validate_config if ch_config.respond_to?(:validate_config) end end |