Module: ActiveRecord::ActsAs::OrderableTable::ClassMethods

Defined in:
lib/active_record/acts_as/orderable_table.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#ordinal_fieldObject (readonly)

Returns the value of attribute ordinal_field.



9
10
11
# File 'lib/active_record/acts_as/orderable_table.rb', line 9

def ordinal_field
  @ordinal_field
end

#starts_fromObject (readonly)

Returns the value of attribute starts_from.



9
10
11
# File 'lib/active_record/acts_as/orderable_table.rb', line 9

def starts_from
  @starts_from
end

Instance Method Details

#acts_as_orderable_table(options = {}) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/active_record/acts_as/orderable_table.rb', line 11

def acts_as_orderable_table(options = {})
  @ordinal_field = options[:ordinal_field] || :ordinal
  @starts_from = options[:starts_from] || 0

  validates @ordinal_field, presence: true
  validate :check_ordinal_uniqueness
  before_validation :set_defaults

  class_eval do
    include ActiveRecord::ActsAs::OrderableTable::InstanceMethods
  end
end