Skip to content

Instantly share code, notes, and snippets.

@ProGM
ProGM / arel_cheatsheet_on_steroids.md
Last active May 15, 2024 20:55
Arel cheatsheet on Steroids

Arel Cheatsheet on Steroids

A (more) complete cheatsheet for Arel, including NamedFunction functions, raw SQL and window functions.

Tables

posts = Arel::Table.new(:posts)
posts = Post.arel_table # ActiveRecord

Table alias

module ProgressBar
class << self
def progress_bar(items_count, current_item_index, prefix)
@@start_time = Time.now if current_item_index == 0
time = Time.now - @@start_time
progress = current_item_index.next.to_f / items_count.to_f * 100
bar = "▓" * ( 50 * (progress / 100 ) ).floor
minutes = ((time / progress) * (100 - progress) / 60).round
left_str = "#{minutes} minutes left "
@stevehodgkiss
stevehodgkiss / native_columns_store.rb
Last active April 6, 2018 06:56
Allow specified session keys to be stored in a separate column using ActiveRecordStore. Useful for clearing sessions based on user_id.
class NativeColumnStore < ActiveRecord::SessionStore::Session
class << self
attr_reader :native_columns
def native_columns=(columns)
@native_columns = columns.map(&:to_s)
end
@native_columns = []
end
def data