Module: ClosureTree::DeterministicOrdering

Defined in:
lib/closure_tree/acts_as_tree.rb

Instance Method Summary collapse

Instance Method Details

#order_columnObject



428
429
430
431
# File 'lib/closure_tree/acts_as_tree.rb', line 428

def order_column
  o = order_option
  o.split(' ', 2).first if o
end

#order_column_symObject



437
438
439
440
# File 'lib/closure_tree/acts_as_tree.rb', line 437

def order_column_sym
  require_order_column
  order_column.to_sym
end

#order_valueObject



442
443
444
# File 'lib/closure_tree/acts_as_tree.rb', line 442

def order_value
  read_attribute(order_column_sym)
end

#order_value=(new_order_value) ⇒ Object



446
447
448
# File 'lib/closure_tree/acts_as_tree.rb', line 446

def order_value=(new_order_value)
  write_attribute(order_column_sym, new_order_value)
end

#quoted_order_column(include_table_name = true) ⇒ Object



450
451
452
453
454
# File 'lib/closure_tree/acts_as_tree.rb', line 450

def quoted_order_column(include_table_name = true)
  require_order_column
  prefix = include_table_name ? "#{quoted_table_name}." : ""
  "#{prefix}#{connection.quote_column_name(order_column)}"
end

#require_order_columnObject



433
434
435
# File 'lib/closure_tree/acts_as_tree.rb', line 433

def require_order_column
  raise ":order value, '#{order_option}', isn't a column" if order_column.nil?
end

#siblings_afterObject



460
461
462
# File 'lib/closure_tree/acts_as_tree.rb', line 460

def siblings_after
  siblings.where(["#{quoted_order_column} > ?", order_value])
end

#siblings_beforeObject



456
457
458
# File 'lib/closure_tree/acts_as_tree.rb', line 456

def siblings_before
  siblings.where(["#{quoted_order_column} < ?", order_value])
end