Sha256: c689b2e688031d78b5d6889c2efcfd0db5a7cf62c167c960bd714deb0f32c4ab

Contents?: true

Size: 1.03 KB

Versions: 3

Compression:

Stored size: 1.03 KB

Contents

unless defined?(Rails)
  require "logger"
end

module TelegramOnSteroids
  class << self
    def config
      @config ||= Configuration.new
    end

    def configure
      yield(config)
      config.verify!

      @__after_configuration.call(config) if @__after_configuration
    end

    def __after_configuration(&block)
      @__after_configuration = block
    end
  end

  class Configuration
    attr_accessor :session_store, :logger, :client, :start_action, :webhook_url, :api_token,
                  :webhook_params, :commands

    REQUIRED_PARAMS = %i(start_action api_token)

    def initialize
      @client = TelegramOnSteroids::Client
      @webhook_params = {}

      if defined?(Rails)
        @session_store = Rails.cache
        @logger = Rails.logger
      else
        @session_store = InMemoryStore
        @logger = Logger.new(STDOUT)
      end
    end

    def verify!
      blank_params = REQUIRED_PARAMS.select { |p| send(p).nil? }

      if blank_params.any?
        raise StandardError, blank_params
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
telegram_on_steroids-0.1.2 lib/telegram_on_steroids/configuration.rb
telegram_on_steroids-0.1.1 lib/telegram_on_steroids/configuration.rb
telegram_on_steroids-0.1.0 lib/telegram_on_steroids/configuration.rb