Sha256: e5d6f06024b633bf4f8a1cd9ddac24b5f2240bca5ef897d6ff97aea4ed51bbd1

Contents?: true

Size: 1.18 KB

Versions: 1

Compression:

Stored size: 1.18 KB

Contents

#
# This class provides an abstract for the runner interface. Whilst any Proc
# could be used, it's easiest to sub-class then overwrite the #load_tenant
# method.
#
# A runner class's responsibility in Penthouse is to receive an identifier for
# a tenant and a block, and to execute that block within the tenant
#

module Penthouse
  module Runners
    class BaseRunner

      # @param tenant_identifier [String, Symbol] The identifier for the tenant
      # @param block [Block] The code to execute within the tenant
      # @raise [Penthouse::TenantNotFound] if the tenant cannot be switched to
      def self.call(tenant_identifier, &block)
        load_tenant(tenant_identifier).call do |tenant|
          Penthouse.with_tenant(tenant.identifier) do
            block.yield(tenant)
          end
        end
      end

      # @abstract returns the tenant object
      # @param tenant_identifier [String, Symbol] The identifier for the tenant
      # @return [Penthouse::Tenants::BaseTenant] An instance of a tenant
      # @raise [Penthouse::TenantNotFound] if the tenant cannot be switched to
      def self.load_tenant(tenant_identifier)
        raise NotImplementedError
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
penthouse-0.3.0 lib/penthouse/runners/base_runner.rb