Sha256: 1e310d1957c39635d1af9dd8099936b50e1c4960ae552af7844c2a58be5fbcdb

Contents?: true

Size: 928 Bytes

Versions: 8

Compression:

Stored size: 928 Bytes

Contents

require 'active_record'

module Motel
  module Sources

    class Default

      attr_accessor :tenants

      alias :configurations= :tenants=

      def initialize(config = {})
        @tenants = config[:configurations] || {}
      end

      def tenant(name)
        tenants[name]
      end

      def tenant?(name)
        tenants.key?(name)
      end

      def add_tenant(name, spec)
        raise ExistingTenantError if tenant?(name)

        tenants[name] = keys_to_string(spec)
      end

      def update_tenant(name, spec)
        raise NonexistentTenantError unless tenant?(name)

        spec = keys_to_string(spec)
        tenants[name].merge!(spec)
      end

      def delete_tenant(name)
        tenants.delete(name)
      end

      private

        def keys_to_string(hash)
          hash = hash.inject({}) do |h, (k, v)|
            h[k.to_s] = v
            h
          end
        end

    end

  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
motel-activerecord-3.0.0 lib/motel/sources/default.rb
motel-activerecord-2.1.0 lib/motel/sources/default.rb
motel-activerecord-2.0.3 lib/motel/sources/default.rb
motel-activerecord-2.0.2 lib/motel/sources/default.rb
motel-activerecord-2.0.1 lib/motel/sources/default.rb
motel-activerecord-2.0.0 lib/motel/sources/default.rb
motel-activerecord-1.0.1 lib/motel/sources/default.rb
motel-activerecord-1.0.0 lib/motel/sources/default.rb