Class: Konsierge::Notifier::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/konsierge/notifier/configuration.rb

Defined Under Namespace

Classes: Error

Constant Summary collapse

ADAPTER_IMPLEMENTATIONS =
{
  telegram: Adapters::Telegram
}.freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeConfiguration

Returns a new instance of Configuration.



17
18
19
20
21
22
23
24
25
26
# File 'lib/konsierge/notifier/configuration.rb', line 17

def initialize
  @app_name              = nil
  @adapter               = :telegram
  @chat_id               = ENV.fetch('TELEGRAM_CHANNEL_ID', nil)
  @bot_enabled           = ENV.fetch('TELEGRAM_BOT_ENABLED', false)
  @message_template_path = File.expand_path('templates/telegram/message.html.erb', __dir__)
  @error_template_path   = File.expand_path('templates/telegram/error.html.erb', __dir__)
  @logger                = Logger.new($stdout)
  @parse_mode            = 'HTML'
end

Instance Attribute Details

#adapterObject

Returns the value of attribute adapter.



14
15
16
# File 'lib/konsierge/notifier/configuration.rb', line 14

def adapter
  @adapter
end

#app_nameObject

Returns the value of attribute app_name.



14
15
16
# File 'lib/konsierge/notifier/configuration.rb', line 14

def app_name
  @app_name
end

#bot_enabledObject

Returns the value of attribute bot_enabled.



14
15
16
# File 'lib/konsierge/notifier/configuration.rb', line 14

def bot_enabled
  @bot_enabled
end

#chat_idObject

Returns the value of attribute chat_id.



14
15
16
# File 'lib/konsierge/notifier/configuration.rb', line 14

def chat_id
  @chat_id
end

#error_template_pathObject

Returns the value of attribute error_template_path.



14
15
16
# File 'lib/konsierge/notifier/configuration.rb', line 14

def error_template_path
  @error_template_path
end

#loggerObject

Returns the value of attribute logger.



14
15
16
# File 'lib/konsierge/notifier/configuration.rb', line 14

def logger
  @logger
end

#message_template_pathObject

Returns the value of attribute message_template_path.



14
15
16
# File 'lib/konsierge/notifier/configuration.rb', line 14

def message_template_path
  @message_template_path
end

#parse_modeObject

Returns the value of attribute parse_mode.



14
15
16
# File 'lib/konsierge/notifier/configuration.rb', line 14

def parse_mode
  @parse_mode
end

Instance Method Details

#adapter_classObject



34
35
36
37
38
39
40
41
# File 'lib/konsierge/notifier/configuration.rb', line 34

def adapter_class
  unless ADAPTER_IMPLEMENTATIONS[@adapter]
    error_msg = "#{@adapter} must be one of #{ADAPTER_IMPLEMENTATIONS.keys.join(', ')}"
    raise Error, error_msg
  end

  ADAPTER_IMPLEMENTATIONS[@adapter.to_s.to_sym]
end

#to_hObject



28
29
30
31
32
# File 'lib/konsierge/notifier/configuration.rb', line 28

def to_h
  instance_variables.each_with_object({}) do |var, hash|
    hash[var.to_s.delete('@').to_sym] = instance_variable_get(var)
  end
end