Class: Penthouse::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/penthouse/configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(router: nil, runner: nil, migrate_tenants: false, db_schema_file: nil, tenants: -> { raise NotImplementedError }) ⇒ Configuration

Returns a new instance of Configuration.

Parameters:

  • router (Penthouse::Routers::BaseRouter) (defaults to: nil)

    the default router for your application to use

  • runner (Penthouse::Runners::BaseRunner) (defaults to: nil)

    the default runner for your application to use

  • migrate_tenants (Boolean) (defaults to: false)

    whether you want Penthouse to automatically migrate all tenants

  • db_schema_file (String) (defaults to: nil)

    a path to your schema file (typically ‘db/schema.rb` or `db/structure.sql` in Rails)

  • tenants (Proc) (defaults to: -> { raise NotImplementedError })

    some code which must return an hash of tenant identifiers (strings/symbols) mapped to tenant objects, which can be anything your runner needs



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/penthouse/configuration.rb', line 24

def initialize(router: nil, runner: nil, migrate_tenants: false, db_schema_file: nil, tenants: -> { raise NotImplementedError })
  self.router = router
  self.runner = runner
  self.migrate_tenants = migrate_tenants
  self.db_schema_file = db_schema_file
  self.tenants = tenants

  if migrate_tenants? && !db_schema_file
    raise ArgumentError, "If you want to migrate tenants, we need a path to a DB schema file"
  elsif migrate_tenants? && !File.exist?(db_schema_file)
    raise ArgumentError, "#{db_schema_file} is not readable"
  end
end

Instance Attribute Details

#db_schema_fileObject

Returns the value of attribute db_schema_file.



15
16
17
# File 'lib/penthouse/configuration.rb', line 15

def db_schema_file
  @db_schema_file
end

#migrate_tenantsObject

Returns the value of attribute migrate_tenants.



15
16
17
# File 'lib/penthouse/configuration.rb', line 15

def migrate_tenants
  @migrate_tenants
end

#routerObject

Returns the value of attribute router.



15
16
17
# File 'lib/penthouse/configuration.rb', line 15

def router
  @router
end

#runnerObject

Returns the value of attribute runner.



15
16
17
# File 'lib/penthouse/configuration.rb', line 15

def runner
  @runner
end

#tenantsObject

Returns the value of attribute tenants.



15
16
17
# File 'lib/penthouse/configuration.rb', line 15

def tenants
  @tenants
end

Instance Method Details

#migrate_tenants?Boolean

Returns whether or not Penthouse should automatically migrate all tenants.

Returns:

  • (Boolean)

    whether or not Penthouse should automatically migrate all tenants



39
40
41
# File 'lib/penthouse/configuration.rb', line 39

def migrate_tenants?
  !!migrate_tenants
end