Module: Roomer::Extensions::Model::ClassMethods

Defined in:
lib/roomer/extensions/model.rb

Instance Method Summary collapse

Instance Method Details

#roomer(scope) ⇒ Symbol

Sets the roomer scope for the model and changes the model’s table_name_prefix Sets the table name prefix (schema name) to current_tenant’s If :shared is passed, the global schema will be used as the table name prefix if :tenanted is pased, the current tenant’s schema will be used as the table name prefix

Returns:

  • (Symbol)

    :shared or :tenanted



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/roomer/extensions/model.rb', line 14

def roomer(scope)
  case scope
    when :shared
      @roomer_scope = :shared
    when :tenanted
      @roomer_scope = :tenanted
    else
      raise "Invalid roomer model scope.  Choose :shared or :tenanted"
  end
  roomer_set_table_name_prefix
end

#roomer_resetObject

Resets model’s cached table_name and column information. This method needs to get called whenever the current tenant changes



42
43
44
45
46
47
# File 'lib/roomer/extensions/model.rb', line 42

def roomer_reset
  roomer_set_table_name_prefix
  reset_table_name 
  reset_column_information
  reset_associations
end

#shared?True, False

Confirms if model is shared

Returns:

  • (True, False)


28
29
30
# File 'lib/roomer/extensions/model.rb', line 28

def shared?
  @roomer_scope == :shared
end

#tenanted?True, False

Confirms if model is scoped by tenant

Returns:

  • (True, False)


34
35
36
# File 'lib/roomer/extensions/model.rb', line 34

def tenanted?
  @roomer_scope == :tenanted
end