Module: SupportTable::ClassMethods

Defined in:
lib/support_table.rb

Instance Method Summary collapse

Instance Method Details

#support_table(data_file: nil, key_attribute: nil, attribute_helpers: nil, cache_by: nil, cache: :memory, ttl: nil) ⇒ void

This method returns an undefined value.

Define details about the support table. You only need to call this method if you need to override any of the defaults. See SupportTableData and SupportTableCache for more details.

Parameters:

  • data_file (String, Array<String>, false, nil) (defaults to: nil)

    Path to the data file to use to load the table. This should be a YAML, JSON, or CSV file that defines the records that should always exist in the table. If no value is specified, then a YAML file in the data directory with the same name as the underscored, pluralized name of the class will be used. For example, if the class name is Task::Status, then it will look for the file task/statuses.yml in the db/support_tables directory. You can pass false to disable loading the default data file.

  • key_attribute (String, Symbol, nil) (defaults to: nil)

    The name of the attribute in the data file that uniquely identifies each row in the data. By default this will be the id attribute.

  • attribute_helpers (String, Symbol, Array<String, Symbol>, nil) (defaults to: nil)

    List of attributes which should have helper methods created for them. This generates methods for each named instance to get that attribute directly from the YAML data. For example, adding a helper for :name will create a class method *_name for each named instance (i.e. Status.draft_name).

  • cache_by (String, Symbol, Array, nil) (defaults to: nil)

    List of attributes that can be used to uniquely identify a row that can be used for caching records. If a unique key is made up of multiple columns, then you will need to set it up with a call to SupportTableCache.cache_by

  • cache (ActiveSupport::Cache::Store, Symbol, Boolean, nil) (defaults to: :memory)

    The caching mechanism to use. This can be either an instance of ActiveSupport::Cache::Store like Rails.cache, or the value :memory to use an in-memory cache, or false or nil to disable caching.

  • ttl (Numeric, ActiveSupport::Duration, nil) (defaults to: nil)

    The time-to-live (in seconds) for cached records. If not specified, cached records never expire.



74
75
76
77
78
79
80
81
82
83
# File 'lib/support_table.rb', line 74

def support_table(data_file: nil, key_attribute: nil, attribute_helpers: nil, cache_by: nil, cache: :memory, ttl: nil)
  SupportTable::Definition.new(self).support_table(
    data_file: data_file,
    key_attribute: key_attribute,
    attribute_helpers: attribute_helpers,
    cache_by: cache_by,
    cache: cache,
    ttl: ttl
  )
end