Class: HeyYou::Config

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Methods included from Configurable

config, configure, extended

Constructor Details

#initializeConfig

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

#collectionObject (readonly)

Returns the value of attribute collection.



36
37
38
# File 'lib/hey_you/config.rb', line 36

def collection
  @collection
end

#configuredObject (readonly)

Returns the value of attribute configured.



36
37
38
# File 'lib/hey_you/config.rb', line 36

def configured
  @configured
end

#data_sourceObject

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_collectionObject (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

#localizationObject

Returns the value of attribute localization.



37
38
39
# File 'lib/hey_you/config.rb', line 37

def localization
  @localization
end

#log_tagObject

Returns the value of attribute log_tag.



37
38
39
# File 'lib/hey_you/config.rb', line 37

def log_tag
  @log_tag
end

#loggerObject

Returns the value of attribute logger.



37
38
39
# File 'lib/hey_you/config.rb', line 37

def logger
  @logger
end

#registered_channelsObject

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_receiversObject (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_channelsObject

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

#splitterObject

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:

  1. HeyYou::Channels::<YOUR_CHANNEL_NAME> < HeyYou::Channels::Base

  2. HeyYou::Builder::<YOUR_CHANNEL_NAME> < HeyYou::Builder::Base

  3. 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_configObject



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