lib/penthouse.rb in penthouse-0.1.0 vs lib/penthouse.rb in penthouse-0.2.0

- old
+ new

@@ -30,10 +30,21 @@ block.yield(tenant_identifier) ensure self.tenant = default_tenant end + # Wraps Penthouse.switch and simply executes the block of code for each + # tenant within Penthouse.tenant_identifiers + # @param default_tenant [String, Symbol] the identifier for the tenant to return to + # @param block [Block] the code to execute + # @yield [String, Symbol] the identifier for the tenant + def each_tenant(default_tenant: tenant, runner: configuration.runner, &block) + tenant_identifiers.each do |tenant_identifier| + switch(tenant_identifier, runner: runner, &block) + end + end + # Executes the given block of code within a given tenant # @param tenant_identifier [String, Symbol] the identifier for the tenant # @param runner [Penthouse::Runners::BaseRunner] an optional runner to use, defaults to the one configured # @param block [Block] the code to execute def switch(tenant_identifier, runner: configuration.runner, &block) @@ -54,8 +65,14 @@ def configuration @configuration ||= Configuration.new( router: Routers::BaseRouter, runner: Runners::BaseRunner ) + end + + # Returns a array of tenant identifiers based on the configured setting + # @return [Array<String, Symbol>] the list of tenant identifiers + def tenant_identifiers + configuration.tenant_identifiers.call end end end