Sha256: 0bc384979c1cb288088118cbf0f4de002197a3a99948954ebd18ff80aea37fac

Contents?: true

Size: 915 Bytes

Versions: 6

Compression:

Stored size: 915 Bytes

Contents

require 'sms_broker/setup'
require 'sms_broker/exceptions/invalid_setup'

module SmsBroker
  module Configuration
    extend self

    @configuration = nil

    def default_service
      configuration[:default_service]
    end

    def clear_setup
      @configuration = nil
    end

    def configuration
      exception = \
        Exceptions::InvalidSetup.new('setup does not exists')

      @configuration || (raise exception)
    end

    def setup
      setup = Setup.new
      yield setup if block_given?

      @configuration = setup.options

      setup
    end

    def setup!
      setup = Setup.new
      yield setup if block_given?

      unless setup.valid?
        exception = \
          Exceptions::InvalidSetup.new("setup is invalid, #{setup.errors}")

        exception.errors = setup.errors

        raise exception
      end

      @configuration = setup.options

      setup
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
sms_broker-1.0.8 lib/sms_broker/configuration.rb
sms_broker-1.0.7 lib/sms_broker/configuration.rb
sms_broker-1.0.5 lib/sms_broker/configuration.rb
sms_broker-1.0.4 lib/sms_broker/configuration.rb
sms_broker-1.0.3 lib/sms_broker/configuration.rb
sms_broker-1.0.2 lib/sms_broker/configuration.rb