Sha256: fc279d9e76284330ebee495e0f9e70c83c3cfcdc6c361b3f3324a9f608ee4549

Contents?: true

Size: 1.2 KB

Versions: 16

Compression:

Stored size: 1.2 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
      # @return [void]
      # @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

16 entries across 16 versions & 1 rubygems

Version Path
penthouse-0.11.0 lib/penthouse/runners/base_runner.rb
penthouse-0.10.1 lib/penthouse/runners/base_runner.rb
penthouse-0.10.0 lib/penthouse/runners/base_runner.rb
penthouse-0.9.0 lib/penthouse/runners/base_runner.rb
penthouse-0.8.0 lib/penthouse/runners/base_runner.rb
penthouse-0.7.5 lib/penthouse/runners/base_runner.rb
penthouse-0.7.4 lib/penthouse/runners/base_runner.rb
penthouse-0.7.3 lib/penthouse/runners/base_runner.rb
penthouse-0.7.2 lib/penthouse/runners/base_runner.rb
penthouse-0.7.1 lib/penthouse/runners/base_runner.rb
penthouse-0.7.0 lib/penthouse/runners/base_runner.rb
penthouse-0.6.0 lib/penthouse/runners/base_runner.rb
penthouse-0.5.0 lib/penthouse/runners/base_runner.rb
penthouse-0.4.2 lib/penthouse/runners/base_runner.rb
penthouse-0.4.1 lib/penthouse/runners/base_runner.rb
penthouse-0.4.0 lib/penthouse/runners/base_runner.rb