Module: SequenceGenerator::ActsAsSequenced::ClassMethods

Defined in:
app/models/concerns/act_as_sequenced.rb

Instance Method Summary collapse

Instance Method Details

#act_as_sequenced(options = {}) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/models/concerns/act_as_sequenced.rb', line 20

def act_as_sequenced(options= {})
  unless defined?(sequenced_options)
    include SequenceGenerator::ActsAsSequenced::InstanceMethods

    mattr_accessor :sequenced_options, instance_accessor: false
    self.sequenced_options = []
  end
  before_create :set_sequential_ids
  options = DEFAULT_OPTIONS.merge(options)
  column_name = options[:column]
  purpose = options[:purpose]

  if sequenced_options.any? { |options| options[:column] == column_name && options[:purpose] == purpose }
    raise(ColumnWithSamePurposeExists, "        Tried to set \#{column_name} as sequenced but there was already a\n        definition here. Did you accidentally call acts_as_sequenced\n        multiple times on the same column with same purpose?\n    MSG\n  else\n    sequenced_options << options\n  end\nend\n".squish)