Module: Pechkin::ConfigurationLoader

Included in:
ConfigurationLoaderBots, ConfigurationLoaderChannels, ConfigurationLoaderViews
Defined in:
lib/pechkin/configuration/configuration_loader.rb

Overview

Common code for all configuration loaders. To use this code just include module in user class.

Instance Method Summary collapse

Instance Method Details

#check_field(object, field, file) ⇒ Object

Raises:



5
6
7
8
9
10
11
# File 'lib/pechkin/configuration/configuration_loader.rb', line 5

def check_field(object, field, file)
  contains = object.key?(field)

  raise ConfigurationError, "#{file}: '#{field}' is missing" unless contains

  object[field]
end

#create_connector(bot) ⇒ Object



13
14
15
16
17
18
19
20
21
22
# File 'lib/pechkin/configuration/configuration_loader.rb', line 13

def create_connector(bot)
  case bot.connector
  when 'tg', 'telegram'
    Connector::Telegram.new(bot.token, bot.name)
  when 'slack'
    Connector::Slack.new(bot.token, bot.name)
  else
    raise "Unknown connector #{bot.connector} for #{bot.name}"
  end
end

#yaml_load(file) ⇒ Object



24
25
26
# File 'lib/pechkin/configuration/configuration_loader.rb', line 24

def yaml_load(file)
  YAML.safe_load(IO.read(file))
end