Module: Sequential::SequentialInclude::ClassMethods

Defined in:
lib/sequential/sequential_include.rb

Instance Method Summary collapse

Instance Method Details

#sequential(options = {}) ⇒ Object

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.



33
34
35
36
37
38
39
40
41
# 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