module Sequential::SequentialInclude::ClassMethods

Public Instance Methods

sequential(options = {}) click to toggle source

Public: Defines ActiveRecord callbacks to set a sequential ID scoped on a specific class.

options - The Hash of options for configuration:

:scope    - The Symbol representing the columm on which the
            sequence should be scoped (default: nil)
:column   - The Symbol representing the column that stores the
            sequence (default: :sequential_id)
:start_at - The Integer value at which the sequence should
            start (default: 1)
:skip     - Skips the sequence generation when the lambda
            expression evaluates to nil. Gets passed the
            model object

Examples

class Answer < ActiveRecord::Base
  belongs_to :question
  sequential scope: :question_id
end

Returns nothing.

# File lib/sequential/sequential_include.rb, line 33
def sequential(options = {})
  cattr_accessor :sequence_options

  (self.sequence_options ||= []) << options

  before_create :set_sequential_values

  include Sequential::SequentialInclude::InstanceMethods
end