Module: Coupler::Models::CommonModel::ClassMethods

Defined in:
lib/coupler/models/common_model.rb

Instance Method Summary collapse

Instance Method Details

#as_of_time(id, time) ⇒ Object



18
19
20
# File 'lib/coupler/models/common_model.rb', line 18

def as_of_time(id, time)
  versions_dataset.filter(["current_id = ? AND updated_at <= ?", id, time]).first
end

#as_of_version(id, version) ⇒ Object



14
15
16
# File 'lib/coupler/models/common_model.rb', line 14

def as_of_version(id, version)
  versions_dataset[:current_id => id, :version => version]
end

#const_missing(name) ⇒ Object



30
31
32
# File 'lib/coupler/models/common_model.rb', line 30

def const_missing(name)
  Models.const_missing(name)
end

#create!(*args) ⇒ Object



5
6
7
# File 'lib/coupler/models/common_model.rb', line 5

def create!(*args)
  new(*args).save!
end

#recently_accessedObject



9
10
11
12
# File 'lib/coupler/models/common_model.rb', line 9

def recently_accessed
  col = columns.include?(:last_accessed_at) ? :last_accessed_at : :updated_at
  order(col.desc).limit(3).all
end

#versions_datasetObject



26
27
28
# File 'lib/coupler/models/common_model.rb', line 26

def versions_dataset
  db[versions_table_name]
end

#versions_table_nameObject



22
23
24
# File 'lib/coupler/models/common_model.rb', line 22

def versions_table_name
  "#{table_name}_versions".to_sym
end