Module: SupportTable

Extended by:
ActiveSupport::Concern
Defined in:
lib/support_table.rb,
lib/support_table/definition.rb,
lib/support_table/belongs_to_support_table.rb

Overview

Include this module to add the ability to define support tables in ActiveRecord models. This will add the support_table and belongs_to_support_table class methods to the model.

A support table is a table that contains a fixed set of data that is used to support the application. This data is typically loaded from a data file (YAML, JSON, or CSV) and is intended to be read-only. Support tables are also usually small and can be cached in memory for fast access.

You would normally just include this module in your ApplicationRecord class. However, you can also include it in individual models.

Examples:

Define a support table


class ApplicationRecord < ActiveRecord::Base
  self.abstract_class = true

  include SupportTable
end

class Status < ApplicationRecord
  support_table
end

class Task < ApplicationRecord
  belongs_to_support_table :status
end

Defined Under Namespace

Modules: BelongsToSupportTable, ClassMethods Classes: Definition

Constant Summary collapse

VERSION =
File.read(File.join(__dir__, "../VERSION")).strip

Class Method Summary collapse

Class Method Details

.cache=(cache_impl) ⇒ void

This method returns an undefined value.

Set the cache used on support tables. See SupportTableCache for details. This is an alias for SupportTableCache.cache=.

Parameters:

  • cache_impl (ActiveSupport::Cache::Store)

    The cache implementation to use.



111
112
113
# File 'lib/support_table.rb', line 111

def cache=(cache_impl)
  SupportTableCache.cache = cache_impl
end

.data_directory=(dir) ⇒ void

This method returns an undefined value.

Set the directory where data files are stored. See SupportTableData for details. This is an alias for SupportTableData.data_directory=.

Parameters:

  • dir (String)

    Path to the directory where data files are stored.



92
93
94
# File 'lib/support_table.rb', line 92

def data_directory=(dir)
  SupportTableData.data_directory = dir
end

.sync_all!(*classes) ⇒ void

This method returns an undefined value.

Sync all support tables. See SupportTableData for details. This is an alias for SupportTableData.sync_all!.

Parameters:

  • classes (Array<Class>)

    List of support table classes to sync. If no classes are specified, then all support tables will be synced.



102
103
104
# File 'lib/support_table.rb', line 102

def sync_all!(*classes)
  SupportTableData.sync_all!(*classes)
end